Skip to content

Instantly share code, notes, and snippets.

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

Izaak Meckler imeckler

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
module State ( State
, return
, join
, map
, bind
, (>!=)
, run
, eval
, exec
, get
@imeckler
imeckler / Circles.elm
Created May 11, 2014 23:04
Elm example
import Keyboard
import List
import Window
import Color
import Random
input = dropRepeats Keyboard.space
ticks = fps 30
@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 / RevEcho.hs
Created May 7, 2014 19:58
Pipes example
module Main where
import Pipes
import qualified Pipes.Prelude as P
import Pipes.Network.TCP
import qualified Data.ByteString as B
main :: IO ()
main =
-- "serve" is from Network.Simple.TCP
@imeckler
imeckler / gadts.ml
Last active July 18, 2023 03:56
Lists with length in OCaml
(* These types are just used as indices for nlist. *)
type z = Z_
type 'a suc = S_
(* A term of type (n, m, k) add is a proof that n + m = k *)
type (_, _, _) add =
| AddZ : (z, 'n, 'n) add
| AddS : ('n, 'm, 'k) add -> ('n suc, 'm, 'k suc) add
(* An (n, 'a) nlist is a list of 'a of length n *)
@imeckler
imeckler / Algebra.hs
Created February 9, 2014 21:36
Algebra problems
import qualified Data.Map as M
import Data.List (nub, sort)
import qualified Data.Set as S
import Control.Applicative
-- problem 19 code
counts :: Ord a => [a] -> M.Map a Int
counts = foldl incr M.empty
where incr m x = M.insertWith (+) x 1 m
@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 =
@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 / 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 / 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();