Skip to content

Commit

Permalink
Normalize types in repl (#1897)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored Mar 17, 2023
1 parent 934a273 commit 3dac3c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/Juvix/Compiler/Internal/Translation/FromInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ typeCheckExpressionType ::
Sem r TypedExpression
typeCheckExpressionType InternalTypedResult {..} exp =
mapError (JuvixError @TypeCheckerError)
$ do
evalState _resultFunctions
$ evalState _resultFunctions
. evalState _resultIdenTypes
. runReader table
. ignoreOutput @Example
. withEmptyVars
. runInferenceDef
$ inferExpression' Nothing exp
$ do
t <- inferExpression' Nothing exp
traverseOf typedType strongNormalize t
where
table :: InfoTable
table = buildTableRepl exp _resultModules
Expand All @@ -71,14 +72,14 @@ typeCheckExpression ::
InternalTypedResult ->
Expression ->
Sem r Expression
typeCheckExpression res exp = fmap (^. typedExpression) (typeCheckExpressionType res exp)
typeCheckExpression res exp = (^. typedExpression) <$> typeCheckExpressionType res exp

inferExpressionType ::
(Members '[Error JuvixError, NameIdGen, Builtins] r) =>
InternalTypedResult ->
Expression ->
Sem r Expression
inferExpressionType res exp = fmap (^. typedType) (typeCheckExpressionType res exp)
inferExpressionType res exp = (^. typedType) <$> typeCheckExpressionType res exp

typeChecking ::
(Members '[Error JuvixError, NameIdGen, Builtins] r) =>
Expand Down
30 changes: 20 additions & 10 deletions tests/smoke/Commands/repl.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ tests:
contains: "Juvix REPL"
exit-status: 0

- name: infer-mutually-recursive-let-expression
command:
- juvix
- repl
stdin: ":type let even : _; odd : _; odd zero := false; odd (suc n) := not (even n); even zero := true; even (suc n) := not (odd n) in even 10"
stdout:
contains:
"Bool"
exit-status: 0

- name: eval-mutually-recursive-let-expression
command:
- juvix
- repl
stdin: "let even : Nat → Bool; odd : _; odd zero := false; odd (suc n) := not (even n); even zero := true; even (suc n) := not (odd n) in even 10"
stdout:
contains:
"true"
exit-status: 0

- name: quit
command:
- juvix
Expand Down Expand Up @@ -118,16 +138,6 @@ tests:
Nat
exit-status: 0

- name: eval-mutually-recursive-let-expression
command:
- juvix
- repl
stdin: "let even : Nat → Bool; odd : _; odd zero := false; odd (suc n) := not (even n); even zero := true; even (suc n) := not (odd n) in even 10"
stdout:
contains:
"true"
exit-status: 0

- name: eval-let-expression
command:
- juvix
Expand Down

0 comments on commit 3dac3c8

Please sign in to comment.