I learn Haskell. From Haskell 2010 documentation:
- An operator symbol starting with a colon is a constructor.
- An operator symbol starting with any other character is an ordinary identifier.
I don't understand first phrase. I know exist data constructors and class type constructors. What constructor this case? Maybe I need a code sample.
In Haskell, the colon operator is used to create lists (we'll talk more about this soon). This right-hand side says that the value of makeList is the element 1 stuck on to the beginning of the value of makeList .
Identifiers contain characters from any of: alpha, digit, underscore, and dollar sign. You can't use spaces or tabs or symbols like #, @, !, and so forth in an identifier.
An identifier starts with a letter or underscore and consists of: Letters. Numbers. _ (underscore) ' (single quote, sometimes pronounced as “prime”)
You can define stuff like
data Symbolic n
= Constant n
| Variable String
| Symbolic n :+ Symbolic n
| Symbolic n :* Symbolic n
deriving (Show)
GHCi> let v = Variable; c = Constant
GHCi> c 2 :* v"a" :+ c 3
(Constant 2 :* Variable "a") :+ Constant 3
That's what the first phrase refers to.
I know exist data constructors and class type constructors. What constructor this case?
In standard Haskell only data constructors can be symbolic and type names must be alphanumeric. If you enable the GHC extension TypeOperators, type names can be symbolic as well, allowing you to define type constructors that start with :
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With