Created
March 22, 2014 01:38
-
-
Save davidgrenier/9699865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cell init = | |
MailboxProcessor.Start(fun inbox -> | |
let rec loop n = | |
async { | |
let! result = inbox.Receive() | |
printfn "Received %d" result | |
return! loop result | |
} | |
loop init | |
) | |
let myCell = cell 4 | |
myCell.Post 5 | |
// Abstract the recursive call away. | |
let iterate init f = | |
MailboxProcessor.Start(fun inbox -> | |
let rec loop n = | |
async { | |
let! result = f inbox | |
return! loop result | |
} | |
loop init | |
) | |
let cell2 init = | |
iterate init (fun inbox -> | |
async { | |
let! result = inbox.Receive() | |
printfn "Received %d" result | |
return result | |
} | |
) | |
let myCell2 = cell2 8 | |
myCell2.Post 32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment