Skip to content

Instantly share code, notes, and snippets.

View eduardoleon's full-sized avatar

Eduardo León eduardoleon

View GitHub Profile
<Quashie> I'm heading to new york city and questioning my future
<Quashie> for the holidays
<nso95_> I'm questioning your future too [00:51]
<someoneigna> Well my future is going to be dark >_<
*** DarkCthulhu ([email protected]) has quit: Quit: Bye
*** raunicolae ([email protected]) has quit: Client Quit [00:52]
<reaga> i had a really good idea
*** DarkCthulhu ([email protected]) has joined channel ##programming
<Sprocklem> what now?
<reaga> what if.. what if a web page played the sound "isnt it annoying when
#include <cstdint>
#include <iostream>
#include <set>
#include <vector>
#include <boost/rational.hpp>
using ext_coord = std::int64_t;
using int_coord = boost::rational<ext_coord>;
@eduardoleon
eduardoleon / PatMat.hs
Created December 17, 2014 11:02
Pattern matching vs. Visitor pattern
import Control.Applicative
data Person = Boy String
| Girl String
data Animal = Dog String
| Cat String
| Bug
boy (Dog n) = " plays with " ++ n
@eduardoleon
eduardoleon / GADT.hs
Created December 17, 2014 11:04
Polytypic programming using GADTs
{-# LANGUAGE GADTs #-}
import Control.Arrow
data Sized a where
Unit :: Sized ()
Int :: Sized Int
Char :: Sized Char
Sum :: Sized a -> Sized b -> Sized (Either a b)
Prod :: Sized a -> Sized b -> Sized (a, b)
@eduardoleon
eduardoleon / HList.v
Last active August 29, 2015 14:14
Simply-typed lambda calculus. Which one is clearer: termDen or termDenote?
Require Import List.
Section HList.
Variable A : Type.
Variable B : A -> Type.
Inductive hlist : list A -> Type :=
| HNil : hlist nil
| HCons : forall x xs, B x -> hlist xs -> hlist (x :: xs).
@eduardoleon
eduardoleon / DELETE
Created March 31, 2015 11:19
2-3 tree rotations
In all cases, the subtree marked with an asterisk is one level shallower than its siblings.
CASE 1:
--------- ---------
| 1 | 4 | | 1 | 3 |
--------- ---------
/ | \ / | \
a | e* a | \
--------- ===> ----- -----
@eduardoleon
eduardoleon / arena.c
Created March 31, 2015 16:18
Simple arena allocation
#include <stdint.h>
#include <stdlib.h>
#include "arena.h"
struct block {
union {
struct block *prev;
max_align_t nope;
};
@eduardoleon
eduardoleon / ghci
Last active August 29, 2015 14:27
Parentheses generation benchmark: GHCi vs. OCaml vs. Poly/ML
lolcathost% ghci
GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help
> type F a = (a, a)
> type G a = F (F a)
> type H a = G (G a)
> type I a = H (H a)
> type J a = I (I a)
> type K a = J (J a)
> let f :: a -> F a ; f x = (x, x)
> let g :: a -> G a ; g x = f (f x)
datatype 'a tree
= Leaf
| Node of 'a tree * 'a * 'a tree
fun build (op <) =
let
fun loop nil = Leaf
| loop (x :: xs) =
let
val (xs, ys) = List.partition (fn y => y < x) xs
@eduardoleon
eduardoleon / Hamming.hs
Created September 2, 2015 10:15
Python is super-readable and concise!
merge xxs@(x:xs) yys@(y:ys) =
case compare x y of
LT -> x : merge xs yys
EQ -> x : merge xs ys
GT -> y : merge xxs ys
xs = map (*2) hamming
ys = map (*3) hamming
zs = map (*5) hamming