Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
@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 / Rot13.hs
Last active December 6, 2023 10:15
Finding words that are their own rot13
module Rot13 where
import Control.Monad (guard)
import Data.Char (ord, chr, toLower, isLower)
import Data.Function (on)
import Data.List (sortBy)
import Data.Maybe (mapMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
module Container
%default total
record Container where
constructor MkContainer
shape : Type
position : shape -> Type
container : Container -> Type -> Type
@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 / TicTacToe.hs
Created February 20, 2016 15:33
A simple game of Tic-Tac-Toe using Haskell's gloss
import Data.Maybe
import Control.Monad
import Control.Applicative
import Graphics.Gloss
import Graphics.Gloss.Interface.Pure.Game
type Coordinates = (Int, Int)
data Player = Nought | Cross
@gallais
gallais / MutuallDefined.hs
Last active April 20, 2023 06:33
Mutually Defined Datatypes
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
module MutuallyDefined where
import Data.Type.Natural
@gallais
gallais / STLC.hs
Last active October 10, 2022 19:49
STLC
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PolyKinds #-}
module STLC where
-- Defining type and the corresponding singletons
@gallais
gallais / Error.idr
Created February 24, 2022 17:19
Error monad in CPS style
module Error
export
data Error : (err, a : Type) -> Type where
MkError : (forall r. (err -> r) -> (a -> r) -> r) -> Error err a
export %inline
runError : Error err a -> (err -> r) -> (a -> r) -> r
runError (MkError hdl) kE kV = hdl kE kV
module LambdaLetRec
import Data.List1
import Data.List.Quantifiers
--------------------------------------------------------------------------------
-- types
infixr 5 ~>
@gallais
gallais / ElemSplit.idr
Created September 30, 2021 10:16
Magic pattern-matching on `Elem`
import Data.String
import Data.List
import Data.List.Elem
import Decidable.Decidable
import Decidable.Equality
%default total
toWitness : (prf1 : Dec a) -> IsYes prf1 -> a
toWitness (Yes prf2) x = prf2