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 / FoobarE.idr
Last active October 13, 2015 13:34
module FoobarE
import Effects
import Effect.State
import Effect.StdIO
namespace Lib
MyLib : Type -> Type
MyLib rTy = Eff rTy ['libstate ::: STATE (List Nat), STDIO]
@jfdm
jfdm / Domains.idr
Created October 14, 2015 17:35
Modelling Domains.
module Domains
allLTE : List Int -> Bool
allLTE Nil = True
allLTE (x::Nil) = True
allLTE (x::y::xs) = x < y && allLTE (y::xs)
data VRange : Int -> Int -> Bool -> Type where
MkVRange : VRange x y (x <= y)
@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
@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 / 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 / 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 / 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.
-- ------------------------------------------------------------- [ 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 / 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 #-}
-- |
@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 {