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
@david-christiansen
david-christiansen / NatInd.idr
Last active October 26, 2017 22:21
Simple proof automation with reflected elaboration
module NatInd
import Language.Reflection.Elab
import Language.Reflection.Utils
%default total
trivial : Elab ()
trivial = do compute
g <- snd <$> getGoal
18:38:27 -> ((:docs-for "Nat")
94)
18:38:27 <- (:return
(:ok "Data type Nat : Type\n Unary natural numbers\n \nConstructors:\n Z : Nat\n Zero\n \n S : Nat -> Nat\n Successor\n "
((10 3
((:name "Prelude.Nat.Nat")
(:implicit :False)
(:decor :type)
(:doc-overview "Unary natural numbers")
(:type "Type")
mutual
class Foo a where
foo : a -> Type
bar : (x : a) -> foo @{nonsense} x -> Int
instance Foo a where
foo x = Nat
bar x n = 354
instance [nonsense] Foo a where
module Main
import Data.So
import Debug.Trace
%include C "bytes.h"
%link C "bytes.o"
%access public
module ClassNonsense
import Language.Reflection.Elab
class Foo a where
foo : a -> () -> a
class Foo a => Bar a where
constructor MkFoo
bar : a -> Int
module ClassNonsense
import Language.Reflection.Elab
class Foo t where
constructor MkFoo
foo : t
myFoo : Foo Nat
myFoo = MkFoo 1
||| Binary parsing, based on the stuff in Power of Pi
module Bin
import System
import Data.So
import Data.Vect
import Bytes
data HList : List Type -> Type where
Nil : HList []
(::) : t -> HList ts -> HList (t :: ts)
%name HList xs,ys
append : HList ts -> HList ts' -> HList (ts ++ ts')
append [] ys = ys
append (x :: xs) ys = x :: append xs ys
module NotElem
import Language.Reflection.Elab
import Language.Reflection.Utils
import Data.List
emptyNotElem : {a : Type} -> {x : a} -> Elem x [] -> Void
emptyNotElem Here impossible
data Typ =
IntTyp
| BolTyp
| FunTyp Typ Typ
toType : Typ -> Type
toType IntTyp = Integer
toType BolTyp = Bool
toType (FunTyp x y) = toType x -> toType y