Skip to content

Instantly share code, notes, and snippets.

@fbiville
Last active August 29, 2015 14:05
Show Gist options
  • Save fbiville/57648ba01f10b94e9a75 to your computer and use it in GitHub Desktop.
Save fbiville/57648ba01f10b94e9a75 to your computer and use it in GitHub Desktop.
My second "real" Haskell program
foobarqix n = take n [ _substitute x | x <- [1..] ]
_substitute value = __substitute value "" [(3,"Foo"),(5,"Bar"),(7,"Qix")]
__substitute value "" [] = show value
__substitute value replacement [] = replacement
__substitute value replacement multiples =
let multiple = fst (head multiples)
string = snd (head multiples)
rest = tail multiples in
if (value `mod` multiple == 0) then
__substitute value (replacement ++ string) rest
else
__substitute value replacement rest
@fdelsert
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment