Suggestion: Syntactic sugar for Maps!
Thomas Davie
tatd2 at kent.ac.uk
Thu Nov 27 16:14:43 EST 2008
On 27 Nov 2008, at 19:59, circ ular wrote:
> I suggest Haskell introduce some syntactic sugar for Maps.
>
> Python uses {"this": 2, "is": 1, "a": 1, "Map": 1}
>
> Clojure also use braces: {:k1 1 :k2 3} where whitespace is comma but
> commas are also allowed.
>
> I find the import Data.Map and then fromList [("hello",1), ("there",
> 2)] or the other form that I forgot(because it is to long!) to be to
> long...
>
> So why not {"hello": 1, "there": 2} ?
In a similar vein, I suggest not only to not do this, but also for
Haskell' to remove syntactic sugar for lists (but keep it for strings)!
I have two (three if you agree with my opinions on other parts of the
language) reasons for this:
1) It's a special case, that doesn't gain anything much. [a,b,c,d] is
actually only one character shorter and not really any clearer than
a:b:c:d:[].
2) Removing it would clear up the ',' character for use in infix
constructors.
3) (requiring you to agree with my opinions about tuples) it would
allow for clearing up the tuple type to be replaced with pairs
instead. (,) could become a *real* infix data constructor for pairs.
This would make us able to recreate "tuples" simply based on a right
associative (,) constructor. I realise there is a slight issue with
strictness, and (,) introducing more bottoms in a "tuple" than current
tuples have, but I'm sure a strict version of the (,) constructor
could be created with the same semantics as the current tuple.
Just my 2p
Thanks
Tom Davie
More information about the Haskell-prime
mailing list