<div class="gmail_quote">On Sun, Dec 13, 2009 at 12:21 PM, Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Sun, Dec 13, 2009 at 11:24:06AM +0100, Heinrich Apfelmus wrote:<br>
><br>
> In other words, the book in your example is not a real book, it's just a<br>
> few bytes in the computer that model it for the purpose of tracking<br>
> whether it's lent out or not. For instance, these few bytes can be a<br>
> unique ID and a possible lend function is<br>
><br>
> lend :: BookID -> Library -> Library<br>
<br>
</div>I should also point out that people coming from an OO or imperative<br>
background often look at a function like this and think it looks<br>
incredibly inefficient --- why throw away the entire *library* and<br>
build a new one *from scratch* when all we want to do is modify one<br>
little part of it? This seems a huge price to pay for immutability!<br>
<br>
But this line of thinking confuses abstract semantics with concrete<br>
implementation (something that imperative programming unfortunately<br>
tends to encourage, in my experience). The runtime is free to<br>
implement operations like "lend" any way it likes, as long as the<br>
abstract semantics are preserved.<br></blockquote></div>+1<br><br>One of the turning points in learning the FP way is the realization that the conception of "function" as a "machine" or "transformation process" is misleading or even harmful. For most programmers coming from an imperative language background that's going to mean returning to a more mathematically pure notion of function, which means discarding the idea of mutating parts of an object in favor of establishing relations among different "objects" and letting the compiler worry about the gory details. Youschkevitch's fascinating <a href="http://www.springerlink.com/content/p3x21230u404p13h/">history of the concept</a> might be useful.<br>
<br>-gregg<br>