Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
@gallais
gallais / feq_dec.v
Created July 23, 2017 14:24
Writing a decision procedure for equality on fins
Inductive fin : nat -> Set :=
| F1 : forall {n : nat}, fin (S n)
| FS : forall {n : nat}, fin n -> fin (S n).
Definition C {m : nat} (x : fin (S m)) :=
{ x' | x = FS x' } + { x = F1 }.
Definition case {m : nat} (x : fin (S m)) : C x :=
match x in fin (S n) return { x' | x = FS x' } + { x = F1 } with
| F1 => inright eq_refl
@gallais
gallais / iotan.v
Created July 23, 2017 18:53
Generalising the statement
Require Import PeanoNat.
Require Import List.
Import ListNotations.
Fixpoint iota (n : nat) : list nat :=
match n with
| 0 => []
| S k => iota k ++ [k]
end.
open import Data.String
record Print (A : Set) : Set where
field
print : A → String
open Print {{…}} public
mutual
data α : Set where
@gallais
gallais / NbeIsASemantics.agda
Last active July 28, 2017 14:23
Nbe Is A Semantics
module NbeIsASemantics where
open import Data.Unit
open import Data.Empty
open import Data.Product
open import Agda.Builtin.List
data Ty : Set where
α : Ty
_⇒_ : Ty → Ty → Ty
@gallais
gallais / AllHList.hs
Last active September 12, 2017 17:16
Have fun with All and HList
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -Wall #-}
module AllHList where
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
module Terminal where
@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) ->
@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]
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module ICofree where
data Nat = Z | S Nat
{-# LANGUAGE DeriveFunctor #-}
module MonadTree where
import Control.Monad
import Control.Monad.Fix
newtype Tree m a = Tree { runTree :: m (Node m a) }
deriving (Functor)