Просмотр исходного кода

make the key customizable/restrictable.

Lucas Stadler лет назад: 11
Родитель
Сommit
0624c6bf14
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      hs/DataStructures.hs

+ 4 - 3
hs/DataStructures.hs

@ -1,3 +1,4 @@
1
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
1 2
{-|
2 3
    Module: DataStructures
3 4
    Description: Having fun with (functional) data structures
@ -268,7 +269,7 @@ instance Queue FingerTree where
268 269
        case last ft of
269 270
            Just x -> Just (x, rest ft) -- broken, we'd need a different version of rest
270 271
271
class Associative as where
272
class Associative as k where
272 273
    get :: (Ord k) => k -> as k v -> Maybe v
273 274
274 275
    insert :: (Ord k) => k -> v -> as k v -> as k v
@ -283,7 +284,7 @@ class Associative as where
283 284
-- examples
284 285
rb = fromPairs $ zip [1..10] [2..11] :: RBTree Int Int
285 286
286
fromPairs :: (Associative as, Ord k) => [(k, v)] -> as k v
287
fromPairs :: (Associative as k, Ord k) => [(k, v)] -> as k v
287 288
fromPairs [] = empty
288 289
fromPairs ((k, v):kvs) = insert k v $ fromPairs kvs
289 290
@ -309,7 +310,7 @@ balance Black a xk xv (RBNode Red b yk yv (RBNode Red c zk zv d)) =
309 310
    RBNode Black (RBNode Red a xk xv b) yk yv (RBNode Black c zk zv d)
310 311
balance c l k v r = RBNode c l k v r
311 312
312
instance Associative RBTree where
313
instance Associative RBTree k where
313 314
    get ik (RBLeaf _) = Nothing
314 315
    get ik (RBNode c l k v r) | k == ik = Just v
315 316
    get ik (RBNode c l k v r) =