Haskell:包含其他数据类型的数据类型 [英] Haskell: Data type containing other Data Types
本文介绍了Haskell:包含其他数据类型的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有两个数据结构
data Tri = Tri {a :: Int, b :: Int , c :: Int} deriving Show
data Quad = Quad {w :: Int, x :: Int, y :: Int, z :: Int} deriving Show
如何创建由这两个组成的另一个数据结构?即:
how do I create another data structure made up of those two? ie something alon the lines of:
data Shape = Tri | Quad derivng Show
推荐答案
您必须为数据构造函数命名:
You have to give names to data constructors:
data Shape = ShapeTri { shapeTri :: Tri }
| ShapeQuad { shapeQuad :: Quad }
deriving Show
这篇关于Haskell:包含其他数据类型的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文