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
infixl 5 (\\), (<<), (<+)
infix 4 (!=), (<), (<=), (>=), (>)
infixr 3 (&&), (&<&)
-infixr 2 (||), orElse, morelse
+infixr 2 (||), orElse, orElseM, morelse
infixr 1 (>>=), (>>), (:=), (>=>)
infixr 1 ($)
infixl 1 catch
"""
class (Monad m) => MonadZero m where
mzero :: m a
+ mfilter :: (a -> Boolean) -> m a -> m a
+
+ mfilter p m = m >>= (\x -> if p x then return x else mzero)
"Injects a boolean test to a type beloning to `MonadZero`."
guard :: MonadZero m => Boolean -> m ()
/// MonadE ///
class (FunctorE m, Monad m) => MonadE m where
+ "An effectful version of the bind operator `(>>=)`"
bindE :: m a -> (a -> <e> m b) -> <e> m b
instance MonadE Maybe where
instance MonadE [] where
bindE l f = concatMap f l
+
+@inline
+"An effectful version of the Kleisli composition operator `(>=>)`"
+compE :: MonadE m => (a -> <e> m b) -> (b -> <f> m c) -> a -> <e,f> m c
+compE f g x = (f x) `bindE` g
+
+/// MZeroE ///
+
+class (MonadE m, MonadZero m) => MonadZeroE m where
+ filter :: (a -> <e> Boolean) -> m a -> <e> m a
+
+ filter p m = m `bindE` (\x -> if p x then return x else mzero)
+instance MonadZeroE [] where
+ filter = filterList
+
+instance MonadZeroE Maybe where
+ filter p (Just x) | not (p x) = Nothing
+ filter _ m = m
+
/// Category ///
"Identity function."
"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 ///
"""
snd (x,y) = y
@inline
-mapFst :: (a -> b) -> (a,c) -> (b,c)
+mapFst :: (a -> <e> b) -> (a,c) -> <e> (b,c)
mapFst f (x,y) = (f x, y)
@inline
-mapSnd :: (a -> b) -> (c,a) -> (c,b)
+mapSnd :: (a -> <e> b) -> (c,a) -> <e> (c,b)
mapSnd f (x,y) = (x, f y)
instance (Ord a, Ord b) => Ord (a, b) where
`filter pred lst` returns those elements of `lst` that the predicate `pred` accepts. For example
filter (> 3) [1, 2, 3, 4, 5, 6] = [4, 5, 6]
-"""
+"""
@inline
-filter :: (a -> <e> Boolean) -> [a] -> <e> [a]
-filter p l = build (\empty cons -> foldl (\cur x -> if p x then cons cur x else cur) empty l)
+filterList :: (a -> <e> Boolean) -> [a] -> <e> [a]
+filterList p l = build (\empty cons -> foldl (\cur x -> if p x then cons cur x else cur) empty l)
"""
Takes those elements of the input list that match `(Just x)` and adds the contents to the resulting list. For example,
"""
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]]
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