Skip to content

Instantly share code, notes, and snippets.

@LightAndLight
LightAndLight / Path.hs
Created February 9, 2020 09:30
Typed paths into datatypes
{-# language GADTs #-}
{-# language RankNTypes #-}\
{-# options_ghc -Wall -Werror #-}
module Path where
data Expr
= Add Expr Expr
| Int Int
| Declare String Expr
@LightAndLight
LightAndLight / Curry.idr
Created January 30, 2020 03:33
uncurry/curry with dependent types
Pi : (A:Type) -> (A -> Type) -> Type
Pi s t = (x:s) -> t x
Sigma : (A:Type) -> (A -> Type) -> Type
Sigma s t = (x:s ** t x)
uncurry :
{A:Type} ->
{B:A->Type} ->
{C:(x:A)->B x->Type} ->
{-# language GADTs, KindSignatures, DataKinds #-}
{-# language TemplateHaskell #-}
import Data.Kind (Type)
import Data.Ratio (Rational)
-- dependent-map
import Data.Dependent.Map (DMap)
import qualified Data.Dependent.Map as DMap
-- dependent-sum-template
import Data.GADT.Compare.TH (deriveGEq, deriveGCompare)
@LightAndLight
LightAndLight / Codec.idr
Created December 11, 2019 12:44
Well-types binary codecs in Idris
module Codec
%default total
data Bits : Nat -> Type where
Nil : Bits 0
Snoc :
{n:Nat} ->
Bits n ->
Bool ->
module Main where
data Thin a = Thin [Int] a
data Exp
= Var
| Lam Bool (Thin Exp)
| App (Thin Exp) (Thin Exp)
data Closure a = Closure (Scope a) a
@LightAndLight
LightAndLight / file.md
Last active October 17, 2019 01:30
Lately I've been writing a lot of files that represent `String`s, then reading them in and running string interpolation on them. What if there was a system that could statically check all that?
--- begin some_template.string ---
Hello, this a big long string. It's an expression.
It might reference variables, like this: $ref1, or this: ${ref2.property}
---  end  some_template.string ---
--- begin three.expr ---
1 + 2
@LightAndLight
LightAndLight / Graph.hs
Created August 8, 2019 01:47
Type safe graphs using DMap
{-# language GADTs, StandaloneDeriving #-}
{-# language LambdaCase #-}
{-# language MultiParamTypeClasses #-}
{-# language TemplateHaskell #-}
module Graph where
import Control.Applicative
import Data.Dependent.Map (DMap)
import Data.Dependent.Sum (ShowTag(..))
import Data.GADT.Compare.TH (deriveGEq, deriveGCompare)
@LightAndLight
LightAndLight / Red.agda
Created July 17, 2019 06:35
almost strong normalisation
module Red where
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; Extensionality; sym)
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat using (ℕ; suc; zero)
open import Data.Vec using (Vec; _∷_; []; lookup; _[_]=_; here; there)
open import Data.Product using (∃-syntax; _×_; _,_; proj₁; proj₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Unit using (⊤; tt)
open import Data.Empty using (⊥; ⊥-elim)
module Load where
import Distribution.ModuleName (ModuleName)
import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
import Distribution.Simple (simpleUserHooks)
import Distribution.Simple.BuildPaths (getLibSourceFiles)
import Distribution.Simple.Configure (findDistPrefOrDefault, configure)
import Distribution.Simple.Flag (fromFlagOrDefault, flagToMaybe, toFlag)
import Distribution.Simple.LocalBuildInfo (localPkgDescr, withLibLBI)
import Distribution.Simple.Program.Db (defaultProgramDb)