aboutsummaryrefslogtreecommitdiff
path: root/entries/zgrannan/Fib.hs
diff options
context:
space:
mode:
authorBraxton Hall2022-10-24 19:38:20 +0000
committerGitHub2022-10-24 19:38:20 +0000
commit59e81fca4d450c71f10722792d36abf1b721caff (patch)
treebbc0837d1a492e1fb946c9fa6a4e6aea66b28305 /entries/zgrannan/Fib.hs
parent0aa0d695f8fef33b02cbf04fbd6825bd2cbc6de1 (diff)
parenta139a04ba0a5de1c36044e3dae1c6833193d2bea (diff)
Merge branch 'main' into main
Diffstat (limited to 'entries/zgrannan/Fib.hs')
-rw-r--r--entries/zgrannan/Fib.hs18
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]