Skip to content

Instantly share code, notes, and snippets.

View eduardoleon's full-sized avatar

eduardoleon

View GitHub Profile
View qsort.sml
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
View euler165.cpp
#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 / GADT.hs
Created December 17, 2014 11:04
Polytypic programming using GADTs
View GADT.hs
{-# 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?
View HList.v
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
View DELETE
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
View arena.c
#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
View ghci
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)
@eduardoleon
eduardoleon / Hamming.hs
Created September 2, 2015 10:15
Python is super-readable and concise!
View Hamming.hs
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
View existing.sql
create table male
( male_id int not null
, name varchar(100) not null
, primary key (male_id) );
create table female
( female_id int not null
, name varchar(100) not null
, primary key (female_id) );
View santa-nerds
<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 (~DarkCthul@84.64.65.234) has quit: Quit: Bye
*** raunicolae (~raunicola@95.76.171.140) has quit: Client Quit [00:52]
<reaga> i had a really good idea
*** DarkCthulhu (~anirudh@101.63.161.88) has joined channel ##programming
<Sprocklem> what now?
<reaga> what if.. what if a web page played the sound "isnt it annoying when