Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created October 11, 2012 09:55
Show Gist options
  • Save hodzanassredin/3871346 to your computer and use it in GitHub Desktop.
Save hodzanassredin/3871346 to your computer and use it in GitHub Desktop.
MessagePassing in fsharp
// 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