Created
October 11, 2012 09:55
-
-
Save hodzanassredin/3871346 to your computer and use it in GitHub Desktop.
MessagePassing in fsharp
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
// Learn more about F# at http://fsharp.net | |
// See the 'F# Tutorial' project for more help. | |
type MyObjectMessage = | |
| PrintState | |
| Set of int;; | |
let MyObject() = | |
let refVar = ref 0 | |
let dispatcher = fun message -> | |
match message with | |
| PrintState -> printfn "%i" !refVar | |
| Set(i) -> refVar := i | |
dispatcher;; | |
[<EntryPoint>] | |
let main argv = | |
let m = MyObject() | |
Set(1) |> m |> ignore | |
PrintState |> m |> ignore | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment