Last active
January 14, 2016 06:49
-
-
Save philcleveland/5b5a1e57e62643e5b823 to your computer and use it in GitHub Desktop.
F# bitwise pattern match
This file contains hidden or 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 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.