For example, I have a type class :
class MyClass a b c where
fun01 :: a -> b
fun02 :: a -> c
fun03 :: a -> b -> c -> ()
fun04 :: a -> WhatEver
I'd like to provide a default implementation for my, let's call it BaseDataType
which defines implementations of fun03
in terms of it self and fun01
and fun02
. Then I'd have something like this :
class MyClass BaseDataType b c where
fun03 = fun01 <$> fun02 ...
fun04 = fun02 ...
And than to finalize my class instance and avoid all the boilerplate code for fun03
and fun04
I'd just provide fun01
and fun02
like this :
instance MyClass BaseDataType Int Char where
fun01 = 1
fun02 = 'C'
Is there possibly some language extension that allows this kind of behaviour? I couldn't find anything on this topic.
MyClass
instances, not just for theMyClass BaseDataType
specialisation. (In other cases, the default implementation will just give a obscure-ish type error to indicate that a custom instance must be replaced.) – Passenger