Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the : infix operator do in Haskell?

Tags:

haskell

I'm reading A Gentle Introduction to Haskell (which is not so gentle) and it repeatedly uses the : operator without directly explaining what it does.

So, what exactly does it do?

like image 805
moo Avatar asked Nov 08 '09 14:11

moo


People also ask

What is operator in infix?

Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—"infixed operators"—such as the plus sign in 2 + 2.

What is a infix function?

User defined infix function notation –It must be member function or extension function. It must accepts a single parameter. The parameter must not accept variable number of arguments and must have no default value. It must be marked with infix keyword.

What does the operator do in Haskell?

Haskell provides special syntax to support infix notation. An operator is a function that can be applied using infix syntax (Section 3.4), or partially applied using a section (Section 3.5).

What is infix operator in C?

Infix notation: X + Y. Operators are written in-between their operands. This is the usual way we write expressions. An expression such as A * ( B + C ) / D is usually taken to mean something like: "First add B and C together, then multiply the result by A, then divide by D to give the final answer."


1 Answers

: is the “prepend” operator:

x : xs 

Returns a list which has x as first element, followed by all elements in xs. In other functional languages, this is usually called cons, because it “cons”tructs a list recursively by repeated application from an empty list:

1 : 2 : 3 : 4 : [] 

is the list [1, 2, 3, 4].

like image 95
Konrad Rudolph Avatar answered Sep 21 '22 19:09

Konrad Rudolph