On Mon, Apr 6, 2009 at 7:39 PM, Manuel M T Chakravarty <span dir="ltr"><<a href="mailto:chak@cse.unsw.edu.au">chak@cse.unsw.edu.au</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Peter Berry:<div><div class="h5"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
3) we apply appl to x, so Memo d1 a = Memo d a. unify d = d1<br>
<br>
But for some reason, step 3 fails.<br>
</blockquote>
<br></div></div>
Step 3 is invalid - cf, <<a href="http://www.haskell.org/pipermail/haskell-cafe/2009-April/059196.html" target="_blank">http://www.haskell.org/pipermail/haskell-cafe/2009-April/059196.html</a>>.<br>
<br>More generally, the signature of memo_fmap is ambiguous, and hence,
correctly rejected. We need to improve the error message, though.
Here is a previous discussion of the subject:<br>
<br>
<a href="http://www.mail-archive.com/haskell-cafe@haskell.org/msg39673.html" target="_blank">http://www.mail-archive.com/haskell-cafe@haskell.org/msg39673.html</a><br><font color="#888888">
<br>
Manuel</font></blockquote></div><br>The thing that confuses me about this case is how, if the type sig on memo_fmap is omitted, ghci has no problem with it, and even gives it the type that it rejected:<br><br>------------------------------------------------<br>
<br>{-# LANGUAGE TypeFamilies #-}<br><br>class Fun d where<br> type Memo d :: * -> *<br> abst :: (d -> a) -> Memo d a<br> appl :: Memo d a -> (d -> a)<br><br>memo_fmap f x = abst (f . appl x)<br><br>-- [m@monire a]$ ghci -ignore-dot-ghci<br>
-- GHCi, version 6.10.1: <a href="http://www.haskell.org/ghc/">http://www.haskell.org/ghc/</a> :? for help<br>--<br>-- Prelude> :l ./Memo.hs<br>-- [1 of 1] Compiling Main ( Memo.hs, interpreted )<br>-- Ok, modules loaded: Main.<br>
--<br>-- *Main> :t memo_fmap<br>-- memo_fmap :: (Fun d) => (a -> c) -> Memo d a -> Memo d c<br><br>-- copy/paste the :t sig<br><br>memo_fmap_sig :: (Fun d) => (a -> c) -> Memo d a -> Memo d c<br>
memo_fmap_sig f x = abst (f . appl x)<br><br>-- and,<br><br>-- *Main> :r<br>-- [1 of 1] Compiling Main ( Memo.hs, interpreted )<br>--<br>-- Memo.hs:26:35:<br>-- Couldn't match expected type `Memo d'<br>
-- against inferred type `Memo d1'<br>-- In the first argument of `appl', namely `x'<br>-- In the second argument of `(.)', namely `appl x'<br>-- In the first argument of `abst', namely `(f . appl x)'<br>
-- Failed, modules loaded: none.<br><br>------------------------------------------------<br><br>Matt<br>