X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.runtime%2Fscl%2FPrelude.scl;h=83d84ccf2da505c6590b404c23c93a484fb98ad2;hb=7db6413ad1d17e7ce4fea3a64f5de435039ad9a6;hp=eb1e8cd6ff35bed0186d22d68e7b115626246d04;hpb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b;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 eb1e8cd6f..83d84ccf2 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -1065,6 +1065,15 @@ mapEither f list = runProc do Right v -> addArrayList r v) (Java.unsafeCoerce l, Java.unsafeCoerce r) +"`replicate n v` returns a list of length `n` such that each element is a copy of `v`." +@inline +replicate :: Integer -> a -> [a] +replicate n v = build (\empty cons -> + let aux 0 l = l + aux i l = aux (i-1) (cons l v) + in aux n empty + ) + /// FunctorM /// class (Functor f) => FunctorM f where @@ -1273,7 +1282,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) @@ -2116,7 +2132,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