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]
@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
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 ///
"""
"Creates a string from a vector of characters."
@JavaName "<init>"
string :: Vector Character -> String
+
+ getBytes :: String -> String -> ByteArray
+
+getBytesUTF8 :: String -> ByteArray
+getBytesUTF8 str = getBytes str "UTF-8"
instance Ord String where
compare = compareString
snd :: (a,b) -> b
snd (x,y) = y
+@inline
+mapFst :: (a -> b) -> (a,c) -> (b,c)
+mapFst f (x,y) = (f x, y)
+
+@inline
+mapSnd :: (a -> b) -> (c,a) -> (c,b)
+mapSnd f (x,y) = (x, f y)
+
instance (Ord a, Ord b) => Ord (a, b) where
compare (a0, b0) (a1, b1) = compare a0 a1 &<& compare b0 b1
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.
"""
- indexBy :: (a -> b) -> [a] -> b -> Maybe a
+ indexBy :: (a -> <e> b) -> [a] -> <e> (b -> Maybe a)
"Works like `index` but uses the given functions as hash codes and equality."
indexWith :: (a -> Integer) -> (a -> a -> Boolean) -> [(a,b)] -> a -> Maybe b
Just el2 -> el == el2
Nothing -> False
+"`elemIndex el lst` returns the index of the first element in the given list `lst` which is equal (by ==) to the query element, or Nothing if there is no such element."
+elemIndex :: a -> [a] -> Maybe Integer
+elemIndex el l = loop 0
+ where
+ len = length l
+ loop i | i < len = if el == l!i
+ then Just i
+ else loop (i+1)
+ | otherwise = Nothing
+
"""
Computes a list that contains only elements that belongs to both input lists.
"""
@private
@JavaName toString
showThrowable :: Throwable -> String
+ @private
+ @JavaName getMessage
+ getMessageThrowable :: Throwable -> String
+ @private
+ @JavaName getCause
+ getCauseThrowable :: Throwable -> Maybe Throwable
importJava "java.lang.Exception" where
data Exception
@private
instance Show Exception where
show = showException
+class Throwable e where
+ toThrowable :: e -> Throwable
+
+messageOfException :: Throwable e => e -> String
+messageOfException = getMessageThrowable . toThrowable
+
+causeOfException :: Throwable e => e -> Maybe Throwable
+causeOfException = getCauseThrowable . toThrowable
+
+instance Throwable Throwable where
+ toThrowable = id
+instance Throwable Exception where
+ toThrowable = Java.unsafeCoerce
+
"Prints the given value in the console."
@inline
print :: Show a => a -> <Proc> ()