Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ':..' mean in Haskell?

I'm reading a following datatype:

data Ne
  = NVar Id
  | Ne :.. (Clos Term)
  | NSplit Ne (Bind (Bind (Clos Term)))
  | NCase Ne (Clos [(Label, Term)])
  | NForce Ne
  | NUnfold Ne (Bind (Clos Term))
  deriving (Show, Eq)

What is :.. in the second member declaration?

like image 219
Alexander Gryzlov Avatar asked Apr 03 '12 15:04

Alexander Gryzlov


People also ask

What is -> in Haskell?

(->) is often called the "function arrow" or "function type constructor", and while it does have some special syntax, there's not that much special about it. It's essentially an infix type operator. Give it two types, and it gives you the type of functions between those types.

What does (:) do in Haskell?

It is a List constructor function. It is used for prepending any value in front of the list.

What does == mean in Haskell?

The == is an operator for comparing if two things are equal. It is quite normal haskell function with type "Eq a => a -> a -> Bool". The type tells that it works on every type of a value that implements Eq typeclass, so it is kind of overloaded.

What does left arrow mean in Haskell?

The left arrow gets used in do notation as something similar to variable binding, in list comprehensions for the same (I'm assuming they are the same, as list comprehensions look like condensed do blocks), and in pattern guards, which have the form (p <- e). All of those constructs bind a new variable.


2 Answers

The name of a constructor can either be alpha-numeric starting with a capital letter or symbolic starting with a colon. In the latter case the operator will be used infix just like infix functions.

So :.. is an infix constructor for the Ne type, which takes an argument of type Ne (left operand) and one of type Clos Term (right operand).

like image 189
sepp2k Avatar answered Oct 05 '22 15:10

sepp2k


:.. is one of the constructors for the algebraic datatype Ne. A constructor name consisting of punctuation and starting with : becomes an infix operator. Try this:

module Main where

data List a = Nil
            | a :.. (List a)
            deriving Show

main = print (1 :.. (2 :.. Nil))
like image 25
Fred Foo Avatar answered Oct 05 '22 16:10

Fred Foo