eloign / YAL

Yet Another Language is a pure functional language written in Haskell
MIT License
0 stars 0 forks source link

Notes #3

Open eloign opened 2 years ago

eloign commented 2 years ago

LamV Env Pattern Expr LamCase [Alt]

eloign commented 2 years ago

Basically, we need to add indentation parsing for: Data declaration Let construction Type declaration If construction Application e t. c.

eloign commented 2 years ago

LamCase [Alt]

Evaluation:

' y = 4 x = 5

main = print x '

go through: 1) y = Nothing x = Nothing

main = Nothing

2) y = Just 5 x = Nothing

main = Nothing

3) e t. c.

eloign commented 2 years ago

Another Idea

Make an extension like this:

x = 5 y = 6

main = print x

1)

x = Left (Lit 5) y = Left (Lit 6)

main = Left (App (Var "print") (Var "x"))

2)

x = Right (LitV 5) y = Left (Lit 6)

main = Right (ConV "IO" [])

Other example:

y = x x = 5

main = print y

1)

y = Left (Var "x") x = Left (Lit 5)

main = Left (App (Var "print") (Var "y"))

2)

y = Right (LitV 5) x = Right (LitV 5)

main = Right ...

and make it with corresponding substitutions in decl environment

eloign commented 2 years ago

Add: LamCaseV and LamCase

eloign commented 2 years ago

LamCase [Alt]

LamCaseV Env ...

eloign commented 2 years ago

LamCase [Alt] restricts: 1) the number of arguments is always the same 2) the number of arguments can be null

f = 5

\case of -> 5

f a = 4

\case a of a -> 4

1)

\a -> \b -> case a, b of ...patterns and stuff

2) or FunApp Name [Value]

eloign commented 2 years ago

evalExpr e en = case exps alts -> case exps of [] -> go exps

go (x:xs) = case x of ([],Nothing,exp) -> evalExpr exp ([],Just c, exp) -> do cond <- evalExpr c if cond == (ConV "True" []) then evalExpr exp else go xs

other: match exps alts ...

eloign commented 2 years ago
maybe add: f a = 5 b = ...

either everything impure, either try to invent something, either add laziness