]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Collection.scl
Merge "List the unsatisfied dependencies in CanvasContext"
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Collection.scl
1 /*
2 import "Prelude"
3 import "IterN"
4
5 type family El a
6
7 class Collection a where
8     size :: a -> Integer
9     isEmpty :: a -> Boolean
10     iter :: (El a -> <e> dummy) -> a -> <e> ()
11     any :: (El a -> <e> Boolean) -> a -> <e> Boolean
12     all :: (El a -> <e> Boolean) -> a -> <e> Boolean
13     filter :: (El a -> <e> Boolean) -> a -> <e> a
14     partition :: (El a -> <e> Boolean) -> a -> <e> (a,a)
15     groupBy :: (El a -> b) -> [(b, a)]
16     uniqueElement :: a -> El a // may fail
17     fromList :: [El a] -> a
18     toList :: a -> [El a]
19
20 @inline
21 for :: a -> (El a -> <e> dummy) -> <e> ()
22 for c f = iter f c
23
24 class (Collection a) => Sequence a where
25     // required
26     (!) :: a -> Integer -> El a
27     sub :: a -> Integer -> Integer -> a
28     
29     // optional
30     length :: a -> Integer
31     take :: Integer -> a -> a
32     drop :: Integer -> a -> a
33     
34     mapFirst  :: (El a -> <e> Maybe b) -> a -> <e> Maybe b
35     foldl :: (b -> El a -> <e> b) -> b -> a -> <e> b
36     foldr :: (El a -> b -> <e> b) -> b -> a -> <e> b
37     foldl1 :: (El a -> El a -> <e> El a) -> a -> <e> a
38     foldr1 :: (El a -> El a -> <e> El a) -> a -> <e> a
39     
40     elem :: El a -> a -> Boolean
41     elemIndex :: El a -> a -> Maybe Integer
42     elemIndices :: El a -> a -> [Integer]
43     find :: (El a -> <e> Boolean) -> a -> <e> Maybe (El a)
44     findIndex :: (El a -> <e> Boolean) -> a -> <e> Maybe Integer
45     findIndices :: (El a -> <e> Boolean) -> a -> <e> [Integer]
46     mapS :: (El a -> <e> El a) -> a -> <e> a
47     singleton :: El a -> a
48     
49     head :: a -> El a
50     tail :: a -> a
51     safeHead :: a -> Maybe (El a)
52     safeTail :: a -> Maybe a
53     
54     reverse :: a -> a
55     
56     sort :: Ord (El a) => a -> a
57     sortBy :: Ord b => (El a -> b) -> a -> a
58     
59     mapN :: (Integer -> <e> El a) -> Integer -> <e> a
60     
61     mapG :: Sequence b => (El b -> <e> El a) -> b -> <e> a
62     
63     length l = size l
64     
65     isEmpty c = length c == 0
66     take n c = sub c 0 n
67     drop n c = sub c n (length c)
68     iter f c = iterN (f . (c !)) (length c)
69     any f c = anyN (f . (c !)) (length c)
70     all f c = allN (f . (c !)) (length c)
71     mapFirst f c = mapFirstN (f . (c !)) (length c)
72
73 class (forall a. Sequence f a, Functor f) => GenericSequence f where
74     concatMap :: (a -> <e> f b)     -> f a -> <e> f b
75     map       :: (a -> <e> b)       -> f a -> <e> f b
76     mapMaybe  :: (a -> <e> Maybe b) -> f a -> <e> f b
77
78 class Set a where
79     union :: a -> a -> a
80     intersection :: a -> a -> a
81
82 type family Key a
83 type family Value a
84     
85 class Map a where
86 */