Skip to content

Instantly share code, notes, and snippets.

View NickHeiner's full-sized avatar
💭
Wubba lubba dub dub!!

Nick Heiner NickHeiner

💭
Wubba lubba dub dub!!
View GitHub Profile
@23Skidoo
23Skidoo / Queue.ml
Created November 8, 2011 08:49
Purely functional queue in Ocaml
type 'a queue = Queue of 'a list * 'a list
let empty = Queue ([], []);;
let add q elt = match q with
| Queue (front, back) -> Queue (elt::front, back);;
let take q = match q with
| Queue ([], []) -> raise (Invalid_argument "Empty queue!")
| Queue (front, b::bs) -> b, (Queue (front, bs))