Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
@gallais
gallais / atleastn.agda
Last active September 15, 2018 11:25
lists of size at least n
open import Data.Nat
module atleastn (n : ℕ) {a} (A : Set a) where
open import Data.List using (List; length)
open import Data.Vec
record SizedList : Set a where
field list : List A
size : length list ≥ n
@gallais
gallais / Names.agda
Created June 2, 2018 20:27
Names with offsets
open import Data.String.Base
open import Data.Nat.Base
open import Data.List.Base
open import Relation.Binary.PropositionalEquality
infix 5 _at_
record Variable : Set where
constructor _at_
field name : String
@gallais
gallais / Impredicative.v
Created February 14, 2018 16:51
Using Impredicativity to beat the positivity checker
Inductive T :=
| Var : nat -> T
| App : T -> T -> T.
Inductive S e : Prop :=
| def: forall R, (forall i, R i -> S i) ->
(forall e', R e' -> S (App e e')) -> S e.
Definition def' :
forall e, (forall e', S e' -> S (App e e')) -> S e.
@gallais
gallais / FF.v
Created December 29, 2017 12:40
Proving FFs extensionally equal
Require Import ZArith.
Local Open Scope Z_scope.
Section FF.
Parameter A : Type.
Parameter (a b c d : A).
Definition FF := Z -> Z -> A.
module Instrumented where
import Control.Monad.State
data Counters = Counters
{ swaps :: !Int
, comparisons :: !Int
}
type Instrumented = State Counters
{-# LANGUAGE DeriveFunctor #-}
module MonadTree where
import Control.Monad
import Control.Monad.Fix
newtype Tree m a = Tree { runTree :: m (Node m a) }
deriving (Functor)
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module ICofree where
data Nat = Z | S Nat
@gallais
gallais / Main.hs
Last active December 6, 2017 22:08
Computing the intersection of two identical heatmaps, one with a black background and the other on a map
module Main where
import Codec.Picture
intersection :: Image PixelRGBA8 -> Image PixelRGBA8 -> Int -> Int -> PixelRGBA8
intersection a b x y =
let (PixelRGBA8 a1 a2 a3 a4) = pixelAt a x y
(PixelRGBA8 b1 b2 b3 b4) = pixelAt b x y
as = [a1, a2, a3]
bs = [b1, b2, b3]
@gallais
gallais / SortedList.ml
Last active October 26, 2017 13:39
Sorted list functor
type comparison = LT | EQ | GT
module type ORDERED =
sig
type t
val compare : t -> t -> comparison
end
module type SORTEDLIST =
functor (O : ORDERED) ->
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
module Terminal where