Skip to content

Instantly share code, notes, and snippets.

@Dierk
Created September 11, 2017 19:14
Show Gist options
  • Save Dierk/32523041db59a1d35ca1da6d1f737ab8 to your computer and use it in GitHub Desktop.
Save Dierk/32523041db59a1d35ca1da6d1f737ab8 to your computer and use it in GitHub Desktop.
module FizzBuzz
import Data.Vect
Rule : Type
Rule = (n: Int) -> (old: List String) -> (List String)
everyNthRule : (every: Int) -> (replacement: String) -> Rule
everyNthRule every replacement n old =
if (mod n every == 0) then old ++ [replacement] else old
fizz : Rule
fizz = everyNthRule 3 "fizz"
buzz : Rule
buzz = everyNthRule 5 "buzz"
num : Rule
num n [] = [show n]
num n old = old
rules : Rule
rules n = num n . buzz n . fizz n
applyRules : Int -> String
applyRules n = concat (rules n [])
main : IO ()
main = do
for_ (map applyRules [1..15]) putStr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment