Skip to content

Instantly share code, notes, and snippets.

@snahor
Last active Sep 21, 2017
Embed
What would you like to do?
structure Pascal =
struct
local
fun nextrow row =
let
val (ns, _) =
foldl
(fn (x, (acc, prev)) => ((prev + x) :: acc, x))
([], 0)
row
in
1 :: ns
end
in
fun triangle 1 = [[1]]
| triangle n =
let
val rows = triangle (n - 1)
in
nextrow (hd rows) :: rows
end
val row = hd o triangle
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment