我正在尝试为其定义一个Monoid
实例,HList Record
但我收到了重叠的实例错误消息。我的尝试(代码看起来很复杂,但基本上就是元组实例)
{-# LANGUAGE TypeFamilies, DataKinds, TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
import Data.Monoid
import Data.HList.FakePrelude
import Data.HList.Record
import Data.HList.Labelable
instance (Monoid v1, Monoid v2) =>
Monoid (Record '[Tagged (t1::Symbol) v1, Tagged (t2::Symbol) v2]) where
mempty = (Label :: Label (t1::Symbol)) .=. mempty
.*. (Label :: Label (t2::Symbol)) .=. mempty .*. emptyRecord
mappend a b = (Label :: Label (t1::Symbol))
.=. (a .!. (Label :: Label (t1::Symbol)))
`mappend` (b .!. (Label :: Label (t1::Symbol)))
.*.(Label :: Label (t2::Symbol))
.=. (a .!. (Label :: Label (t2::Symbol)))
`mappend` (b .!. (Label :: Label (t2::Symbol)))
.*. emptyRecord
错误信息:
Database/Harehouse/Utils.hs:185:59:
Overlapping instances for HEq Symbol l0 t1 b
arising from a use of `.!.'
Matching instances:
instance [overlap ok] 'False ~ b => HEq k x y b
-- Defined in `Data.HList.TypeEqO'
instance [overlap ok] HEq k x x 'True
-- Defined in `Data.HList.TypeEqO'
(The choice depends on the instantiation of `t1, b, l0'
To pick the first instance above, use -XIncoherentInstances
when compiling the other instance declarations)
In the first argument of `mappend', namely
`(a .!. (Label :: Label (t1 :: Symbol)))'
In the second argument of `(.=.)', namely
`(a .!. (Label :: Label (t1 :: Symbol)))
`mappend` (b .!. (Label :: Label (t1 :: Symbol)))'
In the first argument of `(.*.)', namely
`(Label :: Label (t1 :: Symbol))
.=.
(a .!. (Label :: Label (t1 :: Symbol)))
`mappend` (b .!. (Label :: Label (t1 :: Symbol)))'
这意味着什么 ?我怎么解决这个问题 ?(我正在使用 GHC 7.6.3)