-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix termination crash due to empty permutation (#3081)
- Fixes #3064
- Loading branch information
1 parent
a192654
commit 137b6d8
Showing
3 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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); |