Last active
January 19, 2018 11:15
-
-
Save FaustXVI/6f54aa17e5eed4808124a03fd4cc382e to your computer and use it in GitHub Desktop.
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
import Data.So | |
fizz : Integer -> Bool | |
fizz n = (n `mod` 3) == 0 | |
buzz : Integer -> Bool | |
buzz n = (n `mod` 5) == 0 | |
data FizzBuzz : (n: Integer) -> Type where | |
Fizz : {auto fizz : So (fizz n)} -> FizzBuzz n | |
Buzz : {auto buzz : So (buzz n)} -> FizzBuzz n | |
Show (FizzBuzz n) where | |
show Fizz = "Fizz" | |
show Buzz = "Buzz" | |
fizzBuzz : (n: Integer) -> List (FizzBuzz n) | |
fizzBuzz n = case (choose (fizz n),choose (buzz n)) of | |
(Left _,Right _) => [Fizz] | |
(Right _,Left _) => [Buzz] | |
(Left _,Left _) => [Fizz,Buzz] | |
(Right _,Right _) => [] | |
showFizzBuzz : Integer -> String | |
showFizzBuzz n = case (fizzBuzz n) of | |
[] => show n | |
f => concatMap show f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment