Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of single colon in Haskell :t

Tags:

haskell

As far as I've been able to gather, the single colon in Haskell is used in list comprehension. Why then does it show up in the :t command? Also in the :quit command? There isn't any list comprehension being done, is there?

like image 802
Bob Avatar asked Mar 14 '23 15:03

Bob


1 Answers

The :t (short for :type) syntax is special to GHCi, and is not part of the Haskell language syntax. This is similar to how the SQLite interpreter accepts .tables as a command, even though this isn't valid a SQL statement. If you type :?, you can see a complete list of all the commands GHCi understands.

As for using the colon in actual Haskell code:

  • A colon by itself is a list constructor. This is a reserved name, and can never be redefined.
  • You should know that function names always start lowercase, while constructor names always start uppercase. Well, in a similar way, an infix constructor must start with a colon, whereas a normal infix operator must not start with a colon (but may contain colons elsewhere).

So, for example, "?:?" is a legal operator name, and :?? is a legal constructor operator name.

x ?:? y = ...whatever...

data Foobar = Int :?? Bool
like image 71
MathematicalOrchid Avatar answered Mar 19 '23 15:03

MathematicalOrchid