.
warn , , . , ( , - , ), , , .
warn ( ). : Value restriction. The value 'warn' has been inferred to have generic type. , .
, , F # : , . , . .
, warn " ", " ". :
let warn() = getWarn log4net.LogManager.GetLogger("bar")
( - . ) generic, :
let warn<'a> : StringFormat<'a, unit> -> 'a = log4net.LogManager.GetLogger("bar")
, , .
, , :
warn "This is a warning"
warn "The value of my string is %s" someString
: , ( , ). unit. ( ) , , warn, , .. , warn, getWarn GetLogger . , , , , .
: , . . , , . :
let mapTuple f (a,b) = (f a, f b)
let makeList x = [x]
mapTuple makeList (1, "abc")
, - ( [1], ["abc"] ), ? , . mapTuple f (a,b), f . , a b, . -: f , , a, b, a b , mapTuple: ('a -> 'b) -> 'a*'a -> 'b*'b.
, , warn, , . , ( ), : , , .
, ( ), , . - :
type loggers =
abstract member warn: Printf.StringFormat<'a, unit> -> 'a
abstract member err: Printf.StringFormat<'a, unit> -> 'a
let getLoggers (log: log4net.ILog) =
{ new loggers with
member this.warn format = Printf.ksprintf log.Warn format
member this.err format = Printf.ksprintf log.Error format }
let logs = getLoggers (log4net.LogManager.GetLogger("Log"))
logs.warn "This is a warning"
logs.warn "Something is wrong: %s" someString