Issue
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?
Solution
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.
Answered By - ninjagecko Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.