Skip to content

Instantly share code, notes, and snippets.

@dselsam
Last active August 5, 2019 14:18
Show Gist options
  • Save dselsam/95b2c833129a5661767ec64e7625e050 to your computer and use it in GitHub Desktop.
Save dselsam/95b2c833129a5661767ec64e7625e050 to your computer and use it in GitHub Desktop.
Multiple match cases trigger
inductive Term : Type
| const : Nat -> Term
| app : List Term -> Term
namespace Term
instance : Inhabited Term := ⟨Term.const 0⟩
partial def hasToString : Term -> String | (const n) := "[CONST]" | (app ts) := "[APP]"
instance : HasToString Term := ⟨hasToString⟩
end Term
open Term
structure MyState : Type := (ts : List Term)
partial def foo : MyState -> Term -> List Term
| ms₀ t :=
-- Also: why doesn't this print?
-- let foo := dbgTrace ("t: " ++ toString t ) id;
-- Both branches fire!
-- But, it seems that if we ever trace 't', only the right branch fires.
let stateT : State MyState Unit :=
match t with
| const n => dbgTrace "CONST" pure
| app ts => dbgTrace "APP" pure ;
(stateT.run ⟨[]⟩).2.ts
def main : IO Unit := IO.println $ foo ⟨[]⟩ (app [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment