Hi, I was toying around with types traversal and observed a change of behaviour when I start using Text in my records.
Consider this MWE (imports in cabal : text, lens, generic-lens, generic-deriving, with lts-12.20 and ghc-8.4.4):
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module Main (main) where
import Control.Lens.Fold
import Data.Generics.Product.Types
import Data.Text
import GHC.Generics
newtype Name = Name Text deriving (Eq, Show, Generic)
data Description = N None | S Sirname | M Multiple deriving (Eq, Show, Generic)
data None = None deriving (Eq, Show, Generic)
data Sirname = Sirname {
honorific :: Text,
name :: Name
} deriving (Eq, Show, Generic)
data Multiple = Multiple {
descr :: Text,
titles :: [(Text, [Description])]
} deriving (Eq, Show, Generic )
main :: IO ()
main =
print $ toListOf (types @Name) person
person :: Description
person = M $ Multiple "" [
( "born", [N None] ),
( "created", [S $ Sirname "sir" (Name "John") ] ),
( "created", [S $ Sirname "duke of" (Name "Duchy") ] )
]
The compilation fails with
• No instance for (Data.Generics.Product.Types.HasTypes'
(Data.Generics.Product.Types.Snd
(Data.Generics.Product.Types.InterestingOr
(Data.Generics.Product.Types.InterestingOr
(Data.Generics.Product.Types.Interesting'
(Rep Text) Name '[Text, Sirname, None, Description])
(M1
S
('MetaSel
('Just "name")
'NoSourceUnpackedness
'NoSourceStrictness
'DecidedLazy)
(Rec0 Name))
Name)
(M1
C
('MetaCons "M" 'PrefixI 'False)
(S1
('MetaSel
'Nothing
'NoSourceUnpackedness
'NoSourceStrictness
'DecidedLazy)
(Rec0 Multiple)))
Name))
Description
Name)
arising from a use of ‘types’
• In the first argument of ‘toListOf’, namely ‘(types @Name)’
In the second argument of ‘($)’, namely
‘toListOf (types @Name) person’
In the expression: print $ toListOf (types @Name) person
However, if I replace all mentions of Text by String, the compilation goes well and the output is correct.
How do I circumvent this problem?
Hi, I was toying around with
typestraversal and observed a change of behaviour when I start usingTextin my records.Consider this MWE (imports in cabal :
text, lens, generic-lens, generic-deriving, with lts-12.20 and ghc-8.4.4):The compilation fails with
However, if I replace all mentions of
TextbyString, the compilation goes well and the output is correct.How do I circumvent this problem?