在类

时间:2017-11-01 06:10:56

标签: haskell typeclass type-families

让我们说我有这样的课程:

class C a where
  type T a

我想在类中添加同义词,如下所示:

class C a where
  type MT a
  type M = MT a

所以我可以引用M而不是MT a

我知道这听起来不是什么大不了的事,但如果我有这样的话就说:

class Monad (MT a) => C a where
  type MT a
  type ItemT a
  new :: (MT a) a
  anotherSillyFunction :: [ItemT a] -> (MT a) a
  -- etc

但是这种方法使函数定义更清晰:

class Monad (MT a) => C a where
  type MT a
  type ItemT a
  type M = MT a
  type Item = ItemT a
  new :: M a
  anotherSillyFunction :: [Item] -> M a
  -- etc

除了上面没有编译。无论如何要实现上述目标?

0 个答案:

没有答案