Skip to content

Instantly share code, notes, and snippets.

@Ball
Created November 20, 2012 19:53
Show Gist options
  • Save Ball/4120592 to your computer and use it in GitHub Desktop.
Save Ball/4120592 to your computer and use it in GitHub Desktop.
FizzBuzz in types
type Fizzable = Plain of int
| Fizzy
| Buzzy
| FizzyBuzzy
let toFizzable n :Fizzable =
match n with
| _ when (n % 3) = 0 && n % 5 = 0 -> FizzyBuzzy
| _ when n % 3 = 0 -> Fizzy
| _ when 0 = n % 5 -> Buzzy
| _ -> Plain(n)
let toString n =
match n with
| Fizzy -> "Fizz"
| Buzzy -> "Buzz"
| FizzyBuzzy -> "FizzBuzz"
| Plain(i) -> i.ToString()
[1..100]
|> List.map (toFizzable >> toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment