<br><br><div class="gmail_quote">On Feb 10, 2008 1:42 PM, Sebastian Sylvan <<a href="mailto:sebastian.sylvan@gmail.com">sebastian.sylvan@gmail.com</a>> 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 <<a href="mailto:mfeathers@mindspring.com" target="_blank">mfeathers@mindspring.com</a>> 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't complain:<br><br><br>data Thing = Thing (Integer -> Integer)<br><br><br><br>But, I've never seen that sort of construct in an example. Do people<br>
ever embed functions in ADTs?</blockquote></div><div><br>Yes, this is quite common. Here's a quick example (untested):<br><br>data MyMap key value = M (key -> Maybe value)<br></div></div><br>lookup (M m) key = m key<br>
insert (M m) key value = M (\key' -> if key' == key then Just value else m key')<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 (\_-> Nothing )<br><br></div></div>-- <br>Sebastian Sylvan<br>+44(0)7857-300802<br>UIN: 44640862