Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
@gallais
gallais / Joomy.agda
Created January 13, 2026 14:30
Levenshtein distance (basic definitions)
module Joomy where
open import Level using (Level)
open import Data.List.Base
as List
using ()
renaming (List to [>_]; [] to [>]; _∷_ to _:>_)
open import Data.Nat.Base using (ℕ; _+_; _≤_)
@gallais
gallais / EquationalReasoning.v
Last active August 27, 2025 17:53
Equational Reasoning in Coq, using tactics inside terms!
Require Import Coq.Setoids.Setoid.
Require Import Arith.
Notation "`Begin p" := p (at level 20, right associativity).
Notation "a =] p ] pr" := (@eq_trans _ a _ _ p pr) (at level 30, right associativity).
Notation "a =[ p [ pr" := (@eq_trans _ a _ _ (eq_sym p) pr) (at level 30, right associativity).
Notation "a `End" := (@eq_refl _ a) (at level 10).
Definition times2 : forall n, n + n = 2 * n := fun n =>
`Begin
@gallais
gallais / UntypedLambda.agda
Created September 7, 2015 18:53
Interpreting the untyped lambda calculus in Agda
{-# OPTIONS --copatterns #-}
module UntypedLambda where
open import Size
open import Function
mutual
data Delay (A : Set) (i : Size) : Set where
@gallais
gallais / Vector.ml
Last active June 11, 2025 16:36
Length-indexed lists
(*
We don't really care about the data constructors here
but they are needed, cf:
https://sympa.inria.fr/sympa/arc/caml-list/2013-10/msg00190.html
*)
type zero = Zero
type 'a succ = Succ
(*
[] has length 0
@gallais
gallais / Deriving.hs
Created November 25, 2024 15:00
Putting the FUN in Functors
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Deriving where
import Data.Kind (Type)
newtype Cst a i = MkCst { runCst :: a }
newtype Idt i = MkIdt { runIdt :: i }
newtype Prd k l i = MkPrd { runPrd :: (k i, l i) }
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeAbstractions #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Control.Concurrent (forkIO, MVar, newEmptyMVar, putMVar, takeMVar)
import Data.Kind (Type)
@gallais
gallais / ShaSearch.hs
Created November 19, 2024 17:05
Looking for self-referential sentences
module ShaSearch where
import System.Process (readProcess)
-----------------------------------------------
-- Using the list monad to generate all the
-- hexadecimal words of a given length
-- All the hexadecimal characters
hexa :: [Char]
@gallais
gallais / Currying.agda
Last active October 31, 2024 00:03
Currying using a Universe
module Currying where
open import Level
open import Data.Product as P using (_×_ ; _,_)
open import Function
data Universe (ℓ : Level) : Set (suc ℓ) where
set : (A : Set ℓ) → Universe ℓ
_**_ : (u₁ u₂ : Universe ℓ) → Universe ℓ
@gallais
gallais / ImperativeDSL.hs
Created July 26, 2016 23:31
Small well-scoped and well-typed by construction imperative DSL
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE PolyKinds #-}
module ImperativeDSL where
@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.