List Literals

Download haskell eBook

Example

GHC's OverloadedLists extension allows you to construct list-like data structures with the list literal syntax.

This allows you to Data.Map like this:

> :set -XOverloadedLists
> import qualified Data.Map as M
> M.lookup "foo" [("foo", 1), ("bar", 2)]
Just 1

Instead of this (note the use of the extra M.fromList):

> import Data.Map as M
> M.lookup "foo" (M.fromList [("foo", 1), ("bar", 2)])
Just 1

Stats

Contributors: 1
2016-04-08
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook