]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
New method to Prelude: indexSet
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Prelude.scl
index bb6452429b39141a10a45ae19dbf4ad0736d0745..32582affa867947fbac5167b94c4d8919c0bd91c 100644 (file)
@@ -38,11 +38,16 @@ class Serializable a
 binding :: Serializable a => Binding a
 ***********************************************************/
 
+type BooleanArray = Vector Boolean
+type ByteArray = Vector Byte
+type CharacterArray = Vector Character
+type ShortArray = Vector Short
+type IntegerArray = Vector Integer
+type LongArray = Vector Long
+type FloatArray = Vector Float
+type DoubleArray = Vector Double
+
 importJava "java.util.Arrays" where
-    @private
-    @JavaName toString
-    showDoubleArray :: DoubleArray -> String
-    
     "Converts an array to a list."
     @JavaName asList    
     arrayToList :: Array a -> [a]
@@ -52,9 +57,6 @@ importJava "java.util.List" where
     @JavaName toArray
     listToArray :: [a] -> Array a
 
-instance Show DoubleArray where
-    show = showDoubleArray
-
 importJava "org.simantics.scl.runtime.Coercion" where
     "Converts a list of doubles to a double array."
     toDoubleArray :: [Double] -> DoubleArray
@@ -1303,6 +1305,11 @@ orElse :: Maybe a -> (<e> a) -> <e> a
 orElse (Just x) _   = x
 orElse Nothing  def = def
 
+@inline
+orElseM :: Maybe a -> (<e> Maybe a) -> <e> Maybe a
+orElseM mx@(Just x) _   = mx
+orElseM Nothing     def = def
+
 /// Either ///
 
 """
@@ -1958,6 +1965,11 @@ importJava "org.simantics.scl.runtime.Lists" where
     """
     index :: [(a,b)] -> a -> Maybe b
     
+    """
+    Given a list of elements, the function produces its characteristic function.
+    """
+    indexSet :: [a] -> a -> Boolean
+    
     """
     Given a list of values and a function computing a key for each value, the function produces a function that finds a value
     effeciently for the given key.
@@ -2281,16 +2293,6 @@ instance Show TypeRep where
         isSpecialType (TApply a _) = isSpecialType a
 */
 
-// ByteArray
-
-importJava "java.util.Arrays" where
-    @private
-    @JavaName toString
-    byteArrayToString :: ByteArray -> String
-
-instance Show ByteArray where
-    show = byteArrayToString
-
 // Type
 
 @private