Skip to content

Instantly share code, notes, and snippets.

@dgendill
Created June 22, 2017 20:49
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 dgendill/a7e996c57449d92e56e62ce522ab1a3a to your computer and use it in GitHub Desktop.
Save dgendill/a7e996c57449d92e56e62ce522ab1a3a to your computer and use it in GitHub Desktop.
Using Purescript Lazy Fixpoint and Lazy

Using Purescript Lazy Fixpoint and Lazy

-- Fibinachi using fixpoint and lazy
lazyFib :: Int -> Lazy Int
lazyFib x
  | x < 2 = defer \_ -> 1
  | otherwise = defer \_ -> (force $ (lazyFib (x-1))) + (force $ (lazyFib (x-2)))

fixFib :: (Int -> Int)
fixFib = fix (\rec n -> if n < 2 then 1 else rec(n-1) + rec (n-2))

runFixFib :: Int -> Int
runFixFib m = fixFib m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment