Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param traversal fails for nested lists (also nested Maybes etc) #88

Open
czechow-shadow opened this issue Apr 15, 2019 · 1 comment
Open

Comments

@czechow-shadow
Copy link

I just stumbled upon what looks like inconsistent behavior of auto derived traversal and generic-lens while employing nested lists (deep traversal?). Minimal example below (tested with generic-lens 1.1.0.0 and ghc 8.2.2):

{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE DeriveFoldable    #-}
{-# LANGUAGE DeriveFunctor     #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TypeApplications  #-}

module Lib where

import GHC.Generics

import Data.Generics.Product
import Control.Lens (traverseOf)

data MT a = MT [[a]] deriving (Show, Generic, Functor, Foldable, Traversable)

mt :: MT Int
mt = MT [[1]]

go :: IO ()
go = do
  correct <- traverse (\x -> pure $ succ x) mt
  wrong <- traverseOf (param @0) (\x -> pure $ succ x) mt

  putStrLn $ "Traversal results differ: " ++ show correct ++ " vs " ++ show wrong

We expect the results to be MT [[2]] in both cases, but generic-lens outputs MT [[1]].

@balajirrao
Copy link

balajirrao commented Apr 16, 2019

I've seen a version of this. In this case it fails to compile with generic-lens 1.1.0.0 on ghc 8.6.3

{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE DeriveFoldable    #-}
{-# LANGUAGE DeriveFunctor     #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TypeApplications  #-}

module GenericLensMinimalExample where

import GHC.Generics (Generic)
import Data.Generics.Product (param, Rec(..))
import Control.Lens (over)

data Foo a = Foo a deriving (Eq, Show, Generic)
data Bar b = Bar b deriving (Eq, Show, Generic)
data FooBar c = FooBar (Foo (Bar c)) deriving (Eq, Show, Generic)

foo :: FooBar Int -> FooBar String
foo = over (param @0) show
GenericLensMinimalExample.hs:19:13: error:
     Couldn't match type Int with [Char]
        arising from a functional dependency between:
          constraint Data.Generics.Product.Param.GHasParamRec
                        'Nothing (Foo (Bar Int)) (Foo (Bar [Char])) Int [Char]
            arising from a use of param
          instance Data.Generics.Product.Param.GHasParamRec
                      'Nothing a a c d
            at <no location info>
     In the first argument of over, namely (param @0)
      In the expression: over (param @0) show
      In an equation for foo’: foo = over (param @0) show

kcsongor added a commit that referenced this issue Jan 26, 2020
This is achieved by reusing HasTypes (as described in the paper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants