[Haskell-cafe] [extension]syntactic sugar for maps

Eli Frey eli.lee.frey at gmail.com
Wed Mar 27 21:16:09 CET 2013


> Sorry, I forgot to explain (probably because I'm too used to it). I am
referring to a syntax for easy creation of maps. Something equivalent to
lists:
>
> to build a list: [ 1, 2, 3]
> to build a map; { 1, "one", 2, "two", 3, "three"}
>
> Without it I am always forced to use fromList.

This looks like something to use records for, or in any case something
where association list performance is not an issue.

If you just want to store some configuration-like structure and pass it
around, a record is great for this.  You might find where in other
languages you would simply leave a key "null", in Haskell you can just fill
it with a Nothing.

Maps (hash or binary-tree) really pay off when they are filled dynamically
with massive numbers of associations.  I find when I am ending up in this
scenario, I am generating my map programatically, not writing it as a
literal.

Sometimes people even write maps simply as functions and not even as a
data-structure.

> myMap char = case char of
>     'a' -> 1
>     'b' -> 2
>     'c' -> 3

Perhaps you could describe a situation you are in where you are wanting
this, and we could see if there is something you can do already that is
satisfying and solves your problem.



On Wed, Mar 27, 2013 at 12:59 PM, Eli Frey <eli.lee.frey at gmail.com> wrote:

> > http://hackage.haskell.org/trac/ghc/wiki/OverloadedLists comes to mind.
>
> This assumes you can turn ANY list into a thing.  Maps only make sense to
> be constructed from association list.  If I've got a [Char], how do I make
> a map form it?
>
>
> On Wed, Mar 27, 2013 at 12:56 PM, Nicolas Trangez <nicolas at incubaid.com>wrote:
>
>> On Wed, 2013-03-27 at 21:30 +0200, Răzvan Rotaru wrote:
>> > I am terribly missing some syntactic sugar for maps (associative data
>> > structures) in Haskell. I find myself using them more than any other
>> > data
>> > structure, and I think there is no big deal in adding some sugar for
>> > this
>> > to the language. I could not find out whether such an extension is
>> > beeing
>> > discussed. If not, I would like to propose and extension. Any help and
>> > suggestions are very welcome here. Thanks.
>>
>> http://hackage.haskell.org/trac/ghc/wiki/OverloadedLists comes to mind.
>>
>> Nicolas
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130327/2176f27e/attachment.htm>


More information about the Haskell-Cafe mailing list