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

#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

#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 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Description changed by tibbe: Old description:
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.
New description: 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. Both the containers and unordered-containers packages would presumably provide instances. It's possible that mutable data structures, such as those provided by the hashtables package, could provide instances as well. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8967#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Description changed by tibbe: Old description:
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.
Both the containers and unordered-containers packages would presumably provide instances. It's possible that mutable data structures, such as those provided by the hashtables package, could provide instances as well.
New description: 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. Both the containers and unordered-containers packages would presumably provide instances. It's possible that mutable data structures, such as those provided by the hashtables package, could provide instances as well. **Open question**: will this clash badly with the record syntax? It seems to work in other languages which use `{` and `}` to define other entities. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8967#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8967: Add syntax for creating finite maps and sets -------------------------------------+------------------------------------- Reporter: tibbe | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.6.3 Component: Compiler | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #436 None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * related: => #436 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8967#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC