typeclass - Haskell typeclasses with algebraic data types -
typeclass - Haskell typeclasses with algebraic data types -
i have algebraic info types a, b, , c each implements class:
class dog dog :: -> bool if create new algebraic info type:
data d = | b | c is there easy way have d implement dog without having redefine each instance a, b , c again?
thanks
before answering, should point out may falling mutual beginner's misconception adt's. remember, haskell has 2 separate namespaces type , term levels. if write:
data = foo info b = bar info c = baz info d = | b | c ...then there's no connection between type a , constructor a of type d. hence suspect (but not totally sure!) question meant inquire had next format type d, instead:
data d = a | b b | c c in case, short reply "no". might wish tack on deriving dog or such thing , done, facility not provided language. said, there packages generic programming help: check hackage packages list , search "deriv" , you'll 10 hits.
haskell typeclass algebraic-data-types
Comments
Post a Comment