Haskell: Data type containing other Data Types

前端 未结 2 1175
孤城傲影
孤城傲影 2021-01-24 23:56

if I have two data structures

data Tri = Tri {a :: Int, b :: Int , c :: Int} deriving Show
data Quad = Quad {w :: Int, x :: Int, y :: Int, z :: Int} deriving Sh         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-25 00:39

    You have to give names to data constructors:

    data Shape = ShapeTri  { shapeTri  :: Tri }
               | ShapeQuad { shapeQuad :: Quad } 
                     deriving Show
    

提交回复
热议问题