【发布时间】:2015-09-13 16:15:55
【问题描述】:
一些代数数据类型..
data Cell0=Cell0 {c0str::Text,c0uid::Uid}
deriving (Data,Typeable,Show)
data Cell1=Cell1 {c1start::Uid,c1end::Uid,c1str::Text,c1uid::Int}
deriving (Data,Typeable,Show)
data Cell2=Cell2 {c2start::Uid,c2end::Uid,c2str::Text,c2uid::Int}
deriving (Data,Typeable,Show)
data Acell=Cell0|Cell1
但最后一行导致编译错误“Cell0 的多个声明”
我也试过这样的:
data A=Aasdfdsf {sdf::Text}
deriving (Data,Typeable,Show)
data B=Bsdfsd
data AB=A|B
它编译!好奇怪。。
【问题讨论】:
-
data Cell0 = Cell0 ...定义了一个Cell0构造函数,然后data Acell = Cell0 | Cell1再次这样做。也许将其更改为data Acell = ACell0 Cell0 | ACell1 Cell1? -
可行但太多余了..
-
一种选择是使用
Either。 -
您确定需要单独的
Cell0、Cell1和Cell2类型吗?也许您应该只使用一个带有三个构造函数的Cell类型。
标签: haskell types algebraic-data-types