Scrapbook-0.4.0: code examples
Copyright© Frank Jung 2020
LicenseGPL-3
Safe HaskellSafe-Inferred
LanguageHaskell2010

CFold

Description

Synopsis
  • cfold' :: (t1 -> t2 -> (t2 -> t2) -> t2) -> t2 -> [t1] -> t2
  • cfold :: (t1 -> t2 -> t2) -> t2 -> [t1] -> t2

Documentation

cfold' :: (t1 -> t2 -> (t2 -> t2) -> t2) -> t2 -> [t1] -> t2 Source #

CPS fold.

>>> λ> cfold' (\x t g -> (x : g t)) [] [1..10]
[1,2,3,4,5,6,7,8,9,10]
>>> λ> cfold' (\x t g -> g (x : t)) [] [1..10]
[10,9,8,7,6,5,4,3,2,1]

cfold :: (t1 -> t2 -> t2) -> t2 -> [t1] -> t2 Source #

Wrapper function to cfold'.

>>> λ> cfold (+) 0 [1..3]
6
>>> λ> cfold (:) [] [1..3]
[1,2,3]