Skip to content

Instantly share code, notes, and snippets.

@chexxor
Last active June 28, 2018 18:16
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 chexxor/7050a103d3cb8a6ec4b27c151cd9043e to your computer and use it in GitHub Desktop.
Save chexxor/7050a103d3cb8a6ec4b27c151cd9043e to your computer and use it in GitHub Desktop.
module Main where
import Prelude
import Control.Monad.Eff.Console (log, logShow)
import TryPureScript (render, withConsole)
import Control.Lazy (fix)
-- From https://github.com/awkure/purescript-birds/blob/v1.0.4/src/Aviary/Birds.purs#L38-L38
fixB :: forall a. (a -> a) -> a
fixB f = (compose f fixB) f
--fixB f = (f <<< fixB) f
-- From https://en.wikipedia.org/wiki/Fixed-point_combinator#Strict_functional_implementation
fixW :: forall a b. ((a -> b) -> a -> b) -> a -> b
fixW f x = f (fixW f) x
factF :: (Int -> Int) -> Int -> Int
factF fact' i = case i of
0 -> 1
i' -> i' * fact' (i' - 1)
-- !!! The Birds implementation doesn't work.
fact = fixW factF
main = render =<< withConsole do
logShow $ fact 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment