Programming in Scala”
fpiscompanion
fpiscompanion
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter notes 8<br />
Parametricity<br />
When we can “follow the type” of a function to derive the only possible implementation, we say<br />
that the def<strong>in</strong>ition is given by parametricity. See the Wikipedia article on parametricity²², and Philip<br />
Wadler’s paper Theorems for free!²³<br />
Curry<br />
The idea of Curry<strong>in</strong>g²⁴ is named after the mathematician Haskell Curry.²⁵ He also discovered one of<br />
the most important results <strong>in</strong> computer science, the Curry-Howard isomorphism²⁶ which says that<br />
a program is a logical proof, and the hypothesis that it proves is its type.<br />
Function composition<br />
Function composition <strong>in</strong> functional programm<strong>in</strong>g is closely related to function composition <strong>in</strong><br />
mathematics.²⁷<br />
FAQ for chapter 2<br />
Are tail calls optimized if the @annotation.tailrec annotation isn’t there?<br />
They are still optimized, but the compiler won’t warn you if it can’t do the tail call optimization.<br />
Is there a list of other annotation types somewhere?<br />
See the Scaladoc for the Annotation class²⁸, and expand the ‘known subclasses section’.<br />
Is the common style to def<strong>in</strong>e loops us<strong>in</strong>g local function, rather than a<br />
(private) standalone function?<br />
Yes, this is much more common. There’s no need to pollute the namespace with helper functions<br />
you aren’t expect<strong>in</strong>g to be called by anyone.<br />
Is a || go(x) considered a tail call? What about a && go(x)?<br />
Yes<br />
²²http://en.wikipedia.org/wiki/Parametricity<br />
²³http://homepages.<strong>in</strong>f.ed.ac.uk/wadler/topics/parametricity.html<br />
²⁴http://en.wikipedia.org/wiki/Curry<strong>in</strong>g<br />
²⁵http://en.wikipedia.org/wiki/Haskell_Curry<br />
²⁶http://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence<br />
²⁷http://en.wikipedia.org/wiki/Function_composition<br />
²⁸http://www.scala-lang.org/api/current/<strong>in</strong>dex.html#scala.annotation.Annotation