mirror of
https://github.com/anoma/juvix.git
synced 2024-11-30 05:42:26 +03:00
137b6d83eb
- Fixes #3064
36 lines
978 B
Plaintext
36 lines
978 B
Plaintext
module issue3064;
|
|
|
|
import Stdlib.Prelude open;
|
|
|
|
type Expression :=
|
|
-- Put both of these into a Const type
|
|
| Const Nat
|
|
| Str String
|
|
| Var String
|
|
| Lam String Expression
|
|
| App Expression Expression;
|
|
|
|
axiom undefined : {A : Type} -> A;
|
|
|
|
Environment : Type := List (Pair String Expression) ;
|
|
|
|
type Return :=
|
|
| RNatural Nat
|
|
| RString String;
|
|
|
|
terminating eval (env : Environment) : Expression -> Maybe Return
|
|
| (Const x) := RNatural x |> just
|
|
| (Str str) := RString str |> just
|
|
| (App f x) := eval-lookup env f x
|
|
| (Var var) := lookup-var env var >>= eval env
|
|
| _ := undefined;
|
|
|
|
eval-lookup (env : Environment) (f : Expression) (x : Expression) : Maybe Return :=
|
|
let recursive : _ -- Expression -> Return
|
|
| (Lam variable body) := eval ((variable , x) :: env) body
|
|
| _ := undefined;
|
|
in recursive f;
|
|
|
|
lookup-var (env : Environment) (to-lookup : String) : Maybe Expression
|
|
:= (snd <$> find \{ x := fst x == to-lookup } env);
|