Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
@gallais
gallais / Compiled-252.agda
Created March 3, 2017 16:08
New COMPILE pragmas in Agda
module Compiled-252 where
data U : Set where
z : U
s : U → U
{-# IMPORT Compiled.URaw #-}
{-# COMPILED_DATA U Compiled.URaw.U Compiled.URaw.Z Compiled.URaw.S #-}
open List
let bind (xs : 'a list) (f : 'a -> 'b list) : 'b list =
concat (map f xs)
let rec parts : 'a list -> 'a list list list = function
| [] -> [[]]
| [c] -> [[[c]]]
| c :: cs ->
bind (parts cs) (fun (p :: ps) ->
@gallais
gallais / DefaultArgument.agda
Created May 9, 2017 09:24
Default named arguments
record Default {ℓ} (A : Set ℓ) (a : A) : Set ℓ where
constructor _!
field value : A
instance
default : ∀ {ℓ} {A : Set ℓ} a → Default A a
default a = record { value = a }
open import Agda.Builtin.Nat
@gallais
gallais / swapVar.agda
Last active May 12, 2017 13:42
swapping variables
module Subst1 where
open import Term
infixl 20 _-_
_-_ : {σ : Ty} → (Γ : Con) → Var Γ σ → Con
ε - ()
(Γ , σ) - vz = Γ
(Γ , τ) - vs x = (Γ - x) , τ
@gallais
gallais / Agda.Utils.TypeLevel.hs
Created May 14, 2017 23:15
Type level functions for Agda's Utils library
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- We need undecidable instances for the definition of @Foldr@,
-- and @Domains@ and @CoDomain@ using @If@ for instance.
@gallais
gallais / Printf.idr
Created May 30, 2017 13:03
towards a working example
module Printf
import Lightyear.Char
import Lightyear.Core
import Lightyear.Combinators
import Lightyear.Strings
%access public export
%default total
@gallais
gallais / Zippy.agda
Created June 8, 2017 14:21
Structural equality for inductive types
module Zippy where
data Desc : Set₁ where
`σ : (A : Set) (d : A → Desc) → Desc
`r : Desc → Desc
`q : Desc
open import Size
open import Data.Unit
open import Data.Product
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ConstraintKinds #-}
import Data.Constraint
import Data.Function
module Accessibility where
data Acc {A : Set} (R : A → A → Set) (a : A) : Set where
step : (∀ b → R b a → Acc R b) → Acc R a
□^ : ∀ {A : Set} (R : A → A → Set) → (A → Set) → (A → Set)
□^ R P a = ∀ b → R b a → P b
[_] : {A : Set} → (A → Set) → Set
[ P ] = ∀ {a} → P a
@gallais
gallais / FiniteMap.agda
Last active July 13, 2017 13:37
IntMap
module poc.FiniteMap where
open import Function
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
record _↔_ (A B : Set) : Set where
field push : A → B
pull : B → A