Skip to content

Instantly share code, notes, and snippets.

@binq
Last active October 5, 2017 14:52
Show Gist options
  • Save binq/62b0d1c6b8fee38dc9bdebea020db5e9 to your computer and use it in GitHub Desktop.
Save binq/62b0d1c6b8fee38dc9bdebea020db5e9 to your computer and use it in GitHub Desktop.
{-# 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
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