The code available from github:
{-# LANGUAGE TypeFamilies
, TypeOperators #-}
module Test where
import Control.Monad.Reader
import Control.Lens
import Control.Zipper
class Monad f => Family f where
type Set f
-- This does not work
f :: Family f => (Top :>> [Set f] :>> Set f) -> f (Set f)
f = return . view focus
-- This here works
g :: Top :>> [Int] :>> Int -> Int
g = view focus
compiles fine with ghc-8
but fails to compile with ghc-7.10
with the error
Test.hs:16:14:
Could not deduce (MonadReader
(Zipper (Top :>> [Set f]) Int (Set f))
((->) ((Top :>> [Set f]) :>> Set f)))
arising from a use of `view'
from the context (Family f)
bound by the type signature for
f :: Family f => (Top :>> [Set f]) :>> Set f -> f (Set f)
at Test.hs:15:6-57
In the second argument of `(.)', namely `view focus'
In the expression: return . view focus
In an equation for `f': f = return . view focus
in both cases exactly the same dependencies are used (mtl 2.2.1
, transformers 0.5.2
, lens 4.14
, zippers 0.2
) except base
which can only be 4.8
for ghc-7.10
and 4.9
for ghc-8
. I really cannot figure out why it should compile with one compiler and not the other. I would like to make the code work for ghc-7.10
as well.
I still do not know why this problem arises. But with the kind help of a user puregreen
over on #haskell
irc channel I was able to overcome this problem in this setting by simply replacing view focus
with (^. focus)
.