Skip to content

Instantly share code, notes, and snippets.

@marcoonroad
Forked from robotlolita/sum-digits.hm.hs
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoonroad/585637b8f6f7d27e512f to your computer and use it in GitHub Desktop.
Save marcoonroad/585637b8f6f7d27e512f to your computer and use it in GitHub Desktop.
module Fib using: Platform where
open Platform Prelude expose [+, parse, as-string, ~]
open Platform List expose [zip:using:, map:, take:, filter:, sum]
open Platform IO expose [read-line, print]
-- Typing things is currently cumbersome, but the type inference algorithm should catch 90% of this
let (Num a) => String -> a ::
x as-number = x parse
-- ~ is cons.
let fibs = 0 ~ 1 ~ fibs zip: fibs tail using: +
let n sum-digits = n as-string map: as-number |> sum
let main: _ = read-line >>= { x => fibs filter: even
|> take: x as-number
|> sum
|> sum-digits
|> print
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment