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.
constructor types haskell infix-notation
Ajfarmar
source share