c# to f# - Parameterless lambda expressions in F# -
i looking way define parameterless lambda expressions in f#, much next c# example.
var task = () => { int x = 3; dosomething(x); }
i tried following
let task = fun _ -> allow x = 3 dosomething x
it compiles gives me task : ('a -> unit)
looking task : (unit -> unit)
the msdn documentation not talk this. missing here ?
it's just
let task = fun () -> // whatever need
you illustration be:
let task = fun () -> allow x = 3 dosomething(3)
assuming dosomething
of type int -> unit
- if returns else need
let task = fun () -> allow x = 3 dosomething(3) |> ignore
to type unit -> unit
remark: don't write let task = fun () -> ...
let task() = ...
the thing missed: if write fun _ -> ()
saying want take parameter don't mind - f# take general (being named 'a
here) - include unit
! ()
value of type unit
(more or less void
c# ... true type in f#)
f# c#-to-f# unit-type
No comments:
Post a Comment