[Haskell-cafe] Naive booleans and numbers - type-checking fails

Dušan Kolář kolar at fit.vutbr.cz
Sun Jan 24 14:01:09 EST 2010

Dear cafe,

   I'm trying to prepare a naive definition of booleans, numbers and 
some helper functions such a way, so that definition in lambda-calculus 
can be used in a straightforward way in Haskell. I was caught in trouble 
quite soon during change of lambda-expressions to Haskell - defining 
prefn as a helper for prev. When using Haskell-ish if-then-else then 
there is no problem (the code commented out), while using defined 
if-then-else (mif), the type-checking fails, but just for this case! 
Other simple tests are OK for the mif. Do I need some extra option for 
type-checker, or is it a principal failure (infinite type is reported) - 
I'm running ghci 6.10.4.

 > mtrue  x y = x
 > mfalse x y = y

 > m0 f n = n
 > m1 f n = f n
 > m2 f n = f (f n)

 > msucc x g m = x g (g m)
 > iszero m = m (\_ -> mfalse) mtrue

 > mif c t f = c t f
 > mpair f s = \e -> e f s
 > mfst p = p mtrue
 > msnd p = p mfalse

 > -- mprefn f p = if mex True False then mth else mel
 > mprefn f p = mif mex mth mel
 >   where
 >     mex = mfst p
 >     mth = mpair mfalse (msnd p)
 >     mel = mpair mfalse (f (msnd p))

Please, change of definitions is not a solution, I'm trying to follow 
available resources, so using something else is not an option. :-(

Thanks for any help


More information about the Haskell-Cafe mailing list