chrometic
chrometic

Reputation: 81

Learning the meaning of " :?: " operator in Haskell

I'm learning Haskell and I just saw this weird data structure in my book, it looks like this: data ListaOrd a = a :?: (ListaOrd a) | Nulo deriving Show. It was said that this supposed to represent an ordered list, but I don't think I really understood it. My question is, what is the meaning of " :?: " symbol in that code?

Upvotes: 2

Views: 335

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477533

My question is, what is the meaning of :?:

You are here defining a data constructor that is the :?: operator. Indeed, in GHCi you can query the type of the (:?:) function:

:t (:?:)
(:?:) :: a -> ListaOrd a -> ListaOrd 

It is thus exactly the same as if you would have used another name, like:

data ListaOrd a = Conso a (ListaOrd a) | Nulo deriving Show

But here we define a data constructor with name (:?:) that can be used with operator syntax as well. In fact you likely already used such data constructor(s). For example (:) is a data constructor for a list.

Upvotes: 7

Related Questions