typeclass - Haskell Recursive Type Classes -
i want create recursive instance type based on tuples. looking similar this:
class provider b getinstance :: -> b instance provider b => provider (x, a) b getinstance (x, a) = getinstance instance provider (b, x) b getinstance (b, _) = b tryfunc1 :: int tryfunc1 = let provider = ("test", (10, ())) :: (string, (int, ())) in getinstance provider tryfunc2 :: string tryfunc2 = let provider = ("test", (10, ())) :: (string, (int, ())) in getinstance provider unfortunatelly, haskell fails solve instance. reason?
the solution stop using deprecated overlappinginstances pragma , start using per instance overlapping , overlappable pragmas. change:
instance {-# overlappable #-} provider b => provider (x, a) b getinstance (x, a) = getinstance instance {-# overlapping #-} provider (b, x) b getinstance (b, _) = b i tryfunc1 10 , tryfunc2 "test".
technically need either overlappable or overlapping pragma, believe practice have both in case... also, suppose behaviour want, note gets first of whatever type looking (so getinstance (10, (20, ())) :: int gives me 10 , not 20)
good source of info ticket tracking feature's creation.
Comments
Post a Comment