]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Collection.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Collection.scl
diff --git a/bundles/org.simantics.scl.runtime/scl/Collection.scl b/bundles/org.simantics.scl.runtime/scl/Collection.scl
new file mode 100644 (file)
index 0000000..63df233
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+import "Prelude"
+import "IterN"
+
+type family El a
+
+class Collection a where
+    size :: a -> Integer
+    isEmpty :: a -> Boolean
+    iter :: (El a -> <e> dummy) -> a -> <e> ()
+    any :: (El a -> <e> Boolean) -> a -> <e> Boolean
+    all :: (El a -> <e> Boolean) -> a -> <e> Boolean
+    filter :: (El a -> <e> Boolean) -> a -> <e> a
+    partition :: (El a -> <e> Boolean) -> a -> <e> (a,a)
+    groupBy :: Hashable b => (El a -> b) -> [(b, a)]
+    uniqueElement :: a -> El a // may fail
+    fromList :: [El a] -> a
+    toList :: a -> [El a]
+
+@inline
+for :: a -> (El a -> <e> dummy) -> <e> ()
+for c f = iter f c
+
+class (Collection a) => Sequence a where
+    // required
+    (!) :: a -> Integer -> El a
+    sub :: a -> Integer -> Integer -> a
+    
+    // optional
+    length :: a -> Integer
+    take :: Integer -> a -> a
+    drop :: Integer -> a -> a
+    
+    mapFirst  :: (El a -> <e> Maybe b) -> a -> <e> Maybe b
+    foldl :: (b -> El a -> <e> b) -> b -> a -> <e> b
+    foldr :: (El a -> b -> <e> b) -> b -> a -> <e> b
+    foldl1 :: (El a -> El a -> <e> El a) -> a -> <e> a
+    foldr1 :: (El a -> El a -> <e> El a) -> a -> <e> a
+    
+    elem :: Eq (El a) => El a -> a -> Boolean
+    elemIndex :: Eq (El a) => El a -> a -> Maybe Integer
+    elemIndices :: Eq (El a) => El a -> a -> [Integer]
+    find :: (El a -> <e> Boolean) -> a -> <e> Maybe (El a)
+    findIndex :: (El a -> <e> Boolean) -> a -> <e> Maybe Integer
+    findIndices :: (El a -> <e> Boolean) -> a -> <e> [Integer]
+    mapS :: (El a -> <e> El a) -> a -> <e> a
+    singleton :: El a -> a
+    
+    head :: a -> El a
+    tail :: a -> a
+    safeHead :: a -> Maybe (El a)
+    safeTail :: a -> Maybe a
+    
+    reverse :: a -> a
+    
+    sort :: Ord (El a) => a -> a
+    sortBy :: Ord b => (El a -> b) -> a -> a
+    
+    mapN :: (Integer -> <e> El a) -> Integer -> <e> a
+    
+    mapG :: Sequence b => (El b -> <e> El a) -> b -> <e> a
+    
+    length l = size l
+    
+    isEmpty c = length c == 0
+    take n c = sub c 0 n
+    drop n c = sub c n (length c)
+    iter f c = iterN (f . (c !)) (length c)
+    any f c = anyN (f . (c !)) (length c)
+    all f c = allN (f . (c !)) (length c)
+    mapFirst f c = mapFirstN (f . (c !)) (length c)
+
+class (forall a. Sequence f a, Functor f) => GenericSequence f where
+    concatMap :: (a -> <e> f b)     -> f a -> <e> f b
+    map       :: (a -> <e> b)       -> f a -> <e> f b
+    mapMaybe  :: (a -> <e> Maybe b) -> f a -> <e> f b
+
+class Set a where
+    union :: a -> a -> a
+    intersection :: a -> a -> a
+
+type family Key a
+type family Value a
+    
+class Map a where
+*/
\ No newline at end of file