I added a Scala solution since Haskell is already well represented.<br><br>Regarding exercises that are easier in OO, I don&#39;t think you&#39;ll find one that a good Haskell programmer can&#39;t match in a functional style. But if you make simulation the goal of the exercise (rather than writing a program that takes input and produces the correct output however it likes), you&#39;ll get a nice compare/contrast of OO and non-OO approaches.<br>
<br>One idea (contrived and silly though it is) is modeling a Courier that delivers message to Persons. There is a standard default reply for all Persons, some individuals have their own default reply, and there are conditional replies based on the sender. Each reply has the ability to alter a Person&#39;s mood. The goal of the exercise would be to read in a CSV file in the form of &quot;To, From, Message&quot;, and then output the interactions based on rules. A sample run might look like:<br>
<br>Courier delivers &quot;let&#39;s have lunch&quot; from Susan to Joe<br>Joe replies &quot;Thanks for the message!&quot;<br>Courier delivers &quot;how&#39;s your day?&quot; from Joe&#39;s Best Friend to Joe<br>Joe replies &quot;Hey Best Friend, thanks for the message!&quot;<br>
Joe&#39;s mood changes from &quot;normal&quot; to &quot;happy&quot;<br><br>This would be a trivial exercise for any OO programmer, and I suspect solutions in different OO languages would look pretty much the same. But in pure functional programming there are more choices to make (particularly the choice of data structures and types), so you might see a wider range of creative approaches. <br>
<br><br><div class="gmail_quote">On Sun, May 27, 2012 at 8:21 PM, Alexander Solla <span dir="ltr">&lt;<a href="mailto:alex.solla@gmail.com" target="_blank">alex.solla@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div class="im">On Sun, May 27, 2012 at 7:07 PM, Richard O&#39;Keefe <span dir="ltr">&lt;<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><br>
On 26/05/2012, at 4:16 AM, David Turner wrote:<br>
&gt;<br>
&gt; I don&#39;t. I think the trouble is that classes don&#39;t add value in exercises of this size.<br>
<br>
</div>This was the key point, I think.<br>
In this example, there wasn&#39;t any significant behaviour that could be moved<br>
to superclasses.  For that matter, whether a supplier is plain, preferred,<br>
or problematic is, one hopes, not a *permanent* property of a supplier.<br>
<br>
Sometimes higher-order functions can substitute for classes.</blockquote><div><br></div></div><div>Functors can always substitute for OO classes.  A class system is a functor from the set of objects to a set of methods, mediated by inheritance, or things like message-passing, duck typing, prototyping, etc.</div>

<div><br></div><div>Functions with the type Foo -&gt; Foo can be easily used to implement a prototype based dispatch mechanism.  Indeed, this is a common Haskell pattern.  Define:</div><div><br></div><div>-- Library code:</div>

<div>defaultFoo :: Foo</div><div>defaultFoo = Foo { bar =  ..., baz = ... }</div><div><br></div><div>-- Client code</div><div>myFoo = defaultFoo { bar = myBar }</div><div><br></div><div>Things can get as complicated as you would like, up to and including inheritance, by using functors other than ((-&gt;) a)</div>

<div><br></div><div>The defining characteristic of OO is that objects are stateful, but self-contained entities.  How methods are defined and dispatched vary wildly across OO languages.</div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>