Interested in learning more about algorithm design in functional programming, I picked up Andrew Bird's Pearls of Functional Algorithm Design. I have experience with a number of programming languages, but my only experience with functional programming is in Scala. I understood that I would have to pick-up Standard ML and Haskell from the description of the book, but when I started reading the first section, I wasn't familiar with some of the operators being used.
Here are some examples of function definitions from the first chapter of the book (free to preview on Amazon):
I have seen "^" and "v" used to represent "and" and "or," but some of the other syntax (like False (0,n)
) still throws me off.
In this one, I'm not sure what the accumArray(+)...
is referring to. I'm thinking it's like a fold method using addition, but I don't understand the rest of the line.
Here, the author has done a good job of describing that \\ is set difference and the two vertical lines crossed with a horizontal one is union. However, I've never seen anything like that union symbol before.
I don't want to know what each of these examples means as much as I want to know what library of formal representation is Bird using to represent these algorithms, and also, if a specific programming language (Haskell/SML?) syntax is being used as well in conjunction with these special symbols.
False (0, n)
for example throws you off? $\endgroup$False (0, n)
is not a subexpression.False
and(0, n)
are two values, given as arguments toaccumArray
. $\endgroup$False
that was taking two parameters: 0 and n. But C. A. McCann cleared up the misunderstanding. $\endgroup$accumArray
is being applied to four arguments--a "logical or" function, the boolean valueFalse
, a 2-tuple (pair) ofInt
s that appear to be array bounds, and a list of(Int, Bool)
pairs filtered so theInt
s are valid array indices (the whole second line). Thewhere
clause just definesn
as the length of the input list within the scope of the function body. $\endgroup$accumArray
function, which the documentation describes pretty clearly. $\endgroup$