Tehee
This commit is contained in:
42
3or4/Interpreter/Self.hs
Normal file
42
3or4/Interpreter/Self.hs
Normal file
@ -0,0 +1,42 @@
|
||||
{-# Language LambdaCase, Strict #-}
|
||||
|
||||
module Interpreter.Self where
|
||||
|
||||
import Chi
|
||||
import Interpreter.Haskell
|
||||
|
||||
mapExp :: Exp
|
||||
mapExp = parse
|
||||
"\\f. rec map = \\xs. case xs of \
|
||||
\ { Nil() -> Nil() \
|
||||
\ ; Cons(x,xs) -> Cons(f x, map xs)\
|
||||
\ }"
|
||||
|
||||
substBrExp :: Exp
|
||||
substBrExp = parse
|
||||
"rec substBr = \\x. "
|
||||
|
||||
ifExp :: Exp
|
||||
ifExp = parse
|
||||
"\\b. \\t. \\f. case b of \
|
||||
\ { True() -> t \
|
||||
\ ; False() -> f \
|
||||
\ }"
|
||||
|
||||
equalExp :: Exp
|
||||
equalExp = parse ""
|
||||
|
||||
substExp :: Exp
|
||||
substExp =
|
||||
subst (Variable "if") ifExp .
|
||||
subst (Variable "equal") equalExp .
|
||||
subst (Variable "substBr") substBrExp .
|
||||
subst (Variable "map") mapExp $ parse
|
||||
"\\var. \\e. rec subst = \\x. case x of\
|
||||
\ { Apply(e1,e2) -> Apply(subst e1, subst e2) \
|
||||
\ ; Lambda(x,y) -> if (equal x var) Lambda(x,y) Lambda(x,subst y) \
|
||||
\ ; Var(x) -> if (equal x var) e Var(x) \
|
||||
\ ; Const(c,es) -> Const(c, map subst es) \
|
||||
\ ; Rec(x, e') -> if (equal x var) Rec(x,e') Rec(x,subst e')\
|
||||
\ ; Case(e',bs) -> _ \
|
||||
\ }"
|
||||
Reference in New Issue
Block a user