<br><br><div class="gmail_quote">On Feb 10, 2008 1:42 PM, Sebastian Sylvan &lt;<a href="mailto:sebastian.sylvan@gmail.com">sebastian.sylvan@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote"><div class="Ih2E3d">On Feb 10, 2008 1:34 PM, Michael Feathers &lt;<a href="mailto:mfeathers@mindspring.com" target="_blank">mfeathers@mindspring.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

On a lark, I loaded this into Hugs this morning, and it didn&#39;t complain:<br><br><br>data Thing = Thing (Integer -&gt; Integer)<br><br><br><br>But, I&#39;ve never seen that sort of construct in an example. &nbsp;Do people<br>

ever embed functions in ADTs?</blockquote></div><div><br>Yes, this is quite common. Here&#39;s a quick example (untested):<br><br>data MyMap key value = M (key -&gt; Maybe value)<br></div></div><br>lookup (M m) key = m key<br>
insert (M m) key value = M (\key&#39; -&gt; if key&#39; == key then Just value else m key&#39;)<br clear="all">
<br>This is a naive data structure for storing a map as a function from the key to the value. Not very efficient, perhaps, but you use similar concepts in more useful scenarios (e.g. the State monad).<br><font color="#888888"></font></blockquote>
<div><br>Perhaps I should add an empty MyMap too:<br><br>empty = M (\_-&gt; Nothing )<br><br></div></div>-- <br>Sebastian Sylvan<br>+44(0)7857-300802<br>UIN: 44640862