This post originated from an RSS feed registered with Ruby Buzz
by Eigen Class.
Original Post: Some functional programming and OCaml koans
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
One day, a disciple of another sect came to Xavier Leroy and said mockingly:
"The OCaml compiler seems very limited: why do you have to indicate when a
function is recursive, cannot the compiler infer it?"
Xavier paused for a second, and replied patiently with the following story:
"One day, a disciple of another sect came to Xavier Leroy and said
mockingly..."
Polymorphic answers
A novice came to Jacques Garrigue and spoke nervously: "I don't get rank-2
polymorphism. What is it good for? When to use it? How can I understand it?".
Jacques asked: "Do you want an answer to each question, or the answer to
all your questions?." The novice was enlightened.
Leroy instructs a student
The venerable master Leroy was walking with his student. Wishing to start a
discussion with his master, the apprentice said "Master, I've heard that all
loops must be replaced with tail-recursive functions. Is that true?" Leroy
looked commiseratively at his student and replied "Foolish pupil, many
tail-recursive functions are merely inefficient loops."
The student spent the next few weeks replacing tail-recursive functions with
explicit loops. He finally showed his code to master Leroy, seeking his
approval. Leroy hit him with a stick. "When will you learn? Explicit loops
are a poor man's tail-recursive functions." At that moment, the student became
enlightened.
Complete solutions
Anton had been studying the dining philosophers problem and was ecstatic when
he presented a novel solution to Damien Doligez. The great master did not show
the same enthusiasm, though: all he said was "the solution is not complete".
Anton knew that Doligez had written a machine-checked proof of correctness for
the concurrent GC he developed in the early 90s for Caml Light, and began to
work. After struggling with Coq, he came back to Doligez.
"I have proved that my solution prevents starvation and livelock."
Again, Doligez replied: "the solution is not complete".
Anton retorted: "My correctness proof has been verified mechanically.
Moreover, my simulations show that my method allows for a large degree of
concurrency, and it's easy to implement efficiently. Surely the solution is
complete now?"
The Zen master then explained: "You claim to have solved the dining
philosophers problem, yet you haven't expounded where the spaghetti come
from."