例如,我有一个类型类:
class MyClass a b c where
fun01 :: a -> b
fun02 :: a -> c
fun03 :: a -> b -> c -> ()
fun04 :: a -> WhatEver
我想为我的提供一个默认实现,让我们称之为它BaseDataType
,它定义fun03
了 self 和fun01
and的实现fun02
。然后我会有这样的事情:
class MyClass BaseDataType b c where
fun03 = fun01 <$> fun02 ...
fun04 = fun02 ...
而不是完成我的类实例并避免所有样板代码fun03
,fun04
我只是提供fun01
并fun02
喜欢这样:
instance MyClass BaseDataType Int Char where
fun01 = 1
fun02 = 'C'
是否有一些语言扩展允许这种行为?我找不到有关此主题的任何内容。