add decrement example to UntypedLambda

This commit is contained in:
pilfer-pandex 2019-09-28 22:47:20 -07:00
parent c966f98a0f
commit 7d4ab2ceb9

View File

@ -3,7 +3,7 @@ module UntypedLambda where
import ClassyPrelude import ClassyPrelude
import Bound import Bound
import Control.Monad.Writer import Control.Monad.Writer hiding (fix)
import Data.Deriving (deriveEq1, deriveOrd1, deriveRead1, deriveShow1) import Data.Deriving (deriveEq1, deriveOrd1, deriveRead1, deriveShow1)
import qualified Data.Function as F import qualified Data.Function as F
import Data.List (elemIndex) import Data.List (elemIndex)
@ -307,6 +307,10 @@ posIn i n
copy :: Ord a => Exp a -> Nock copy :: Ord a => Exp a -> Nock
copy = copyToNock . toCopy copy = copyToNock . toCopy
-- | Decrements its argument.
decrement :: Exp String
decrement = lam "a" $ App (fix "f" $ lam "b" $ Ift (Eql (Var "a") (Suc (Var "b"))) (Var "b") (App (Var "f") (Suc (Var "b")))) (Atm 0)
-- x. y. x -- x. y. x
-- old: [8 [1 0] [1 8 [1 0] [1 0 30] 0 1] 0 1] -- old: [8 [1 0] [1 8 [1 0] [1 0 30] 0 1] 0 1]
-- =+ 0 = -- =+ 0 =