0
votes

Here, it is the source code to output church number. As I compiler, it occurs an error message:

parse error (possibly incorrect indentation or mismatched brackets)

I have no idea. Anyone can help? Thanks

module Main where

type Church a = (a -> a) -> a -> a

church :: Integer -> Church Integer
church 0 = \f -> \x -> x
church n = \f -> \x -> f (church (n-1) f x)

let r = church 0  
main = print (r)
1

1 Answers

4
votes

let is used in expressions and do notation; to define a binding at the module level, drop the let:

r = church 0  
main = print r

Even after this change, though, you'll get an error, since r has type Church Integer, aka (Integer -> Integer) -> Integer -> Integer, a function. Unfortunately, functions aren't showable, and thus aren't printable. If you wanted to display the number inside, you could use

r = church 0  
main = print (r succ 0)