, F #. F # , .NET, , , Haskell, , , .
F #, .
, F # , Haskell, "" , .
, , , :
type IO<'a> =
private
|Return of 'a
|Delay of (unit -> 'a)
/// Pure IO Functions
module IO =
/// Runs the IO actions and evaluates the result
let run io =
match io with
|Return a -> a
|Delay (a) -> a()
/// Return a value as an IO action
let return' x = Return x
let fromEffectful f = Delay (f)
let bind x f =
match x with
|Return a -> f a
|Delay (g) -> Delay (fun _ -> run << f <| g())
return IO.
fromEffectful unit -> 'a IO.
bind - .
run IO . unsafePerformIO Haskell.
.
: F #?
F # Haskell , F # , Haskell . Haskell ( , .NET, ) , , /IO, .
IO Haskell, ( ) - - , - . , .
, F #, :
let randomSeq = Seq.init 4 (fun _ -> rnd.Next())
let sortedSeq = Seq.sort randomSeq
printfn "Sorted: %A" sortedSeq
printfn "Random: %A" randomSeq
, , , .
. , , - . , , .
. , Seq.cache, , , .
, , , , F # Haskell.
, , . Mark Seemann , , - , .
IO , IO, .
, F #, " ". F #, . , IO , .
, , , Curse of the Excluded Middle, , , .
, , , , / , , F # .
, F # , " " - .