简体   繁体   中英

Haskell: What is the meaning of :.?

A symbol combined (:.) of cons following by a dot.

Taken from here:

-- The custom list type
data List t =
  Nil
  | t :. List t
  deriving (Eq, Ord)

-- Right-associative
infixr 5 :.

Taken from here: https://github.com/tonymorris/fp-course

In short : the code constructs an alterative version of a list, and (:.) is one of the two data constructors .

Well it is a data constructor of the List t data type. For example the standard list [a] has two data constructors [] and (:) , here the code introduces a new data constructor (:.) , but it acts completely the same way as the "cons" of the standard list (:) .

So the code defines it as:

data List t = Nil | (:.) t (List t) deriving (Eq, Ord)

and like any data constructor, we can do pattern matching on it, construct new lists, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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