Created
September 11, 2017 19:14
-
-
Save Dierk/32523041db59a1d35ca1da6d1f737ab8 to your computer and use it in GitHub Desktop.
FizzBuzz in Idris, cmp: https://dierk.gitbooks.io/fregegoodness/src/docs/asciidoc/fizzbuzz_reconstructed.html
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 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