Skip to content

Instantly share code, notes, and snippets.

View donovancrichton's full-sized avatar

Donovan Crichton donovancrichton

View GitHub Profile
@donovancrichton
donovancrichton / well-scoped.idr
Created September 28, 2020 04:52
An idris implementation of well-scoped lambda terms a la Allais et al.
{-
data Λ : List Type -> Type where
Var : (xs : List Type) -> Λ xs
Lam : Λ (x :: xs) -> Λ xs
App : Λ xs -> Λ xs -> Λ xs
-}
Scoped : Type -> Type
Scoped i = i -> List i -> Type
@donovancrichton
donovancrichton / let_parser_type_fail.idr
Created August 4, 2020 05:39
Error when parsing let expressions of equality types.
f : (n : Nat) -> n = n + 0
f 0 = Refl
f (S k) =
let ih : k = plus k 0
ih = f k
in rewrite sym ih in Refl
@donovancrichton
donovancrichton / hf_zipper_nat.idr
Created August 3, 2020 13:15
Example of HF Zipper breaking on Nat
%default total
ℕ : Type
ℕ = Nat
data D : ℕ -> Type where
K0 : D Z
K1 : {k : ℕ} -> D k -> D (S k)
K2 : {k : ℕ} -> D k -> D Z
data Ctx : ℕ -> Type where
@donovancrichton
donovancrichton / hf_full.idr
Last active July 29, 2020 06:03
Full specification of HF ZIpper as given (doesn't actually work)
-- Example 3.8 from Hanmana and Fiore - page 63
-- (Foundations of GADTS and Inductive Families)
data Expr : Type -> Type where
Const : Int -> Expr Int
IsZero : Expr Int -> Expr Bool
If : Expr Bool -> Expr a -> Expr a -> Expr a
-- Page 66: Context specialised for the Expr type above
-- General form for non-root cases is:
@donovancrichton
donovancrichton / implicit_break.idr
Created July 26, 2020 09:07
Introducing implicits on the LHS works when an infix operator is matched in prefix form but fails to parse when introduced on a match in infix form.
data MyList : Type -> Type where
Nil : {a : Type} -> MyList a
(::) : {a : Type} -> a -> MyList a -> MyList a
f : MyList b -> ()
f [] = ()
f ((::) {a} x xs) = ?normal
g : MyList b -> ()
g [] = ()
@donovancrichton
donovancrichton / sigma_break.idr
Created July 24, 2020 21:31
Matching on different types error
%default total
data MyList : Type -> Type where
Nil : {a : Type} -> MyList a
(::) : {a : Type} -> a -> MyList a -> MyList a
F : MyList a -> Maybe Type
F [] = Nothing
F ((::) {a} x xs) = Just a
G : MyList a -> Maybe Type
@donovancrichton
donovancrichton / zerolinearholes.idr
Created July 24, 2020 20:24
@-Patterns forcing bound implicit types to 0 linearity
data MyList : Type -> Type where
Nil : {a : Type} -> MyList a
(::) : {a : Type} -> a -> MyList a -> MyList a
f : MyList a -> ()
f [] = ()
f (x :: xs) = ?normal
g : MyList a -> ()
g [] = ()
@donovancrichton
donovancrichton / DepZipTestIdris2.idr
Last active July 23, 2020 22:49
Dependent Types not fully evaluating?
%default total
data Term : Type -> Type where
Const : {a : Type} -> a -> Term a
Pair : {a : Type} -> {b : Type} -> Term a -> Term b -> Term (a, b)
App : {a : Type} -> {b : Type} -> Term (a -> b) -> Term a -> Term b
GoLeft : {a : Type} -> Term a -> Maybe Type
GoLeft (Const x) = Nothing
GoLeft (Pair {a} x y) = Just a
GoLeft (App {a} {b} f x) = Just (a -> b)
@donovancrichton
donovancrichton / TestParserApplicative.idr
Created July 19, 2020 03:02
Type-checking Idris2 Parser (minimal example) for shmis111 via Idris slack
data ParamType = OptionParams
| FlagParams
| ArgParams
| CmdParams
data Visibility = Visible
| Hidden
| Internal
@donovancrichton
donovancrichton / SList.idr
Last active July 7, 2020 07:57
SListForYCombinatorian
--module Queue
import Syntax.WithProof
%default total
data State = Empty | NonEmpty
Eq State where
Empty == Empty = True