You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]].
The text was updated successfully, but these errors were encountered:
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 #-}
moduleGenericLensMinimalExamplewhereimportGHC.Generics (Generic)
importData.Generics.Product (param, Rec(..))
importControl.Lens (over)
dataFooa=Fooaderiving (Eq, Show, Generic)
dataBarb=Barbderiving (Eq, Show, Generic)
dataFooBarc=FooBar (Foo (Barc)) deriving (Eq, Show, Generic)
foo::FooBarInt->FooBarString
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 (BarInt)) (Foo (Bar [Char])) Int [Char]’
arising from a use of‘param’instance‘Data.Generics.Product.Param.GHasParamRec
'Nothing aacd’at<nolocationinfo>•In the first argument of‘over’, namely ‘(param @0)’In the expression: over (param @0) showIn an equation for ‘foo’: foo = over (param @0) show
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):
We expect the results to be MT [[2]] in both cases, but generic-lens outputs MT [[1]].
The text was updated successfully, but these errors were encountered: