Last active
October 5, 2017 14:52
-
-
Save binq/62b0d1c6b8fee38dc9bdebea020db5e9 to your computer and use it in GitHub Desktop.
This file contains 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
{-# LANGUAGE ExplicitNamespaces, GADTs, KindSignatures, Safe, StrictData #-} | |
module FizzBuzz where | |
import Control.Arrow | |
import Data.Kind (type (*)) | |
data ZZ :: * -> * where | |
Base :: a -> ZZ a | |
Fizz :: ZZ a | |
Buzz :: ZZ a | |
FizzBuzz :: ZZ a | |
deriving Show | |
fizzBuzz :: (Integral a) => Int -> [ZZ a] | |
fizzBuzz max = fmap transform . take max $ [1..] | |
where | |
isFizzBuzz = isFizz &&& isBuzz >>> uncurry (&&) | |
isFizz = (`mod` 3) >>> (== 0) | |
isBuzz = (`mod` 5) >>> (== 0) | |
transform n | |
| isFizzBuzz n = FizzBuzz | |
| isBuzz n = Buzz | |
| isFizz n = Fizz | |
| otherwise = Base n |
This file contains 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
module Main where | |
import Control.Arrow | |
import Data.List (intersperse) | |
import FizzBuzz | |
main :: IO () | |
main = fizzBuzz >>> map show >>> intersperse ", " >>> concat >>> putStrLn $ 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment