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 instances not implement foo or bar yourself, take default implementation.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -