I want to write a class introducing a function which should append a b
resulting in a HList containing a and b (order doesn't matter)

So I came up with:

============= code ===================================================

class (HList c) => HListAppendArbitrary a b c | a b -> c where
  hAppendArbitrary :: a -> b -> c

-- instance HList + HList (1)
instance (HList a, HList b, HAppend a b c, HList c) 
          => HListAppendArbitrary a b c where
  hAppendArbitrary a b = hAppend a b

-- overlapping instance HList + value (2)
instance (HList a, HList c)
  => HListAppendArbitrary a b c where
  hAppendArbitrary a b = HCons b a

============= error ==================================================

hps-lib/HPS/Utils.hs|130| 0:
||     Duplicate instance declarations:
||       instance [overlap ok] (HList a, HList b, HAppend a b c, HList c) =>
||                          HListAppendArbitrary a b c
-- Defined at hps-lib/HPS/Utils.hs|130| 0
||       instance [overlap ok] (HList a, HList c) =>
||                          HListAppendArbitrary a b c
-- Defined at hps-lib/HPS/Utils.hs|134| 0

=============  =======================================================

instance (2) should be used if b does not belong to class HList.

Of course there is another opportunity by writing (HCons a x) instead of
to force the first type beeing a HList...

Which is the topic to read from the ghc/ haskell manual ?

Marc Weber
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to