Skip to content

Instantly share code, notes, and snippets.

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

Izaak Meckler imeckler

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
@imeckler
imeckler / gist:3401817
Created August 20, 2012 07:22
All strings
-- The list where nth element is the list of strings of length n.
strings = iterate (map (:) letters <*>) letterStrings
where letterStrings = map (:[]) letters
letters = ['a'..'z']
@imeckler
imeckler / gist:3763245
Created September 21, 2012 19:00
LiveScript Guard
guard(pred, f) = if pred then f!
g(x) ->
y = getY!
<~ guard (x != y)
x + y
@imeckler
imeckler / gist:3885281
Created October 13, 2012 16:39
Pithy finite state machine in haskell
import Control.Monad
import Data.Maybe
import Prelude hiding (any, elem)
import Data.Foldable
type State = String
type Map a b = [(a, b)]
-- In Map State (Map Char (m State)), the monad m determines the kind of FSM that is being run.
-- If m = [] (or Set), these functions work as a NFA. If m = Maybe, we essentially have a DFA.
@imeckler
imeckler / Wordcount.hs
Last active October 12, 2015 19:18
A wordcount program in Haskell as an example of programming as data transformation
import qualified Data.Map as M
import Control.Arrow ((>>>))
import Data.List (intercalate)
import GHC.Exts (sortWith)
main = interact $ words
>>> foldr incr M.empty
>>> M.toList
>>> sortWith (negate . snd)
>>> map show
@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 / parse.hs
Created December 7, 2012 20:47
Booth_parse
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
import System.Directory (getDirectoryContents)
import qualified System.IO.Strict as S
import Data.String.Utils (split, join)
import qualified Data.HashMap.Lazy as M
import qualified Data.HashSet as H
import qualified Data.ByteString.Lazy as B
@imeckler
imeckler / Random_walk.hs
Last active December 13, 2015 18:58
A fast Haskell program to help answer the following question: How long does it take a person randomly walking on a grid to touch every square?
import Prelude hiding (scanl, length, takeWhile, sum, map)
import Data.List.Stream
import System.Random.Mersenne.Pure64
import qualified Data.Set as S
import Data.Word
randUpTo :: Int -> PureMT -> [Int]
randUpTo n gen = unfoldr make gen
where make g = let (k, g') = randomInt g in Just (k `mod` n, g')
@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 / 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
@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();