Advertisement
Guest User

Untitled

a guest
Mar 30th, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.66 KB | None | 0 0
  1. type IO<'a> = private IO of (unit -> 'a)
  2.  
  3. type IOBuilder () =
  4.     member inline this.Bind (IO x : IO<'a>, f: 'a -> IO<'b>) : IO<'b> =
  5.         f (x ())
  6.  
  7.     member inline this.Bind (x: IO<'a> list, f: 'a list -> IO<'b>) : IO<'b> =
  8.         f (x |> List.map (fun (IO x) -> x ()))
  9.  
  10.     member inline this.Delay (f: unit -> IO<'a>) : IO<'a> =
  11.         IO (fun _ -> match f () with | IO x -> x ())
  12.  
  13.     member inline this.Return (x: 'a) : IO<'a> =
  14.         IO (fun _ -> x)
  15.  
  16.     member inline this.ReturnFrom (IO x : IO<'a>) : IO<'a> =
  17.         IO (fun _ -> x ())
  18.  
  19. let io = IOBuilder ()
  20.  
  21. [<RequireQualifiedAccess>]
  22. module IO =
  23.     let inline run (IO x) = x ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement