<div dir="ltr">One possible fix (tested on GHC-7.10.1 with lens-4.12.3):<div><br></div><div><div><font face="monospace, monospace">test2 :: (Test a, t ~ TestT a) => t -> a</font></div><div><font face="monospace, monospace">test2 = view (from myiso)</font></div></div><div><br></div><div>This might have something to do with type families not being injective, but I'm not completely sure.</div><div><br></div><div>I also agree that it might be possible to trigger this without lens, will try to find an example and post if I succeed.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 11 September 2015 at 05:28, Nikolay Amiantov <span dir="ltr"><<a href="mailto:ab@fmap.me" target="_blank">ab@fmap.me</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Cafe,<br>
<br>
I've been playing around with lens and stumbled upon strange GHC<br>
behaviour. Consider this source (using lens package and GHC 7.10.2):<br>
<br>
{-# LANGUAGE TypeFamilies #-}<br>
<br>
import Control.Lens<br>
<br>
class Test a where<br>
type TestT a<br>
myiso :: Iso' a (TestT a)<br>
<br>
test1 :: Test a => a -> TestT a<br>
test1 = view myiso<br>
<br>
test2 :: Test a => TestT a -> a<br>
test2 = view (from myiso)<br>
<br>
GHC would emit this error:<br>
<br>
/tmp/test.hs:13:9:<br>
Could not deduce (Control.Monad.Reader.Class.MonadReader<br>
(TestT a) ((->) (TestT a)))<br>
arising from a use of ‘view’<br>
from the context (Test a)<br>
bound by the type signature for test2 :: Test a => TestT a -> a<br>
at /tmp/test.hs:12:10-31<br>
In the expression: view (from myiso)<br>
In an equation for ‘test2’: test2 = view (from myiso)<br>
Failed, modules loaded: none.<br>
<br>
However, `MonadReader r ((->) r)` is defined for any and all `r`!<br>
Furthermore, `test1` has no problem with this and `view` there uses this<br>
instance too. The only difference that I see is the presence of a type<br>
family:<br>
<br>
* `test1` needs `MonadReader a ((->) a)`<br>
* `test2` needs `MonadReader (TestT a) ((->) (TestT a))`<br>
<br>
, but I don't understand how can this result in a different behavior.<br>
Notice that this likely may be reproduced somehow without lens -- I've<br>
spent some time trying to minify this example further but alas to no avail.<br>
<br>
Thanks in advance!<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Nikolay.<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>