haskell - Is it possible to combine instances of a typeclass? -
i have feeling isn't possible, love input see if there's extensions or techniques i'm missing.
i have generic instance of typeclass defines default methods:
class testclass foo :: -> maybe text bar :: -> [int] instance testclass foo _ = nothing bar _ = [] data specifictype = somevalue | othervalue instance testclass specifictype foo somevalue = "success" foo othervalue = "other success"
i believe needs overlappinginstances
, problem instance of testclass
specifictype
doesn't implement bar
. i'd declare part of second instance, , use default implementation rest. there way achieve this?
in haskell 98, can put default implementations in class
definition:
class testclass foo :: -> maybe text foo _ = nothing -- default implementation bar :: -> [int] bar _ = [] -- default implementation
now instance
s not implement foo
or bar
yourself, take default implementation.
Comments
Post a Comment