{--<br>Thanks!<br>Yes, you got it right - I "want to make explicit the fact that the type s depends on k and v.<br>So I followed your advice and used the most simple way to do what I need:<br>--}<br><br>class Store s where<br>
put :: Eq k => (k, v) -> s k v -> s k v <br> get :: Eq k => k -> s k v -> Maybe v<br><br>instance Store OneCell where<br> put (k1, v1) (Cell(k, v)) = Cell(k1, v1)<br> get k (Cell (_, v)) = Just v<br>
<br>instance Store CellList where<br> put (k,v) (CLst xs) = CLst ((k,v) : xs)<br> get k (CLst xs) = lookup k xs<br><br><br>storePut :: (Store s, Eq k) => s k v -> k -> v -> s k v<br>storePut store key value = put (key, value) store <br>
<br>storeGet :: (Store s, Eq k) => k -> s k v -> Maybe v<br>storeGet key store = get key store<br><br>aCell :: OneCell String Int<br>aCell = Cell("one", 1)<br>lst :: CellList Int String<br>lst = CLst [(1, "one"),(2, "two"),(3, "three")]<br>
<br>st1 = storePut aCell "two" 2<br>st2 = storePut lst 4 "four" <br><br>-- v1 = storeGet "one" st2 -- error<br>v2 = storeGet "one" st1 -- ok<br><br>{--<br>And what does the word "newbie" imply to you when answering my question?<br>
In what case using 'fundeps' and 'associated types' will make sence for this example?<br>--}<br><br>Thanks again for your great help!<br>Dima<br> <br><div class="gmail_quote">On Sat, Jun 7, 2008 at 11:11 PM, Luke Palmer <<a href="mailto:lrpalmer@gmail.com">lrpalmer@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;"><div class="Ih2E3d"><br>
</div>Oops. Should be:<br>
<br>
get :: k -> s k v -> Maybe v<br>
<br>
And correspondingly for the later examples. After actually using my<br>
brain thinking about your problem, and reading the word "Newbie", I<br>
would absolutely stay away from the fundeps/associated types business.<br>
:-) Try to get this working with Cell and CellList first :-)<br>
<font color="#888888"><br>
Luke<br>
</font><div><div></div><div class="Wj3C7c"></div></div></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="Wj3C7c">
<br>
> If instead you have cell types which are restricted in what they can<br>
> store in different ways, you might explore fundeps or associated<br>
> types:<br>
><br>
> -- fundeps<br>
> class Store s k v | s -> k v where<br>
> put :: (k,v) -> s -> s<br>
> get :: s -> Maybe v<br>
><br>
> -- associated types<br>
> class Store s where<br>
> type Key s :: *<br>
> type Value s :: *<br>
> put :: (Key s, Value s) -> s -> s<br>
> get :: s -> Maybe (Value s)<br>
><br>
> But if you can get away with the former, I would recommend that before<br>
> looking into these advanced extensions.<br>
><br>
> Luke<br>
><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Dmitri O. Kondratiev<br><a href="mailto:dokondr@gmail.com">dokondr@gmail.com</a><br><a href="http://www.geocities.com/dkondr">http://www.geocities.com/dkondr</a>