Skip to content

Instantly share code, notes, and snippets.

View jfdm's full-sized avatar

Jan de Muijnck-Hughes jfdm

View GitHub Profile
@jfdm
jfdm / Tupled.idr
Last active September 1, 2021 08:20
module Tupled
import Data.Vect
import Data.Fin
%default total
namespace Types
public export
@jfdm
jfdm / rebuttal-count.sh
Created April 21, 2021 11:07
Count words in a rebuttal, and show first n words that are not blockquotes and headings.
#!/bin/bash
# $1 first n words
# $2 the rebuttal.
echo "## WC"
grep -vE -e "^>" $2 | grep -vE -e "^#" | uniq | wc -w
echo ""
echo "## TeX Count"
grep -vE -e "^>" $2 | uniq | texcount -1 -
@jfdm
jfdm / 00-about.org
Last active November 2, 2020 19:48
LightClick: a linearly typed orchestration language for Systems-on-a-Chip Designs that supports lightweight dependent types in the form of domain-specific indexed-types.

About LightClick

LightClick is a linearly typed orchestration language for Systems-on-a-Chip Designs that supports lightweight dependent types in the form of domain-specific indexed-types.

Designs represent the specification of modules at the same level of design and we capture:

  • various port attributes at the type level:
    • port direction (input/output/inout)
    • wire sensitivity (high/low, rising/falling, or insensitive)
    • signal usage intent (clocking, reset, interrupt, control, information, general)
module Lambda
%default total
data Ty = TyFunc Ty Ty | TyNat
data Context = Empty | Extend Context Ty
data Contains : Context -> Ty -> Type where
@jfdm
jfdm / Example.idr
Last active May 1, 2020 19:57
An example showing how to deal with mutually defined data structures.
||| Dependent Types Suck!
|||
||| Sometimes dependent types push you towards mutually defined data
||| structures: I try to avoid them where I can. For me, this occurrs
||| when you need a helper data type where a container is not suitable
||| expressive at the type level to capture the inductive case. When
||| this happens you can index your helper data structure with the
||| signature of the top type. This helps remove the need for a mutual
||| definition, that is turn the call graph edge from being undirected
||| to directed.
@jfdm
jfdm / LeftPad.idr
Created April 4, 2019 18:55
A Verified LeftPad?
module LeftPad
import Data.List
data Padding : (s : List Char) -> (target : Nat) -> Type where
Pad : (pad : Nat) -> Padding s (length s + pad)
Nop : Padding (ys ++ x :: xs) (length ys)
padding : (s : List Char) -> (target : Nat) -> Padding s target
padding [] t = Pad t
@jfdm
jfdm / Filter.idr
Last active March 5, 2019 13:46
Valid filter.
import Data.List
import Data.List.Quantifiers
data SubsetEq : (xs, ys : List a) -> Type where
Empty : SubsetEq Nil xs
Cons : (Elem x ys)
-> SubsetEq xs ys
-> SubsetEq (x::xs) ys
@jfdm
jfdm / Thinnings.idr
Created January 23, 2019 12:24
An example of Thinnings for a very specific use case.
data CanSkip = MustKeep | CanSkip
data ThinnedList : (a : Type)
-> (contract : List (Pair a CanSkip))
-> Type
where
Empty : ThinnedList a Nil
Add : (x : a)
-> (rest : ThinnedList a xs) -> ThinnedList a ((x,b )::xs)
Skip : (rest : ThinnedList a xs) -> ThinnedList a ((x,CanSkip)::xs)
module Sorted
data LessThanOrEq : (x,y : type)
-> Type
where
IsLessThan : Ord type => {x,y : type} -> (prf : compare x y = LT) -> LessThanOrEq x y
IsEqual : Ord type => {x,y : type} -> (prf : compare x y = EQ) -> LessThanOrEq x y
data IsSorted : (list : List type)
-> Type
@jfdm
jfdm / Tree.py
Created September 21, 2018 14:25
Summing up the good and the bad of dynamic typing and a programmer's mental model.
class Tree():
pass
class Node(Tree):
def __init__(self,l,r,value):
self.l = l
self.r = r
self.value = value
class Leaf(Tree):