Export-Package: org.simantics.scl.runtime,
org.simantics.scl.runtime.chr,
org.simantics.scl.runtime.collection,
+ org.simantics.scl.runtime.either,
org.simantics.scl.runtime.exceptions,
org.simantics.scl.runtime.function,
org.simantics.scl.runtime.io,
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)
--- /dev/null
+package org.simantics.scl.runtime.either;
+
+public interface Either {
+}
--- /dev/null
+package org.simantics.scl.runtime.either;
+
+public class Left implements Either {
+ public final Object value;
+
+ public Left(Object value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Left " + value;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj)
+ return true;
+ if(obj == null || obj.getClass() != getClass())
+ return false;
+ Right other = (Right)obj;
+ return value == null ? other.value == null : value.equals(other.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * (value == null ? 0 : value.hashCode()) + 13532;
+ }
+}
--- /dev/null
+package org.simantics.scl.runtime.either;
+
+public class Right implements Either {
+ public final Object value;
+
+ public Right(Object value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Right " + value;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj)
+ return true;
+ if(obj == null || obj.getClass() != getClass())
+ return false;
+ Right other = (Right)obj;
+ return value == null ? other.value == null : value.equals(other.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * (value == null ? 0 : value.hashCode()) + 13533;
+ }
+}