diff options
author | Zack Grannan | 2022-10-24 19:02:15 +0000 |
---|---|---|
committer | Zack Grannan | 2022-10-24 19:11:19 +0000 |
commit | 06ad8853e86b5c270f31f6d7b99081323f2f677a (patch) | |
tree | cd295975137b9ff64a183fd2a50cd5cf33b73e54 /entries | |
parent | 0ed78b5a990776b0db8c794b4e9ca415fee86fce (diff) |
Add submission for zgrannan
Diffstat (limited to 'entries')
-rw-r--r-- | entries/zgrannan/Fib.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/entries/zgrannan/Fib.hs b/entries/zgrannan/Fib.hs new file mode 100644 index 0000000..1918fc8 --- /dev/null +++ b/entries/zgrannan/Fib.hs @@ -0,0 +1,18 @@ +-- Point-less fibonacci +fib :: Int -> Int +fib = fix fib' + where + fib' = + ap (when 0 . (0 ==)) . + ap (when 1 . (1 ==)) . + ap (ap . ((+) .) . (. subtract 1)) (. subtract 2) + + when t c e = if c then t else e + + ap mf m = mf >>= (\f -> m >>= return . f) + + fix f = f (fix f) + + +main :: IO () +main = mapM_ (print . fib) [0 .. 10] |