Skip to content

Instantly share code, notes, and snippets.

@philcleveland
Last active January 14, 2016 06:49
Show Gist options
  • Save philcleveland/5b5a1e57e62643e5b823 to your computer and use it in GitHub Desktop.
Save philcleveland/5b5a1e57e62643e5b823 to your computer and use it in GitHub Desktop.
F# bitwise pattern match
let parseState value =
match value with
| 0us ->
printfn "state 0"
| value when value &&& 16us <> 16us ->
printfn "state 1"
| value when value &&& 32us <> 32us ->
printfn "state 2"
| value when value &&& 64us <> 64us ->
printfn "state 3"
| value when value &&& 4096us <> 4096us ->
printfn "state 4"
| value when value &&& 8192us <> 8192us ->
printfn "state 5"
| _ ->
printfn "Unexpected state"
@mastoj
Copy link

mastoj commented Jan 14, 2016

Not sure why state 0 is always matched, does it read 0us as a variable maybe? That shouldn't be the case since I don't think you're allowed to start a variable name with a number. Either way, we do match and set the new variable name to the same as the one you matched on, it's confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment