packages feed

baskell-0.1: examples/Fix.bs

# The paradoxical fixpoint combinator in Baskell.
# How to implement recursion without using a recursive function.
#
# Author: Bernie Pope
# Date:   10 October 2004

fix = \h -> (\x -> h (x x)) (\x -> h (x x));

# factorial 

fac = fix facNonRec;
facNonRec 
   = \f -> \n -> 
        ite (eqI n 0) 
            1 
            (mult n (f (sub n 1)));

# an infinite list of 1s

ones = fix (\x -> Cons 1 x);