Tehee
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
{-# Language LambdaCase, Strict #-}
|
||||
module Main where
|
||||
|
||||
module Interpreter.Haskell where
|
||||
|
||||
import Chi
|
||||
import Data.Functor ( (<&>) )
|
||||
@ -45,5 +46,3 @@ eval = runIdentity . eval'
|
||||
else lookupBranch c brs
|
||||
|
||||
|
||||
main :: IO ()
|
||||
main = getLine >>= print . eval . parse
|
||||
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) -> _ \
|
||||
\ }"
|
||||
8
3or4/app/Main.hs
Normal file
8
3or4/app/Main.hs
Normal file
@ -0,0 +1,8 @@
|
||||
{-# Language LambdaCase, Strict #-}
|
||||
module Main where
|
||||
|
||||
import Chi
|
||||
import Interpreter.Haskell
|
||||
|
||||
main :: IO ()
|
||||
main = getLine >>= print . eval . parse
|
||||
@ -24,14 +24,15 @@ library
|
||||
LexChi
|
||||
ParChi
|
||||
PrintChi
|
||||
Interpreter.Haskell
|
||||
Interpreter.Self
|
||||
hs-source-dirs:
|
||||
.
|
||||
|
||||
executable interpreter
|
||||
main-is: Main.hs
|
||||
hs-source-dirs:
|
||||
interpreter
|
||||
other-modules: Self
|
||||
app
|
||||
build-depends: base
|
||||
, chi
|
||||
, mtl
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
-- |
|
||||
|
||||
module Self where
|
||||
|
||||
import Chi
|
||||
|
||||
substExp :: Exp
|
||||
substExp = parse ""
|
||||
Reference in New Issue
Block a user