【发布时间】:2021-08-24 00:54:11
【问题描述】:
有没有办法根据关联的类型同义词来定义类型同义词? (不确定我的术语是否正确。)
{-# LANGUAGE TypeFamilies #-}
class Reproductive a where
-- | A sequence of genetic information for an agent.
type Strand a
-- | Full set (both strands) of genetic information for an organism.
type Genome a = (Strand a, Strand a)
这是我收到的错误消息。
λ> :l stackOverflow.hs
[1 of 1] Compiling Main ( stackOverflow.hs, interpreted )
stackOverflow.hs:9:8: error:
‘Genome’ is not a (visible) associated type of class ‘Reproductive’
|
9 | type Genome a = (Strand a, Strand a)
| ^^^^^^
Failed, no modules loaded.
我可以在任何地方使用(Strand a, Strand a),但最好使用Genome a。
【问题讨论】:
标签: haskell type-families associated-types