Idris2/tests/idris2/reg/reg018/cycle.idr

28 lines
800 B
Idris
Raw Normal View History

import Data.Vect
2020-07-04 13:02:04 +03:00
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))