summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/boxy/Church1.hs
blob: fccaac7d8cb1e77fb43b20066fd40f90c1c44ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE RankNTypes #-}

module Church1 where 
-- Church numerals w/o extra type constructors 

type CNat = forall a. (a->a) -> a -> a 

n0 :: CNat 
n0 = \f z -> z

n1 :: CNat 
n1 = \f z -> f z 

nsucc :: CNat -> CNat 
nsucc n = \f z -> f (n f z)

add, mul :: CNat -> CNat -> CNat
add m n = \f -> \a -> m f (n f a)
mul m n = \f -> \a -> m (n f) a

-- already works with GHC 6.4 
exp0 :: CNat -> CNat -> CNat 
exp0 m n = n m


exp1 :: CNat -> CNat -> CNat 
exp1 m n = (n::((CNat -> CNat) -> CNat -> CNat)) (mul m) n1  -- checks with app rule