简体   繁体   English

haskell:谁能解释以下代数数据类型

[英]haskell : could anyone explain the below algebric data type

could anyone explain the below algebric data type 谁能解释下面的代数数据类型

data LOS = Cons Student LOS | Empty deriving (Show) 

and

type Name = String



data Student = Student           
  { firstName :: Name
  , lastName :: Name
  } deriving (Eq, Show)

I find it confusing the construction of the LOS data type 我发现它混淆了LOS数据类型的构造

LOS is defining a list of students. LOS正在定义学生名单。 You either have an empty list ( Empty ) or Cons , which holds both a value or the rest of the list. 您可能有一个空列表( Empty )或Cons ,它既包含值也包含列表的其余部分。

You can have a list with an element ( Cons s1 Empty ), a list with two elements ( Cons s1 (Cons s2 Empty) ) and so on. 您可以拥有一个包含一个元素的列表( Cons s1 Empty ),一个包含两个元素的列表( Cons s1 (Cons s2 Empty) ),依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM