Hello dear friends.
I’m struggling with barbies.
Consider:
import "base" GHC.Generics (Generic)
import "base" Data.Functor.Identity (Identity(..))
import "barbies" Data.Functor.Barbie
data A' f = A
{ name :: f Int
, thing :: f Int
}
deriving (Generic, FunctorB)
Works fine.
Also fine:
data A' f = A
{ name :: f Int
, thing :: [f Int]
}
deriving (Generic, FunctorB)
(thing
is now a list of f Int
)
But …
data A' f = A
{ name :: f Int
, thing :: f [f Int]
}
deriving (Generic, FunctorB)
(thing
now an f [f int]
fails with:
<interactive>:5:24: error:
• No instance for (barbies-2.0.4.0:Barbies.Generics.Functor.GFunctor
0
f
g
(Rec (barbies-2.0.4.0:Data.Generics.GenericN.Param 0 f [barbies-2.0.4.0:Data.Generics.GenericN.Param 0 f Int]) (f [f Int]))
(Rec (barbies-2.0.4.0:Data.Generics.GenericN.Param 0 g [barbies-2.0.4.0:Data.Generics.GenericN.Param 0 g Int]) (g [g Int])))
arising from the 'deriving' clause of a data type declaration
Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself
• When deriving the instance for (FunctorB A')
)
So okay, plan 1, can I make it a different argument (and live with having to write the desired type twice)? No
data A' f g = A
{ name :: f Int
, thing :: f [g Int]
}
deriving (Generic, FunctorB)
Gives:
<interactive>:5:24: error:
• No instance for (barbies-2.0.4.0:Barbies.Generics.Functor.GFunctor
0 f1 g (Rec (f [barbies-2.0.4.0:Data.Generics.GenericN.Param 0 f1 Int]) (f [f1 Int])) (Rec (f [barbies-2.0.4.0:Data.Generics.GenericN.Param 0 g Int]) (f [g Int])))
arising from the 'deriving' clause of a data type declaration
Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself
• When deriving the instance for (FunctorB (A' f))
Plan 2, can I make a new type that hides things?
data A' f g = A
{ name :: f Int
, thing :: f [X' g]
}
deriving (Generic, FunctorB)
newtype X' g = X { x :: g Int }
deriving (Generic, FunctorB)
Yep!
But wait, can I just remove that g
now?
data A' f = A
{ name :: f Int
, thing :: f [X' f]
}
deriving (Generic, FunctorB)
newtype X' g = X { x :: g Int }
deriving (Generic, FunctorB)
No.
<interactive>:7:11: error:
• No instance for (barbies-2.0.4.0:Barbies.Generics.Functor.GFunctor
0
f
g
(Rec (barbies-2.0.4.0:Data.Generics.GenericN.Param 0 f [X' (barbies-2.0.4.0:Data.Generics.GenericN.Param 0 f)]) (f [X' f]))
(Rec (barbies-2.0.4.0:Data.Generics.GenericN.Param 0 g [X' (barbies-2.0.4.0:Data.Generics.GenericN.Param 0 g)]) (g [X' g])))
arising from the 'deriving' clause of a data type declaration
Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself
• When deriving the instance for (FunctorB A')
But wait, what if I do something crazy and introduce a meaningless field:
data A' f g = A
{ name :: f Int
, thing :: f [X' f]
, meaningless :: g Int
}
deriving (Generic, FunctorB)
newtype X' g = X { x :: g Int }
deriving (Generic, FunctorB)
Yep!
Does this work on the original scheme? Yep.
data A' f g = A
{ name :: f Int
, thing :: f [f Int]
, meaningless :: g Int
}
deriving (Generic, FunctorB)
Please help. What is going on?!