
Thank you all for responses! There are always more things to learn ^_^. I'll also take a look at the paper to understand better what's going on. On 09/11/2015 02:58 AM, Nikolay Amiantov wrote:
Hi Cafe,
I've been playing around with lens and stumbled upon strange GHC behaviour. Consider this source (using lens package and GHC 7.10.2):
{-# LANGUAGE TypeFamilies #-}
import Control.Lens
class Test a where type TestT a myiso :: Iso' a (TestT a)
test1 :: Test a => a -> TestT a test1 = view myiso
test2 :: Test a => TestT a -> a test2 = view (from myiso)
GHC would emit this error:
/tmp/test.hs:13:9: Could not deduce (Control.Monad.Reader.Class.MonadReader (TestT a) ((->) (TestT a))) arising from a use of ‘view’ from the context (Test a) bound by the type signature for test2 :: Test a => TestT a -> a at /tmp/test.hs:12:10-31 In the expression: view (from myiso) In an equation for ‘test2’: test2 = view (from myiso) Failed, modules loaded: none.
However, `MonadReader r ((->) r)` is defined for any and all `r`! Furthermore, `test1` has no problem with this and `view` there uses this instance too. The only difference that I see is the presence of a type family:
* `test1` needs `MonadReader a ((->) a)` * `test2` needs `MonadReader (TestT a) ((->) (TestT a))`
, but I don't understand how can this result in a different behavior. Notice that this likely may be reproduced somehow without lens -- I've spent some time trying to minify this example further but alas to no avail.
Thanks in advance!
-- Nikolay.