Syntax rules for haskell infix datatype constructors

I am trying to make the Haskell data type a bit like a python dictionary, a hash ruby ​​or a javascript object in which a string is associated with a value, for example:

data Entry t = Entry String t type Dictionary t = [Entry t] 

The above code is working fine. However, I would like a slightly more pleasant constructor, so I tried to define it as follows:

 data Entry t = String ~> t 

This failed. I tried this:

 data Entry t = [Char] ~> t 

Again, this failed. I know that ~ has special meaning in Haskell, and GHCi still allows the ~> operator, but I still tried another way:

 data Entry t = [Char] & t 

And another glitch due to a parsing error. I find this confusing because for some inexplicable reason this works:

 data Entry t = String :> t 

Does this mean that there are certain rules for what characters can occur in constructors like infix, or is this a great interpretation. I'm not new to Haskell, and I know that it would be more idiomatic to use the first constructor, but that cut me off and seems to be the important part of Haskell that I miss.

+8
constructor types haskell infix-notation
source share
1 answer

Any statement starting with a colon : is a type constructor or data constructor, except (->) . If you want a tilde, you can use :~> , but you will not be able to avoid using something that does not start with a colon. A source

+9
source share

All Articles