Ich bin ein Anfänger in Haskell, und versuchen, die Kirche Codierung für natürliche Zahlen zu implementieren, wie in this guide erläutert.Typ passt nur innerhalb einer Funktion in Haskell
{-# LANGUAGE RankNTypes #-}
newtype Chur = Chr (forall a. (a -> a) -> (a -> a))
zero :: Chur
zero = Chr (\x y -> y)
-- church to int
c2i :: Chur -> Integer
c2i (Chr cn) = cn (+ 1) 0
-- this works
i1 = c2i zero
-- this doesn't
i2 = zero (+ 1) 0
Für i2
Ich erhalte eine Typenkonflikt:
Couldn't match expected type ‘(Integer -> Integer) -> Integer -> t’
with actual type ‘Chur’
Relevant bindings include i2 :: t (bound at test.hs:14:1)
The function ‘zero’ is applied to two arguments,
but its type ‘Chur’ has none
In the expression: zero (+ 1) 0
In an equation for ‘i2’: i2 = zero (+ 1) 0
Wie kommt Chur
können Argumente, wenn in einer Funktion eingewickelt, kann aber nicht ohne sie?
Thx, eine Idee, wie diese Ersetzungen gedruckt werden? http://stackoverflow.com/questions/36650044/show-substitutions-in-ghci – dimid
@dimid Sie tippen sie auf Ihrer Tastatur, wie ich es tat. – molbdnilo