summaryrefslogtreecommitdiff
path: root/examples/passing/TCO.purs
blob: dc55311bce7fe124d009383ed37d10b2588a56a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Main where

import Prelude
import Control.Monad.Eff.Console (log, logShow)

main = do
  let f x = x + 1
  let v = 0
  logShow (applyN 0 f v)
  logShow (applyN 1 f v)
  logShow (applyN 2 f v)
  logShow (applyN 3 f v)
  logShow (applyN 4 f v)
  log "Done"

applyN :: forall a. Int -> (a -> a) -> a -> a
applyN = go id
  where
  go f n _ | n <= 0 = f
  go f n g = go (f >>> g) (n - 1) g