Skip to content

Instantly share code, notes, and snippets.

View imeckler's full-sized avatar
🤷‍♂️
¯\_(ツ)_/¯

Izaak Meckler imeckler

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
@imeckler
imeckler / PiCalc.hs
Created April 10, 2013 00:52
Pi calculus
{-# LANGUAGE GADTs, StandaloneDeriving, RankNTypes #-}
type Var = String
data RecT a
data SendT a
data RepT a
data ParT a b
data NilT
data NuT a
@imeckler
imeckler / EltMouse.js
Last active December 17, 2015 23:49
Elm runtime patch
Elm.Native.EltMouse = function(elm){
'use strict';
elm.Native = elm.Native || {};
if (elm.Native.EltMouse) return elm.Native.EltMouse;
var Utils = Elm.Native.Utils(elm);
function EltClicks(input) {
this.id = Utils.guid();
@imeckler
imeckler / FFIex.idr
Created September 2, 2013 22:20
Idris FFI example
module Main
apply2 : (a -> b -> c) -> a -> b -> IO c
apply2 {a} {b} {c} f x y =
let funTy = FFunction (FAny a) (FFunction (FAny b) (FAny c)) -- What is the right FTy here?
in mkForeign (FFun "apply2" [funTy, FAny a, FAny b] (FAny c)) f x y
-- This works
apply1 : (a -> b) -> a -> IO b
apply1 {a} {b} f x =
@imeckler
imeckler / IdrisFFIWrap.idr
Last active December 22, 2015 06:39
Idris Javascript FFI hack
abstract
data Js : Type -> Type -- In the style of js_of_ocaml
wrap : (a -> b) -> Js (a -> b)
wrap {a} {b} f = unsafePerformIO (
mkForeign (FFun "wrapIdrisUncurried" [FAny (a -> b)] (FAny (Js (a -> b)))) f)
-- You can use it like so:
apply2 : Js (a -> b -> c) -> a -> b -> IO c
apply2 {a} {b} {c} f x y =
module State ( State
, return
, join
, map
, bind
, (>!=)
, run
, eval
, exec
, get
let check_merkle_lookup
: type a.
depth:int
-> root:Hash.Var.t
-> entry:Hash.Var.t
-> Bool_var.t list
-> ((hash, a) Merkle_tree.t, unit) T.t
=
fun ~depth ~root ~entry addr ->
let initial_path =
@imeckler
imeckler / integer_partitions.hs
Created November 21, 2012 05:57
Integer partitions in haskell
ps = [] : map parts [1..]
where parts n = [n] : [x : p | x <- [1..n], p <- ps !! (n - x), x <= head p]
@imeckler
imeckler / PipeChat.hs
Last active October 12, 2017 01:53
Pipes chat server
{-# LANGUAGE LambdaCase, DeriveGeneric, NamedFieldPuns, RecordWildCards, OverloadedStrings #-}
module Main where
import Pipes
import qualified Pipes.Prelude as P
import Pipes.Network.TCP
import qualified Data.ByteString as B
import qualified Data.HashTable.IO as H
import System.IO.Unsafe
import Data.Serialize
@imeckler
imeckler / BFS.hs
Last active October 12, 2017 01:55
BFS
{-# LANGUAGE LambdaCase #-}
import Control.Applicative
import Control.Monad.State
import System.Random
data Tree a = Empty | Bin a (Tree a) (Tree a)
deriving Show
-- O(n)
@imeckler
imeckler / pipeline.hs
Last active October 12, 2017 01:56
Haskell pipeline
{-# LANGUAGE GADTs #-}
import Data.Char (digitToInt)
data Nil
data Cons a b
data Pipeline ts a c where
(:>) :: (a -> b) -> Pipeline ts b c -> Pipeline (Cons (a -> b) ts) a c
Id :: Pipeline Nil t t