Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does :: (double colon) stand for?

I see and use the :: symbols everywhere but still don't know what the :: symbol means when programming in Haskell, e.g.

run :: Int -> Int -> Int --  ?? 

What does :: (double colon) stand for in Haskell?

like image 904
maclunian Avatar asked May 08 '11 10:05

maclunian


People also ask

What are :: in Java?

The double colon (::) operator, also known as method reference operator in Java, is used to call a method by referring to it with the help of its class directly. They behave exactly as the lambda expressions.

What is double colon called?

Scope Resolution Operator (::) ¶ The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.

What does 2 colons mean in CSS?

The double colon replaced the single-colon notation for pseudo-elements in CSS3. This was an attempt from W3C to distinguish between pseudo-classes and pseudo-elements. The single-colon syntax was used for both pseudo-classes and pseudo-elements in CSS2 and CSS1.

What does colon symbol mean?

The colon ( : ) is a mark of punctuation used after a statement (such as an independent clause) or that introduces a quotation, an explanation, an example, or a series.


2 Answers

You can google for haskell "double colon" or similar things; it's unfortunately a bit hard to google for syntax, but in this case you can name it.

In Haskell, your programs will often run fine without it (though you will want to use it to hone the specification of any functions you define, and it is good practice).

The idea is that you can insert a :: ... anywhere (even in the middle of an expression) to say "by the way Mr. Compiler, this expression should be of type ...". The compiler will then throw an error if it can be proved this may not be the case.

I think you can also use it to "cast" functions to the versions you want; e.g. if a function is "polymorphic" (has a general type signature) and you actually want, say an Integer, then you could do :: Integer on the resulting value perhaps; I'm a bit rusty though.

like image 125
ninjagecko Avatar answered Sep 23 '22 21:09

ninjagecko


You should read:

foo :: a  

as "the name foo refers to a value of type a". When you write:

run :: a -> b  

this means:

  1. You are declaring the name run.

  2. This name will refer to a value that have type a -> b,

The type a -> b is the type of a function which takes a value of type a and returns another value of type b.

You must really learn about types to understand Haskell. The type system is one of the most crucial feature of Haskell, and it's what makes the language so expressive.

like image 29
Rafael S. Calsaverini Avatar answered Sep 24 '22 21:09

Rafael S. Calsaverini