
Can somebody check that I've implemented this correctly? *****X*X*X*XX***X*X*XXX*X*X*XX***X*X*X*XX**X*X*XX**X*X*X*XX ***X*X*XXX*X*X*XX**XX*X*XX***X*X*XXX*X*XX****X*X*X*XX****X* X*X*XX***X*X*XXX*X*X*XXX*X*XXXX****X*X*XXX****X*X*X*XX***X* X*XXX*X*X*XXX*X*XXXX A parser for this is given by decode (c:cs) = case c of 'X' -> X '*' -> let (e0,cs0) = decode cs; (e1,cs1) = decode cs0 in (e0 `apply` e1, cs1) The letter X stands for the following combinator: X = \x -> xSK K = \xy -> x S = \fgx -> fx(gx) Assuming my Haskell code is correct, the above *should* be a program to compute the sum of the Church numberal 2 and the Church numeral 2. In other words, this is the world's most verbose way to define the act of putting two and two together. ;-) But... I don't know... that's A LOT of expression there! Have a slipped up somewhere? Does anybody have a way to check?

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Andrew Coppin wrote:
decode (c:cs) = case c of 'X' -> X '*' -> let (e0,cs0) = decode cs; (e1,cs1) = decode cs0 in (e0 `apply` e1, cs1)
The letter X stands for the following combinator:
X = \x -> xSK K = \xy -> x S = \fgx -> fx(gx)
Assuming my Haskell code is correct, ... Does anybody have a way to check?
Whether X is a data constructor or a function \x -> x S K, it isn't the same type as the tuple that the other case alternative returns, so you have a type error. If you had working haskell code, you could check if it worked by trying running the haskell code! (ghci/hugs can be convenient, if nothing else) Isaac -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGh++BHgcxvIWYTTURAg+QAKCYOZuV3/TwC4Ye8kMbSVy7D+UOJwCfadGG IJmQx8GfrXOiIADwO8np8og= =hfNa -----END PGP SIGNATURE-----

Hi Andrew! Seems that you've made a typo or something...
module Term where import Control.Monad.State testData = "*****X*X*X*XX**X*X*XX*X*X*X*XX*X*X*XX***X*X*X*XX" ++ "***X*X*X*XX**X*X*XX*X*X*X*XX*X*X*XX*XX***X*X*X*X" ++ "X***X*X*X*XX**X*X*XX*X*X*X*XX*X*X*XX*XX" data Term = IntTerm Int | Term (Term -> Term) inc = Term $ \x -> case x of IntTerm n -> IntTerm (n+1) out x = case x of IntTerm n -> n outCh x = out $ x `apply` inc `apply` IntTerm 0 apply x y = case x of Term f -> f y infixl `apply` xComb = Term $ \x -> x `apply` sComb `apply` kComb kComb = Term $ \x -> Term $ \y -> x sComb = Term $ \f -> Term $ \g -> Term $ \x -> f `apply` x `apply` (g `apply` x) decode = evalState decodeS where decodeS = do c:cs <- get put cs case c of 'X' -> return xComb '*' -> do f <- decodeS x <- decodeS return $ f `apply` x
Then outCh $ decode testData prints "4", as desired, while your version simply fails. AC> Can somebody check that I've implemented this correctly? AC> *****X*X*X*XX***X*X*XXX*X*X*XX***X*X*X*XX**X*X*XX**X*X*X*XX AC> ***X*X*XXX*X*X*XX**XX*X*XX***X*X*XXX*X*XX****X*X*X*XX****X* AC> X*X*XX***X*X*XXX*X*X*XXX*X*XXXX****X*X*XXX****X*X*X*XX***X* AC> X*XXX*X*X*XXX*X*XXXX AC> A parser for this is given by AC> decode (c:cs) = case c of AC> 'X' -> X AC> '*' -> let (e0,cs0) = decode cs; (e1,cs1) = decode cs0 in (e0 AC> `apply` e1, cs1) AC> The letter X stands for the following combinator: AC> X = \x -> xSK AC> K = \xy -> x AC> S = \fgx -> fx(gx)
participants (3)
-
Andrew Coppin
-
Isaac Dupree
-
Miguel Mitrofanov