Skip to content

Instantly share code, notes, and snippets.

@rpearl
Created September 20, 2012 15:30
Show Gist options
  • Save rpearl/3756624 to your computer and use it in GitHub Desktop.
Save rpearl/3756624 to your computer and use it in GitHub Desktop.
Getting around stupid constraints
(* 03:40 < Oejet> How would you implement f n = [1, ..., n], using only map, or
foldl?
*)
fun range n = foldl (op ::) [] (
(fn fix => fix (fn f => fn n => case n of 0 => [] | n => n::f (n-1)))
(
fn f =>
(fn cell =>
(fn f' => (fn () => f')(cell := SOME f')
)(f (fn x => valOf (!cell) x))
)(ref NONE)
) n
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment