I can't get GHC to resolve the generic typeclass instance below: (The goal is to achieve the same effect as accessing the property x of point like x point, but, instead by utilizing type level strings)
data Label (l :: Symbol) =
Get
class Has a l b | a l -> b where
get :: a -> Label l -> b
instance (Generic r, GenericHas (Rep r) pl pt) => Has r pl pt where
get = genericHas . from
class GenericHas a l b | a l -> b where
genericHas :: a x -> Label l -> b
instance GenericHas (D1 a (C1 b (S1 (c ('Just pl) d e f) (Rec0 pt)))) pl pt where
genericHas (M1 (M1 (M1 (K1 v)))) _ = v
data Point =
Point
{ x :: Int
}
deriving (Show, Generic)
example :: Int
example = get (Point 1) (Get :: Label "x")
This below is the error:
* No instance for (GenericHas
(D1
('MetaData
"Point"
"Alba.Persistence"
"alba-0.1.0.0-w6KgEimatKAP1g0rWS7YT"
'False)
(C1
('MetaCons "Point" 'PrefixI 'True)
(S1
('MetaSel
('Just "x")
'NoSourceUnpackedness
'NoSourceStrictness
'DecidedLazy)
(Rec0 Int))))
"x"
Int)
arising from a use of `get'
* In the expression: get (Point 1) (Get :: Label "x")
In an equation for `example':
example = get (Point 1) (Get :: Label "x")