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
"Returns the first element of a sequence"
@inline
+first :: [a] -> a
first l = l!0
"Returns the last element of a sequence"
@inline
+last :: [a] -> a
last l = l!(length l-1)
instance IndexedSequence [] where
fromMaybe default maybeValue = match maybeValue with
Just v -> v
_ -> default
-
-
+
+"`maybe def f v` returns `def` if `v=Nothing` and `f x` if `v=Just x`."
+@inline
+maybe :: b -> (a -> <e> b) -> Maybe a -> <e> b
+maybe n _ Nothing = n
+maybe _ f (Just x) = f x
+
"""
Provides a default value if the first parameter is Nothing.
The default value is evaluated only if needed. The function
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
"""
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.
unique :: [a] -> [a]
"Like `unique`, but uses the given function for finding the key values used for uniqueness testing."
- uniqueBy :: (a -> b) -> [a] -> [a]
+ uniqueBy :: (a -> <e> b) -> [a] -> <e> [a]
"Works like `unique` but uses the given function for equality tests."
uniqueWith :: (a -> a -> Boolean) -> [a] -> [a]
transpose [[1,2,3],[4,5,6]] == [[1,4],[2,5],[3,6]]
transpose [[1,2],[3,4,5]] == [[1,3],[2,4],[5]]
"""
+transpose :: [[a]] -> [[a]]
transpose xss = [[xs!i | xs <- xss, i < length xs]
| i <- [0..maximum [length xs | xs <- xss]-1]]
@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> ()
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