X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.runtime%2Fscl%2FPrelude.scl;h=f0eca0eb26dc78141f4a4f204f9f46ce14948c2c;hb=074cf59788feedea1837d60b133142dd73c43058;hp=2c5966dc40f99a2b38a594b675dd8dc9588bf1bb;hpb=7045f0f516c243563976207abcec13a68891ff1d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index 2c5966dc4..f0eca0eb2 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -1273,7 +1273,14 @@ The Either type represents values with two possibilities: a value of type `Eithe The `Either` type is sometimes used to represent a value which is either correct or an error; by convention, the `Left` constructor is used to hold an error value and the `Right` constructor is used to hold a correct value (mnemonic: "right" also means "correct"). """ -data Either a b = Left a | Right b +@JavaType "org.simantics.scl.runtime.either.Either" +data Either a b = + @JavaType "org.simantics.scl.runtime.either.Left" + @FieldNames [value] + Left a + | @JavaType "org.simantics.scl.runtime.either.Right" + @FieldNames [value] + Right b deriving instance (Ord a, Ord b) => Ord (Either a b) deriving instance (Show a, Show b) => Show (Either a b) @@ -1396,7 +1403,7 @@ instance Show String where instance Read String where read str = str -@deprecated +@deprecated "Instead of 'splitString text pattern', write 'split pattern text' (note change in the parameter order)." "`splitString text pattern` splits the string into a list of string where the parts are sepratated in the original list by the given pattern." splitString :: String -> String -> [String] splitString source pattern = arrayToList $ splitString_ source pattern @@ -1540,6 +1547,24 @@ joinWithSeparator :: Show a => String -> [a] -> String joinWithSeparator separator values = runProc ( StringBuilder.toString $ printWithSeparator StringBuilder.new separator values) + +intercalate :: String -> [String] -> String +intercalate separator strings = do + l = length strings + if l == 0 + then "" + else if l == 1 + then strings!0 + else runProc do + sb = StringBuilder.new + sb << strings!0 + loop i | i == l = () + | otherwise = do + sb << separator << strings!i + loop (i+1) + loop 1 + StringBuilder.toString sb + instance (Show a) => Show [a] where sb <+ l = do len = length l @@ -2098,7 +2123,7 @@ importJava "org.simantics.scl.runtime.procedure.Procedures" where "Executes the given expression and catches certain class of exceptions (specified by the catch handler that is given as a second parameter.)" @JavaName catch_ - catch :: VecComp ex => ( a) -> (ex -> a) -> a + catch :: VecComp ex => ( a) -> (ex -> a) -> a importJava "java.lang.Throwable" where data Throwable