
It is late, but I was not sleepy enough, so here is my first translation of the
algorithm to a functional approach...
{- Quote wikipedia: http://en.wikipedia.org/wiki/Longest_increasing_subsequence
L = 0
M[0] = 0
for i = 1, 2, ... n:
binary search for the largest j ≤ L such that X[M[j]] < X[i] (or set j = 0
if no such value exists)
P[i] = M[j]
if j == L or X[i] < X[M[j+1]]:
M[j+1] = i
L = max(L, j+1)
-}
{-
X[i] defined for i = 1,2,3…
So X[0] is not defined.
Now, rethink '0' as Nothing, and 1≤j≤L since X[M[0]] is also undefined.
Not that after the binary search that one the three conditions holds:
X[i] ≤ X[M[1]]
"The same or a new minimum value"
P[i] is created and set to Nothing
If X[i] < X[M[1]] then M[1] is changed to i
X[M[j]] < X[i] ≤ X[M[j+1]] for some j