Skip to content

Instantly share code, notes, and snippets.

View donovancrichton's full-sized avatar

Donovan Crichton donovancrichton

View GitHub Profile
@donovancrichton
donovancrichton / proof.coq
Created July 6, 2018 02:20
Proof by Simplification from Logical Foundations
Theorem plus_id_example : ∀ n m:nat,
n = m →
n + n = m + m.
Proof.
(* move both quantifiers into the context: *)
intros n m.
(* move the hypothesis into the context: *)
intros H.
(* rewrite the goal using the hypothesis: *)
rewrite → H.
@donovancrichton
donovancrichton / RoseTreeWF.idr
Created December 4, 2019 08:13
well founded recursion for size on rose trees
%default total
-- Our type of rose trees.
data PfTree : Type -> Type where
Grow : a -> List (PfTree a) -> PfTree a
-- We want to show that recursion on rose trees is well-founded.
-- This is a little tricky. Idris has pre-existing well-founded proofs in the
-- prelude (WellFounded.idr). These are designed in such a way that if one can
-- conform to a 'Sized' interface, then the proof of well founded recursion is
@donovancrichton
donovancrichton / DepZip.idr
Created February 11, 2020 01:01
Example dependent zipper
%default total
data Expr : Type -> Type where
Var : a -> Expr a
App : Expr a -> Expr b -> Expr a
GoLeft : Expr a -> Maybe Type
GoLeft (Var x) = Nothing
GoLeft (App {a} x y) = Just a
@donovancrichton
donovancrichton / fibequiv.idr
Last active February 26, 2020 09:19
Proving extensionally equivalent fibonacci functions using Idris
%default total
||| A stream (an infinite list) of natural numbers representing the
||| fibbonacci sequence.
fibs : Stream Nat
fibs = f 0 1
where
f : Nat -> Nat -> Stream Nat
f a b = a :: f b (a + b)
%default total
interface Queue (q: Type -> Type) where
empty : q a
isEmpty : q a -> Bool
snoc : q a -> a -> q a
head : q a -> a
tail : q a -> q a
data CatList : (Type -> Type) -> Type -> Type where
@donovancrichton
donovancrichton / ForcingErrorOkasakiCatList.idr
Created June 30, 2020 23:11
Forcing too early results in a failure to solve constraints.
%default total
interface Queue (q: Type -> Type) where
empty : q a
isEmpty : q a -> Bool
snoc : q a -> a -> q a
head : q a -> a
tail : q a -> q a
data CatList : (Type -> Type) -> Type -> Type where
@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
@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 / 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 / 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 [] = ()