[go: up one dir, main page]

File: Map.hs

package info (click to toggle)
alex 2.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 560 kB
  • ctags: 70
  • sloc: haskell: 3,134; xml: 1,314; yacc: 235; makefile: 116; ansic: 4
file content (67 lines) | stat: -rw-r--r-- 1,468 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module Map (
   Map,
   member, lookup, findWithDefault,
   empty,
   insert, insertWith,
   delete,
   union, unionWith, unions,
   mapWithKey,
   elems,
   fromList, fromListWith,
   toAscList
) where

#if __GLASGOW_HASKELL__ >= 603
import Data.Map
import Prelude ()
#else
import Data.FiniteMap
import Prelude hiding ( lookup )

type Map k a = FiniteMap k a

member :: Ord k => k -> Map k a -> Bool
member = elemFM

lookup :: Ord k => k -> Map k a -> Maybe a
lookup = flip lookupFM

findWithDefault :: Ord k => a -> k -> Map k a -> a
findWithDefault a k m = lookupWithDefaultFM m a k

empty :: Map k a
empty = emptyFM

insert :: Ord k => k -> a -> Map k a -> Map k a
insert k a m = addToFM m k a

insertWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
insertWith c k a m = addToFM_C c m k a

delete :: Ord k => k -> Map k a -> Map k a
delete = flip delFromFM

union :: Ord k => Map k a -> Map k a -> Map k a
union = flip plusFM

unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
unionWith c l r = plusFM_C c r l

unions :: Ord k => [Map k a] -> Map k a
unions = foldl (flip plusFM) emptyFM

mapWithKey :: (k -> a -> b) -> Map k a -> Map k b
mapWithKey = mapFM

elems :: Map k a -> [a]
elems = eltsFM

fromList :: Ord k => [(k,a)] -> Map k a
fromList = listToFM

fromListWith :: Ord k => (a -> a -> a) -> [(k,a)] -> Map k a 
fromListWith c = addListToFM_C (flip c) emptyFM

toAscList :: Map k a -> [(k,a)]
toAscList = fmToList
#endif