X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.runtime%2Fscl%2FPrelude.scl;h=eb8026de910e15f2b8900c2e0fce6a6d6a0d0d6e;hp=c04cc8625aa0be2bceb1ab372f8f9fe5a7eca5c4;hb=e9757cdfe5996d87738cabad84bff0343f56e4e3;hpb=46ea0d713406fbd0a0d8a8e5f41b7fb8ea7001c3 diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index c04cc8625..eb8026de9 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -1484,6 +1484,14 @@ fst (x,y) = x 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 @@ -2206,6 +2214,12 @@ importJava "java.lang.Throwable" where @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 @@ -2217,6 +2231,20 @@ instance Show Throwable where 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 -> ()