Skip to content

Instantly share code, notes, and snippets.

View david-christiansen's full-sized avatar

David Thrane Christiansen david-christiansen

  • Copenhagen, Denmark
View GitHub Profile
module HList
%default total
data HList : List Type -> Type where
(::) : t -> (xs : HList ts) -> HList (t :: ts)
Nil : HList []
foo : HList [Int, String, Int]
foo = [3, "yes", 17]
@david-christiansen
david-christiansen / gist:4994631
Last active December 13, 2015 23:49
Simple predicate
module PropDemo
data GreaterThanTwo : Nat -> Type where
threeOK : GreaterThanTwo 3
moreOK : GreaterThanTwo n -> GreaterThanTwo (S n)
total sumGreater : GreaterThanTwo n -> GreaterThanTwo m -> GreaterThanTwo (n + m)
sumGreater threeOK mOK = moreOK (moreOK (moreOK mOK))
sumGreater (moreOK nOK') mOK = moreOK (sumGreater nOK' mOK)
@david-christiansen
david-christiansen / Lambda.idr
Created July 29, 2013 18:44
Error with idiom brackets in equality type
module Lambda
%default total
infixr 8 ==>
data T : Type where
U : T
NAT : T
(*) : T -> T -> T
@david-christiansen
david-christiansen / Addition.idr
Created August 2, 2013 00:04
Using type classes for logic programming
module Addition
class Plus (n : Nat) (m : Nat) (o : Nat) where {}
instance Plus Z m m where {}
instance Plus n m o => Plus (S n) m (S o) where {}
parameters (n : Nat, m : Nat)
module Bugfind
import Language.Reflection
import Language.Reflection.Util
foo : TT
foo = Erased
@david-christiansen
david-christiansen / JSON.idr
Created December 10, 2013 17:58
Zygote of a JSON parser
module JSON
import Data.HVect
import Control.Monad.Identity
import Lightyear.Core
import Lightyear.Combinators
import Lightyear.Strings
@david-christiansen
david-christiansen / PreorderReasoning.idr
Created December 14, 2013 18:27
Agda-style preorder reasoning in Idris
module PreOrderReasoning
-- QED is first to get the precedence to work out. It's just refl with an explicit argument.
syntax [expr] "QED" = qed expr
-- foo ={ prf }= bar ={ prf' }= fnord QED
-- is a proof that foo is related to fnord, with the intermediate step being bar, justified by prf and prf'
syntax [from] "={" [prf] "}=" [to] = step from prf to
--These are the components for using the syntax with equality
@david-christiansen
david-christiansen / gist:8336956
Created January 9, 2014 16:19
First reflected error in Idris
drc@drc:~/Documents/Code/Idris/error-reflection-test$ idris ErrorTest.idr
____ __ _
/ _/___/ /____(_)____
/ // __ / ___/ / ___/ Version 0.9.10.1-git:5361547
_/ // /_/ / / / (__ ) http://www.idris-lang.org/
/___/\__,_/_/ /_/____/ Type :? for help
Type checking ./ErrorTest.idr
*ErrorTest> the Nat ""
ERROR HAPPENED!
@david-christiansen
david-christiansen / ErrorTest.idr
Created January 10, 2014 10:25
First-ever Idris DSL with domain-specific error messages!
module ErrorTest
import Language.Reflection
import Language.Reflection.Errors
import Language.Reflection.Utils
%language ErrorReflection
data Ty = TUnit | TFun Ty Ty
@david-christiansen
david-christiansen / FunErrTest.idr
Created January 23, 2014 15:34
Error reflection now supports specific function arguments
import Language.Reflection.Errors
import Language.Reflection.Utils
%language ErrorReflection
total
cadr : (xs : List a)
-> {auto cons1 : isCons xs = True}
-> {auto cons2 : isCons (tail xs cons1) = True}
-> a