Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
@gallais
gallais / RoseTree.agda
Created June 28, 2016 14:00
Induction principle for RoseTrees
module RoseTree where
open import Level
open import Data.List as List
open import Data.Unit
open import Data.Product
data RoseTree {ℓ : Level} (A : Set ℓ) : Set ℓ where
node : (a : A) (ts : List (RoseTree A)) → RoseTree A
@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 / State.agda
Last active August 4, 2016 11:18
Based on the material discussed in https://www.youtube.com/watch?v=9v4_FQm-b4I
module State where
open import Data.Unit
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality
_⟶_ : {I : Set} (X Y : I → Set) → Set
X ⟶ Y = ∀ {i} → X i → Y i
@gallais
gallais / Mini2048.hs
Created August 22, 2016 12:24
Patched version of András Kovács' Mini2048 to use the arrow keys, turn off buffering and clear the screen regularly
-- Slight variant of https://gist.github.com/AndrasKovacs/9597994
{-
Copyright (C) 2014 András Kovács
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TO
@gallais
gallais / STLC.agda
Last active September 8, 2016 11:01 — forked from useronym/STLC.agda
module STLC (Atom : Set) (_≠_ : Atom → Atom → Set) where
open import Data.Empty
open import Data.Product as P hiding (_,_)
open import Data.List
open import Function hiding (_∋_)
data ★ : Set where
ι : ★
_⊳_ : ★ → ★ → ★
@gallais
gallais / Sums.agda
Last active September 12, 2016 15:57
Example of Small IR
module Sums where
open import Data.Nat
open import Data.Fin using (Fin; module Fin)
open import Function
sum : (k : ℕ) (f : Fin k → ℕ) → ℕ
sum zero f = 0
sum (suc k) f = f Fin.zero + sum k (f ∘ Fin.suc)
@gallais
gallais / Providers2.hs
Created September 13, 2016 14:25
Instance disambiguation using a type family
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PolyKinds #-}
@gallais
gallais / AllContexts.hs
Created September 15, 2016 00:33
Focusing on each element individually and applying a function to the foci
{-# LANGUAGE RecordWildCards #-}
module AllContexts where
import Data.List
data Context a = Context
{ before :: [a]
, focus :: a
, after :: [a]
@gallais
gallais / Vector.ml
Last active October 5, 2018 23:46
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
{-# OPTIONS_GHC -fdefer-type-errors #-}
{-# LANGUAGE RankNTypes #-}
module NumList where
import Data.Void
type NumList a = Num a => [a]
first :: NumList a -> a