https://wiki.haskell.org/index.php?title=Constant_applicative_form&feed=atom&action=historyConstant applicative form - Revision history2016-08-25T02:39:44ZRevision history for this page on the wikiMediaWiki 1.19.14+dfsg-1https://wiki.haskell.org/index.php?title=Constant_applicative_form&diff=55632&oldid=prevHowardBGolden: Add link to Memoization#Memoising_CAFS2013-04-01T22:40:28Z<p>Add link to <a href="/Memoization#Memoising_CAFS" title="Memoization">Memoization#Memoising_CAFS</a></p>
<table class='diff diff-contentalign-left'>
<tr valign='top'>
<td colspan='1' style="background-color: white; color:black;">← Older revision</td>
<td colspan='1' style="background-color: white; color:black;">Revision as of 22:40, 1 April 2013</td>
</tr></table>HowardBGoldenhttps://wiki.haskell.org/index.php?title=Constant_applicative_form&diff=24524&oldid=prevAndrewBromage: Syntax fixen2008-12-06T01:27:41Z<p>Syntax fixen</p>
<table class='diff diff-contentalign-left'>
<tr valign='top'>
<td colspan='1' style="background-color: white; color:black;">← Older revision</td>
<td colspan='1' style="background-color: white; color:black;">Revision as of 01:27, 6 December 2008</td>
</tr></table>AndrewBromagehttps://wiki.haskell.org/index.php?title=Constant_applicative_form&diff=6908&oldid=prevBrettGiles: HaWiki conversion2006-10-12T01:33:03Z<p>HaWiki conversion</p>
<p><b>New page</b></p><div>Also referred to as CAF.<br />
<br />
Any [[super combinator]] which is not a [[lambda abstraction]]. This includes truly constant expressions such as <hask>12, (+ 1 2), [1,2,3]</hask> as well as partially applied functions such as <hask>(+ 4)</hask>. Note that this last example is equivalent under eta abstraction to <hask>\ x -> + 4 x</hask> which is not a CAF.<br />
<br />
==Examples and discussions==<br />
Since a CAF is a [[super combinator]], it contains no [[free variable]]s. Moreover, since it is not a [[lambda abstraction]] it contains no variables at all. It may however contain identifiers which refer to other CAFs, e.g.<br />
<br />
<haskell><br />
c 3 where c = (* 2).<br />
</haskell><br />
<br />
A CAF can always be lifted to the top level of the program. It can either be compiled to a piece of graph which will be shared by all uses or to some shared code which will overwrite itself with some graph the first time it is evaluated. A CAF such as<br />
<br />
<haskell><br />
ints = from 1 where from n = n : from (n+1)<br />
</haskell><br />
<br />
can grow without bound but may only be accessible from within the code of one or more functions. In order for the [[garbage collector]] to be able to reclaim such structures, we associate with each function a list of the CAFs to which it refers. When garbage collecting a reference to the function we collect the CAFs on its list.<br />
<br />
<br />
<br />
===Q&A discussion from HaWiki===<br />
:''What is the difference between ''<hask>((+) 4)</hask>'' and ''<hask>\x -> (+) 4 x</hask>'', apart from the obvious difference in notation? (I have braced the + to make the expressions compliant with Haskell syntax.)''<br />
::One is an application that returns a function and may imply some work in general, the other is a syntactic value (a lambda abstraction).<br />
<br />
:''If notation really happens to matter so much, then what about ''<hask>(4 +)</hask>'' and ''<hask>(+ 4)</hask>''? Are '''both''' of these CAFs? If we take away the nifty syntax, how do we express ''<hask>(+ 4)</hask>'' then? Or is it no longer a CAF? ;)''<br />
<br />
::It depends on how they desugar. `(4 +)` presumably desugars to `((+) 4)` and so is a CAF. If (+ 4) desugars to `\x -> x + 4` it isn't, if it desugars to `flip (+) 4` it is. -- DerekElkins<br />
<br />
:::''--- Rambler'' ''I'm afraid I still don't get it (or maybe I do, but I secretly wish it didn't mean '''that'''...) To the best of my understanding of the matter, `flip (+) 4` should return something that should behave exactly as `\x -> x + 4` would. Moreover, even if I take it for granted that `flip (+) 4` differs dramatically from `\x -> x + 4`, what happens when we expand the former?<br />
:::'''''There is no difference in ''behavior'' as far as meaning is concerned. They are just treated differently. -- DerekElkins'''''<br />
:::Suppose `flip` is defined as `\f x y -> f y x` (which it probably is, anyway,) then `flip (+) 4 where flip = \f x y -> f y x` is obviously not a CAF, according to the definition.<br />
:::What about `flip (+) 4 where flip f x y = f y x`???''<br />
::::''I believe that FOLDOC is incorrect here. A better way of thinking about CAFs is that a CAF is anything that can be let floated (see [[lifting pattern]]) to the top level. So a CAF can not only call other CAFs, but also other [[super combinator]]s.''<br />
:::::I believe that's already granted, according to the definition of a [[super combinator]]. A CAF may reference any [[super combinator]] simply by virtue of being one.<br />
::::''The difference between <hask>flip (+) 4</hask> and <hask>\x -> x + 4</hask> is that in a pure lambda calculus implementation, the former can be reduced but the latter cannot. Remember that <hask>\f x y -> f y x</hask> is a shorthand for <hask>\f -> (\x -> (\y -> f y x)))</hask>, which means if given two arguments, it can be reduced. --AndrewBromage''<br />
:::::Fine, is it then irreducibility that makes CAFs special? If so, then the current formulation of the definition clearly misses the point. If not, then why is this distinction relevant in the context of the definition?<br />
:::::In any case, I am left wondering 1) why irreducible expressions might be of such interest (apart from the trivially imaginable,) and 2) whatever happened to the proverbial [[referential transparency]]. It just struck me lately that my difficulty may be due to the fact that I am trying to make sense of CAFs in a broad theoretical context, whereas they may be simply an implementation instrument -- is this the case? --Rambler<br />
<br />
:'''You've inverted it slightly (or it reads that way): it's ''reducibility'' that makes CAFs special. Since they are reducible they may imply work; work that could be saved. Nevertheless, yes, one typically doesn't care whether something's a CAF or not as far as meaning goes. Read the relevant parts of the book I linked to below, if you haven't already. As for ReferentialTransparency, whether or not something is viewed as a CAF doesn't change it's meaning, i.e. it is just a different ''implementation'' of the ''same'' function. -- DerekElkins'''<br />
<br />
::''OK, it definitely makes sense now, thanks to everyone for the explanations and references. --Rambler''<br />
<br />
==See also==<br />
* Simon Peyton Jones' [http://research.microsoft.com/%7Esimonpj/papers/slpj-book-1987/index.htm Implementation of Functional Programming Languages] for more about this and related terms.<br />
* [[Memoising constant applicative forms]]<br />
[[Category:Glossary]]</div>BrettGiles