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 / 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):
@jfdm
jfdm / DijkstraMonad.idr
Last active December 8, 2017 20:34
I heard you like monads, so I put a monad in your monad.
module DijkstraMonad
data NormalMonad : (A : Type) -> Type where
Return : (value : a) -> NormalMonad a
Bind : (doThis : NormalMonad a) -> (thenThis : a -> NormalMonad b) -> NormalMonad b
data DijkstraMonad : (A : Type) -> (NormalMonad A) -> Type where
DReturn : {A : Type}
-> (a : A)
-> DijkstraMonad A (Return a)
@jfdm
jfdm / Tree.swift
Last active August 21, 2017 09:39
Playing around with Tree's in Swift.
protocol Show {
func show() -> String
}
class Tree<T> : Show {
func show() -> String { return "" }
}
class Leaf<T> : Tree<T> {
override func show() -> String {
@jfdm
jfdm / FindRelations.hs
Created November 28, 2016 12:44
A simple utility to parse a CSV file listing pairs, and find relations between said pairs.
#!/usr/bin/env stack
-- stack --resolver lts-7.10 --install-ghc runghc
-- --package text
-- --package bytestring
-- --package containers
-- --package cassava
-- --package generics
-- --package vector
{-# LANGUAGE DeriveGeneric #-}
-- |
-- ------------------------------------------------------------- [ Channel.idr ]
-- Module : Channel.idr
-- Copyright : (c) Jan de Muijnck-Hughes
-- License : see LICENSE
--
-- A effectful API for `System.Concurrency.Sessions`.
--
-- The code was partially adapted from existing code developed by
-- Edwin Brady (see `FILE_IO` effect) and Simon Fowler---see `Process`
-- effect in `IdrisNet2`.
@jfdm
jfdm / Pairing.idr
Last active September 24, 2016 16:21
What pairings in Idris can look like at least.
module Pairing
||| Model different group types.
data GTy = G1 | G2 | GT
||| Group element, implementation is incomplete but shows how dependent types can be used to provide more infomation.
data Element : GTy -> Type where
MkElement : value -> (ty : GT) -> Element ty
||| Pairing information, implementation is incomplete.
@jfdm
jfdm / Constraints.idr
Last active September 13, 2016 20:27
module Data.List.Constraints
import Data.Vect
data NotElem : a -> List a -> Type where
NotHere : NotElem x []
NotThere : Eq ty => {x,y : ty} -> {auto prf : x /= y = True} -> NotElem x xs -> NotElem x (y::xs)
data AllDiff : List a -> Type where
@jfdm
jfdm / DList.idr
Created September 9, 2016 16:55
MFE for Idris regression.
module Data.DList
using (aTy : Type, elemTy : (aTy -> Type), x : aTy)
||| A list construct for dependent types.
|||
||| @aTy The type of the value contained within the list element type.
||| @elemTy The type of the elements within the list
||| @as The List used to contain the different values within the type.
public export
@jfdm
jfdm / Arith.py
Created May 31, 2016 21:17
Python is strange but amusing, but interesting, and with mypy I like it.
class Expr(object):
def __init__(self):
raise NotImplementedError
def eval(self):
raise NotImplementedError
class Value(Expr):
def __init__(self, value):
self.value = value
@jfdm
jfdm / Interp.idr
Last active October 26, 2017 22:03
Well Typed Interpreter using generic structures of context and environment.
||| You need latest version of my containers package:
||| https://github.com/jfdm/idris-containers/
module Interp
import Data.DList
import Data.DeBruijn
data Ty = TyInt | TyBool | TyFun Ty Ty