[GHC] #8967: Add syntax for creating finite maps and sets

GHC ghc-devs at haskell.org
Mon Apr 7 15:28:12 UTC 2014


#8967: Add syntax for creating finite maps and sets
------------------------------------+-------------------------------------
       Reporter:  tibbe             |             Owner:
           Type:  feature request   |            Status:  new
       Priority:  normal            |         Milestone:
      Component:  Compiler          |           Version:  7.6.3
       Keywords:                    |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple  |   Type of failure:  None/Unknown
     Difficulty:  Unknown           |         Test Case:
     Blocked By:                    |          Blocking:
Related Tickets:                    |
------------------------------------+-------------------------------------
 Many languages have syntax for creating maps. Commonly used syntax is
 either

 {{{
 {key1: value1, key2: value2, ...}
 }}}

 or

 {{{
 {key1 => value1, key2 => value2, ...}
 }}}

 Since few Haskellers (with the notable exception of SPJ) use the curly
 bracket Haskell syntax for layout, I thought we could co-opt it and
 instead use it for map (and set literals.) The feature would of course be
 protected by a language pragma as to not break old code.

 Strawman proposal:

 `{key1: value1, key2: value2, ...}` desugars to `fromList [(key1, value1),
 (key2, value2), ...]`, using a new type class:

 {{{#!haskell
 class IsMap m where
   type Key m
   type Value m

   fromList :: [(Key m, Value m)] -> m
 }}}

 `{:}` is the literal for empty maps.

 Analogously, `{value1, value2, ...}` desugars to `fromList [value1,
 value2, ...]`, using a new type class:

 {{{#!haskell
 class IsSet m where
   type Item m

   fromList :: [Item m] -> m
 }}}

 `{}` is the literal for empty sets.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8967>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list