# This is a sample macro definition file of LambdaFriends. # These macros are designed for untyped lambda-calculus. # '#' and following characters are regarded as comments. # Note: Following Combinators are supported as built-in macros. # * Church Numerals : <0>, <1>, <2>, ... # * Church Booleans : , # * SKI Combinators : , , # Note 2: In the current version of LambdaFriends, # once you redefine a macro, # the previous version of the macro will be "shadowed". # For example, if you input the following two lines: # M = \x.x # M = # then is syntactically equivalent to (\x.x)(\x.x). # Logical operators on Church booleans not = \p.p and = \xy.xy or = \xy.xy if = \ctf.ctf # Pairs pair = \xy.\p.pxy head = tail = fst = \p.p snd = \p.p # Predecessor prefn = \f.\p.(f(p))(p) pre = \nfx.(n(f)(xx)) pre2 = \nfx.n(\p.\y.y(f(p(\tf.t)))(p(\tf.t)))(\p.pxx)(\tf.f) pre3 = \nfx.n(\g.\h.h(gf))(\u.x)(\u.u) # Arithmetic operators on Church numerals succ = \n.\sz.s(nsz) add = \mn.\sz.ms(nsz) sub = \mn.n
m
mul    = \mn.\sz.m(ns)z
exp    = \mn.nm
is0    = \n.n(\x.)
eq     = (\f.\nm.((n)(m))((n)(m))(f(
n)(
m)))
one?   = \n.n(\x.\p.p(\tf.f)(x(\tf.t)))(\p.p(\tf.t)(\tf.t))(\tf.f)

# Fixpoint Combinator
Y      = \f.(\x.f(xx))(\x.f(xx)) # this is a kind of fixed-point combinator

# Sample of recursion using Y combinator
fact   = (\g.\n.( n) <1> (n(g(
n))))
lt2 = \n. ( n) ( (
 n))
fib = (\g.\n.( n)n((g(n<1>))(g(n<2>))))