Idris2/tests/idris2/reg018/cycle.idr
2021-01-21 11:33:03 +00:00

28 lines
800 B
Idris

import Data.Vect
import Data.Vect.Elem
data Typ : Type where
TLam : Typ -> Typ -> Typ
TNat : Typ
data Term : Typ -> Vect len Typ -> Type where
Var : Elem a ctx -> Term a ctx
Lam : Term b (a :: ctx) -> Term (TLam a b) ctx
Fix : Term a (a :: ctx) -> Term a ctx
lookup : Vect len Typ -> Fin len -> Typ
lookup (a :: ctx) FZ = a
lookup (_ :: ctx) (FS n) = lookup ctx n
count : {ctx : Vect len Typ} -> (n : Fin len) -> Elem (lookup ctx n) ctx
count {ctx = _ :: ctx} FZ = Here
count {ctx = _ :: ctx} (FS n) = There (count n)
segfaults : {len : _} -> {ctx : Vect len Typ} ->
Term (TLam TNat TNat) ctx
segfaults = Fix (Lam (Var (count 0)))
cycleDetected : {len : _} -> {ctx : Vect len Typ} ->
Term (TLam TNat TNat) ctx
cycleDetected = Fix (Var (count 0))