<div dir="ltr"><font class="Apple-style-span" color="#003333" face="&#39;trebuchet ms&#39;, sans-serif">Thanks, Patrick. I&#39;m disappointed, though, that no one has actually responded to my question. It wasn&#39;t how to solve KenKen. It was how best to deal with quasi-mutable data structures. </font><br clear="all">

<div dir="ltr"><font><font face="&#39;trebuchet ms&#39;, sans-serif"><i><font color="#003333"><br>-- Russ </font></i></font></font></div><br>
<br><br><div class="gmail_quote">On Thu, Nov 25, 2010 at 6:17 AM, Patrick LeBoutillier <span dir="ltr">&lt;<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@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;">

Russ,<br>
<br>
If I understand correctly KenKen is something like Sudoku except that<br>
the (more complicated) &quot;cages&quot;<br>
constraints replace the usual &quot;square&quot; constraints.<br>
<br>
Have you seen these sudoku solvers: <a href="http://www.haskell.org/haskellwiki/Sudoku" target="_blank">http://www.haskell.org/haskellwiki/Sudoku</a> ?<br>
<br>
Maybe you can get ideas there on how to attack the problem in a more<br>
functional fashion.<br>
<br>
<br>
Patrick<br>
<div><div></div><div class="h5"><br>
<br>
On Wed, Nov 24, 2010 at 9:58 PM, Russ Abbott &lt;<a href="mailto:russ.abbott@gmail.com">russ.abbott@gmail.com</a>&gt; wrote:<br>
&gt; My previous two messages suggest a Haskell coding principle: distinguish<br>
&gt; between fixed and (quasi-)mutable data structures. (I know values don&#39;t<br>
&gt; change, but I hope you understand what I mean. The cage and the cell in my<br>
&gt; previous example are quasi-mutable. They are conceptually mutable in the<br>
&gt; context of the problem.)  The fixed data structures can be organized any way<br>
&gt; one wants. The quasi-/conceptually-mutable elements should be referred to<br>
&gt; symbolically and stored in a Map. The maps themselves should be stored at a<br>
&gt; global level of the system&#39;s data structure so that it is easy to replace<br>
&gt; them when values change.<br>
&gt;<br>
&gt; -- Russ<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Nov 24, 2010 at 5:54 PM, Russ Abbott &lt;<a href="mailto:russ.abbott@gmail.com">russ.abbott@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Actually using a Map does solve the problem. The Map has to be kept at the<br>
&gt;&gt; level of the Tree rather than have each leaf node point to it.  So instead<br>
&gt;&gt; of just a Tree one has, say (Map, Tree). Then when one wants to change the<br>
&gt;&gt; property of something associated with a leaf node, one can just change the<br>
&gt;&gt; map. The Tree is unchanged.<br>
&gt;&gt;<br>
&gt;&gt; -- Russ<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Nov 24, 2010 at 2:02 PM, Russ Abbott &lt;<a href="mailto:russ.abbott@gmail.com">russ.abbott@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; OK. So putting a Map at Leaf nodes doesn&#39;t solve the problem.<br>
&gt;&gt;&gt; (Apparently I haven&#39;t been able to communicate what I see as the problem.)<br>
&gt;&gt;&gt; The problem that I&#39;m trying to get to is the need to write excessive code<br>
&gt;&gt;&gt; for something that would require a lot less code in an OO world.  It&#39;s not a<br>
&gt;&gt;&gt; matter of execution time or space. It&#39;s a matter of the amount of code one<br>
&gt;&gt;&gt; is required to write.<br>
&gt;&gt;&gt; -- Russ<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Nov 24, 2010 at 1:52 PM, Daniel Fischer<br>
&gt;&gt;&gt; &lt;<a href="mailto:daniel.is.fischer@web.de">daniel.is.fischer@web.de</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Wednesday 24 November 2010 22:12:37, Russ Abbott wrote:<br>
&gt;&gt;&gt;&gt; &gt; Cool. I wasn&#39;t aware of that notation.  It doesn&#39;t quite get to the<br>
&gt;&gt;&gt;&gt; &gt; issue though.<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; The problem I&#39;m concerned about is the need to define y in the first<br>
&gt;&gt;&gt;&gt; &gt; place. If one is chasing through a data structure and finds a need to<br>
&gt;&gt;&gt;&gt; &gt; change something buried within it, it seems necessary to rebuild<br>
&gt;&gt;&gt;&gt; &gt; everything that includes the changed thing.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; In general, values are immutable, so you can&#39;t &quot;change something buried<br>
&gt;&gt;&gt;&gt; within it&quot;. You have to build a new value containing some of the old<br>
&gt;&gt;&gt;&gt; stuff<br>
&gt;&gt;&gt;&gt; and a new part. Building the new value usually consists mostly of<br>
&gt;&gt;&gt;&gt; copying a<br>
&gt;&gt;&gt;&gt; couple of pointers (plus building the new part of course), so isn&#39;t too<br>
&gt;&gt;&gt;&gt; expensive normally.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; You can have mutable values in the IO or (ST s) monads, if you need<br>
&gt;&gt;&gt;&gt; them.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt; That is, I can&#39;t change a<br>
&gt;&gt;&gt;&gt; &gt; component of somethingNew without creating y. The point is there&#39;s<br>
&gt;&gt;&gt;&gt; &gt; nothing about x that changed,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The thing with the changed component is not x anymore.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt; and there may be nothing about (var1 x)<br>
&gt;&gt;&gt;&gt; &gt; that changed, and there may be nothing about var11 . var1 $ x that<br>
&gt;&gt;&gt;&gt; &gt; changed, etc. Yet one is apparently forced to keep track of and<br>
&gt;&gt;&gt;&gt; &gt; reconstruct all those elements.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The compiler takes care of that.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; Another example is to imagine a Tree in which the leaves contain<br>
&gt;&gt;&gt;&gt; &gt; &quot;objects.&quot; If I want to change a property of one of those leaf<br>
&gt;&gt;&gt;&gt; &gt; objects,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; You can&#39;t in general, the thing with a different property is a different<br>
&gt;&gt;&gt;&gt; object.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt; I am forced to rebuild all the ancestor nodes of that leaf down to<br>
&gt;&gt;&gt;&gt; &gt; rebuilding the root.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Yes (well, not you, the compiler does it), except if your tree contains<br>
&gt;&gt;&gt;&gt; mutable objects (IORefs/STRefs for example).<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; One way to avoid that is for the leaves to refer to their objects<br>
&gt;&gt;&gt;&gt; &gt; through a Map. Then changing a leaf object requires only that the<br>
&gt;&gt;&gt;&gt; &gt; value<br>
&gt;&gt;&gt;&gt; &gt; associated with key represented by the leaf be (re-)inserted into the<br>
&gt;&gt;&gt;&gt; &gt; Map.  The Tree itself need not change at all.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Oh, it will. If you change a Map, you get a new one, thus you get a new<br>
&gt;&gt;&gt;&gt; tree containing the new Map.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; But that trick isn&#39;t always available.  In the example we are talking<br>
&gt;&gt;&gt;&gt; &gt; about we can&#39;t make a Map where they keys are the instance variable<br>
&gt;&gt;&gt;&gt; &gt; names and the values are their values.  That would seem to do the job,<br>
&gt;&gt;&gt;&gt; &gt; but since the values are of different types, we can&#39;t create such a<br>
&gt;&gt;&gt;&gt; &gt; Map.<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;&gt; &gt; So now what?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Well, what&#39;s the problem with the compiler copying some nodes?<br>
&gt;&gt;&gt;&gt; Normally, that doesn&#39;t cost very much performance, if it does in your<br>
&gt;&gt;&gt;&gt; case,<br>
&gt;&gt;&gt;&gt; we&#39;d need to know more to suggest the best way to go.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt; *<br>
&gt;&gt;&gt;&gt; &gt; -- Russ *<br>
&gt;&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Beginners mailing list<br>
&gt; <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
&gt;<br>
&gt;<br>
<font color="#888888"><br>
<br>
<br>
--<br>
=====================<br>
Patrick LeBoutillier<br>
Rosemère, Québec, Canada<br>
</font></blockquote></div><br></div>