]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/src-isv/JavaVsSCL.mediawiki
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.runtime / src-isv / JavaVsSCL.mediawiki
index 029333907d73eb91f13e24053ee415b400a3c1a8..344d6f42dba41cf8a324c1bb297176a83cc59ab4 100644 (file)
-== Comparison of Java and SCL ==\r
-\r
-=== Language constructions and patterns ===\r
-\r
-<table border="1">\r
-<tr>\r
-<td><pre>0.5 + x * (2e-3 + x * 2)</pre></td>\r
-<td><pre>0.5 + x * (2e-3 + x * 2)</pre></td>\r
-</tr>\r
-\r
-<tr>\r
-<td><pre>x >= 0 && x <= 1</pre></td>\r
-<td><pre>x >= 0 && x <= 1</pre></td>\r
-</tr>\r
-\r
-<tr>\r
-<td><pre>Math.sin(a1) - Math.cos(a2)</pre></td>\r
-<td><pre>sin a1 - cos a2</pre></td></tr>\r
-\r
-<tr>\r
-<td><pre>cond ? value : alternative</pre></td>\r
-<td><pre><b>if</b> cond <b>then</b> value <b>else</b> alternative</pre></td>\r
-</tr>\r
-\r
-<tr>\r
-<td><pre>"I am " + age + " years old."</pre></td>\r
-<td>\r
-<pre>"I am " + show age + " years old."</pre>\r
-\r
-In future:\r
-\r
-<pre>"I am ${age} years old."</pre>\r
-</td>\r
-</tr>\r
-\r
-<tr><td><pre>\r
-<b>final</b> int sum = a + b;</pre>\r
-</td><td><pre>\r
-sum = a + b</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-public static String decorate(String x) {\r
-    return "(" + x + ")"; \r
-}</pre>\r
-</td><td><pre>\r
-decorate :: String -> String\r
-decorate x = "(" + x + ")"</pre>\r
-(the first line is optional)\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-{\r
-    statement1;\r
-    statement2;\r
-    statement3;\r
-}</pre>\r
-</td><td><pre>\r
-<b>do</b>\r
-    statement1\r
-    statement2\r
-    statement3\r
-</pre></td></tr>\r
-\r
-<tr><td><pre>\r
-<b>if</b>(cond1)\r
-    statement1;\r
-<b>else if</b>(cond2)\r
-    statement2;\r
-<b>else</b> \r
-    statement3;\r
-</pre></td><td><pre>\r
-<b>if</b> cond1\r
-<b>then</b> statement1\r
-<b>else if</b> cond2\r
-<b>then</b> statement2\r
-<b>else</b> statement3\r
-</pre></td></tr>\r
-\r
-<tr><td><pre>\r
-<b>for</b>(T x : l)\r
-    statement;\r
-</pre></td><td><pre>\r
-for l (\x -> \r
-    statement\r
-)\r
-</pre></td></tr>\r
-\r
-<tr><td><pre>\r
-<b>while</b>(cond) statement;\r
-</pre></td><td><pre>\r
-while (\() -> cond) (\() -> statement)\r
-</pre>\r
-In future with improvements to macros:\r
-<pre>\r
-while cond statement\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-int var;\r
-<b>switch</b>(value) {\r
-<b>case</b> Label1: \r
-    var = case1; \r
-    break;\r
-<b>case</b> Label2: \r
-    var = case2; \r
-    break;\r
-<b>default</b>:\r
-    var = case3;        \r
-}</pre>\r
-</td><td><pre>\r
-var = <b>match</b> value <b>with</b>\r
-    Label1 -> case1\r
-    Label2 -> case2\r
-    _      -> case3\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-<b>break</b>;\r
-<b>continue</b>;\r
-<b>return</b> x; // In the middle of the code\r
-</pre></td><td>No exact correspondence. However, every control sequence can be written in the following form:\r
-<pre>label1 initialState\r
-  where\r
-    label1 state = \r
-        ...\r
-        then label2 modifiedState1\r
-        else label3 modifiedState2\r
-    label2 state = \r
-        ...\r
-    label3 state = \r
-        ...\r
-        label1 modifiedState</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-int a, b;\r
-<b>if</b>(cond) {\r
-    a = aExp1;\r
-    b = bExp1;\r
-}\r
-<b>else</b> {\r
-    a = aExp2;\r
-    b = bExp2;\r
-}\r
-</pre>\r
-</td><td><pre>\r
-(a, b) = <b>if</b> cond\r
-          <b>then</b> (aExp1, bExp1)\r
-          <b>else</b> (aExp2, bExp2)         \r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-int a = 1;\r
-a = 2;\r
-a = 3;\r
-return a;\r
-</pre>\r
-</td><td><pre>\r
-a = ref 1\r
-a := 2\r
-a := 3\r
-getRef a\r
-</pre>\r
-\r
-The name of the function <code>getRef</code> will change in the future and is\r
-probably replaced by some special syntax. For example in ML <code>getRef a</code>\r
-would be written as <code>!a</code>.\r
-\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-public static String f(int x) {\r
-    if(x >= 0)\r
-        return Integer.toString(x);\r
-    else\r
-        return null;\r
-}</pre>\r
-</td><td><pre>\r
-f :: Integer -> Maybe String\r
-f x | x >= 0    = Just (show x)\r
-     | otherwise = Nothing\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-public static int invF(String s) {\r
-    if(s == null)\r
-        return -1;\r
-    else\r
-        return Integer.parseInt(s);\r
-}</pre>\r
-</td><td><pre>\r
-invF :: Maybe String -> Integer\r
-invF Nothing  = -1\r
-invF (Just s) = read s\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-Arrays.asList(new String[] {"x", "y", "z"})\r
-</pre>\r
-</td><td><pre>\r
-[ "x", "y", "z" ]\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-l.get(3)\r
-</pre>\r
-</td><td><pre>\r
-l!3\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-List<String> decorated = new ArrayList<String>();\r
-for(String s : undecorated)\r
-    decorated.add("(" + s + ")");\r
-</pre>\r
-</td><td><pre>\r
-decorated = [ "(" + s + ")" | s <- undecorated ]\r
-</pre>\r
-or\r
-<pre>\r
-decorated = map (\s -> "(" + s + ")") undecorated\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-List<String> nonempty = new ArrayList<String>();\r
-for(String s : l)\r
-    if(!s.isEmpty())\r
-        nonempty.add(l);\r
-</pre>\r
-</td><td><pre>\r
-decorated = [ s | s <- l, s != "" ]\r
-</pre>\r
-or\r
-<pre>\r
-decorated = filter (\s -> s != "") l\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-List<List<String>> listOfLists;\r
-List<String> flattened \r
-    = new ArrayList<String>();\r
-for(List<String> l : listOfLists)\r
-    for(String s : l)\r
-        flattened.add(s);\r
-</pre>\r
-</td><td><pre>\r
-flattened = [ s | l <- listOfLists, s <- l ]\r
-</pre>\r
-or\r
-<pre>\r
-flattened = sum listOfLists\r
-</pre>\r
-or\r
-<pre>\r
-flattened = join listOfLists\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-throw new RuntimeException("Unhandled case.");\r
-</pre>\r
-</td><td>\r
-<pre>fail "Unhandled case."</pre>\r
-</td></tr>\r
-\r
-\r
-<tr><td><pre>\r
-<b>try</b> {\r
-    ...\r
-    <b>throw</b> new ExceptionX(...);\r
-    ...\r
-} <b>catch</b>(ExceptionX e) {\r
-    ...\r
-} <b>finally</b> {\r
-    ...\r
-}\r
-</pre>\r
-</td><td>\r
-Currently no correspondence. Exceptions need to be thrown and catched in Java code.\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-<b>synchronized</b>(obj) {\r
-    ...\r
-}\r
-</pre>\r
-</td><td>\r
-Currently no correspondence. Synchronization must be done in Java code.\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-<b>final static class</b> Vec3 {\r
-    public final double x;\r
-    public final double y;\r
-    public final double z;\r
-    \r
-    public Vec3(double x, \r
-                double y, \r
-                double x) {\r
-        this.x = x;\r
-        this.y = y;\r
-        this.z = z;\r
-    }\r
-}\r
-</pre>\r
-</td><td><pre>\r
-<b>data</b> Vec3 = Vec3 Double Double Double\r
-</pre>\r
-\r
-In future also:\r
-\r
-<pre>\r
-<b>data</b> Vec3 = Vec3 {\r
-  x :: Double,\r
-  y :: Double,\r
-  z :: Double\r
-}\r
-</pre>\r
-</td></tr>\r
-\r
-<tr><td><pre>\r
-public static interface Num {}\r
-public static class Int implements Num {\r
-    public static final int value;\r
-    public Int(int value) {\r
-        this.value = value;\r
-    }  \r
-}\r
-public static class Real implements Num {\r
-    public static final double value;\r
-    public Real(double value) {\r
-        this.value = value;\r
-    } \r
-}\r
-</pre>\r
-</td><td><pre>\r
-data Num = Int Integer\r
-          | Real Double\r
-</pre></td></tr>\r
-\r
-<tr><td><pre>\r
-public static Num add(Num a_, Num b_) {\r
-    if(a_ instanceof Int) {\r
-        Int a = (Int)a_;\r
-        if(b_ instanceof Int) {\r
-            Int b = (Int)b_;\r
-            return new Int(a.value + b.value);\r
-        }\r
-        else if(b_ instanceof Real) {\r
-            Real b = (Real)b_;\r
-            return new Real(a.value + b.value);\r
-        }\r
-    }\r
-    else if(a_ instanceof Real) {\r
-        Real a = (Real)a_;\r
-        if(b_ instanceof Int) {\r
-            Int b = (Int)b_;\r
-            return new Real(a.value + b.value);\r
-        }\r
-        else if(b_ instanceof Real) {\r
-            Real b = (Real)b_;\r
-            return new Real(a.value + b.value);\r
-        }\r
-    }\r
-    throw new IllegalArgumentException();\r
-}\r
-</pre>\r
-</td><td><pre>\r
-add :: Num -> Num -> Num\r
-add (Int a)  (Int b)  = Int (a + b)\r
-add (Int a)  (Real b) = Real (fromInteger a + b)\r
-add (Real a) (Int b)  = Real (a + fromInteger b)\r
-add (Real a) (Real b) = Real (a + b)\r
-</pre></td></tr>\r
-\r
-<tr><td><pre>\r
-public static interface Bijection<A,B> {\r
-    B forward(A v);\r
-    A backward(B v);\r
-}\r
-\r
-Bijection<Integer,Integer> inc = \r
-new Bijection<Integer,Integer> {\r
-   public Integer forward(Integer v) {\r
-       return v + 1;\r
-   }\r
-   public Integer backward(Integer v) {\r
-       return v - 1;\r
-   }\r
-}\r
-</pre>\r
-</td><td><pre>\r
-data Bijection a b = \r
-    Bijection (a -> b) (b -> a)\r
-    \r
-forward (Bijection f _) v = f v \r
-backward (Bijection _ f) v = f v\r
-\r
-inc = Bijection (\v -> v + 1) (\v -> v - 1)\r
-</pre>\r
-\r
-In future:\r
-\r
-<pre>\r
-data Bijection a b = Bijection {\r
-    forward :: a -> b,\r
-    backward :: b -> a\r
-}\r
-\r
-inc = Bijection {\r
-    forward v = v + 1,\r
-    backward v = v - 1\r
-}\r
-</pre>\r
-</td></tr>\r
-</table>\r
-\r
-=== Longer examples ===\r
-\r
-<table border="1">\r
-<tr><td><pre>\r
-publid static int findIndex(List<String> strings, String target) {\r
-    int low=0, high=xs.size();\r
-    while(high-low > 1) {\r
-        int middle = (low + high)/2;\r
-        int cmp = xs.get(middle).compareTo(target);\r
-        if(cmp < 0)\r
-            low = middle;\r
-        else if(cmp > 0)\r
-            high = middle;\r
-        else\r
-            return middle;\r
-    }\r
-}\r
-</pre>\r
-</td><td><pre>\r
-findIndex :: [ String ] -> String -> Integer\r
-findIndex strings target = loop 0 (length strings) \r
-  where\r
-    loop low high \r
-    | high - low > 1 = do\r
-        middle = (low + high) `div` 2\r
-        cmp = compare (xs!middle) target\r
-        if cmp < 0\r
-        then loop middle high\r
-        else if cmp > 0\r
-        then loop low middle\r
-        else middle\r
-    | otherwise = low \r
-</pre>\r
-</td></tr>\r
+== Comparison of Java and SCL ==
+
+=== Language constructions and patterns ===
+
+<table border="1">
+<tr>
+<td><pre>0.5 + x * (2e-3 + x * 2)</pre></td>
+<td><pre>0.5 + x * (2e-3 + x * 2)</pre></td>
+</tr>
+
+<tr>
+<td><pre>x >= 0 && x <= 1</pre></td>
+<td><pre>x >= 0 && x <= 1</pre></td>
+</tr>
+
+<tr>
+<td><pre>Math.sin(a1) - Math.cos(a2)</pre></td>
+<td><pre>sin a1 - cos a2</pre></td></tr>
+
+<tr>
+<td><pre>cond ? value : alternative</pre></td>
+<td><pre><b>if</b> cond <b>then</b> value <b>else</b> alternative</pre></td>
+</tr>
+
+<tr>
+<td><pre>"I am " + age + " years old."</pre></td>
+<td>
+<pre>"I am " + show age + " years old."</pre>
+
+In future:
+
+<pre>"I am ${age} years old."</pre>
+</td>
+</tr>
+
+<tr><td><pre>
+<b>final</b> int sum = a + b;</pre>
+</td><td><pre>
+sum = a + b</pre>
+</td></tr>
+
+<tr><td><pre>
+public static String decorate(String x) {
+    return "(" + x + ")"; 
+}</pre>
+</td><td><pre>
+decorate :: String -> String
+decorate x = "(" + x + ")"</pre>
+(the first line is optional)
+</td></tr>
+
+<tr><td><pre>
+{
+    statement1;
+    statement2;
+    statement3;
+}</pre>
+</td><td><pre>
+<b>do</b>
+    statement1
+    statement2
+    statement3
+</pre></td></tr>
+
+<tr><td><pre>
+<b>if</b>(cond1)
+    statement1;
+<b>else if</b>(cond2)
+    statement2;
+<b>else</b> 
+    statement3;
+</pre></td><td><pre>
+<b>if</b> cond1
+<b>then</b> statement1
+<b>else if</b> cond2
+<b>then</b> statement2
+<b>else</b> statement3
+</pre></td></tr>
+
+<tr><td><pre>
+<b>for</b>(T x : l)
+    statement;
+</pre></td><td><pre>
+for l (\x -> 
+    statement
+)
+</pre></td></tr>
+
+<tr><td><pre>
+<b>while</b>(cond) statement;
+</pre></td><td><pre>
+while (\() -> cond) (\() -> statement)
+</pre>
+In future with improvements to macros:
+<pre>
+while cond statement
+</pre>
+</td></tr>
+
+<tr><td><pre>
+int var;
+<b>switch</b>(value) {
+<b>case</b> Label1: 
+    var = case1; 
+    break;
+<b>case</b> Label2: 
+    var = case2; 
+    break;
+<b>default</b>:
+    var = case3;        
+}</pre>
+</td><td><pre>
+var = <b>match</b> value <b>with</b>
+    Label1 -> case1
+    Label2 -> case2
+    _      -> case3
+</pre>
+</td></tr>
+
+<tr><td><pre>
+<b>break</b>;
+<b>continue</b>;
+<b>return</b> x; // In the middle of the code
+</pre></td><td>No exact correspondence. However, every control sequence can be written in the following form:
+<pre>label1 initialState
+  where
+    label1 state = 
+        ...
+        then label2 modifiedState1
+        else label3 modifiedState2
+    label2 state = 
+        ...
+    label3 state = 
+        ...
+        label1 modifiedState</pre>
+</td></tr>
+
+<tr><td><pre>
+int a, b;
+<b>if</b>(cond) {
+    a = aExp1;
+    b = bExp1;
+}
+<b>else</b> {
+    a = aExp2;
+    b = bExp2;
+}
+</pre>
+</td><td><pre>
+(a, b) = <b>if</b> cond
+          <b>then</b> (aExp1, bExp1)
+          <b>else</b> (aExp2, bExp2)         
+</pre>
+</td></tr>
+
+<tr><td><pre>
+int a = 1;
+a = 2;
+a = 3;
+return a;
+</pre>
+</td><td><pre>
+a = ref 1
+a := 2
+a := 3
+getRef a
+</pre>
+
+The name of the function <code>getRef</code> will change in the future and is
+probably replaced by some special syntax. For example in ML <code>getRef a</code>
+would be written as <code>!a</code>.
+
+</td></tr>
+
+<tr><td><pre>
+public static String f(int x) {
+    if(x >= 0)
+        return Integer.toString(x);
+    else
+        return null;
+}</pre>
+</td><td><pre>
+f :: Integer -> Maybe String
+f x | x >= 0    = Just (show x)
+     | otherwise = Nothing
+</pre>
+</td></tr>
+
+<tr><td><pre>
+public static int invF(String s) {
+    if(s == null)
+        return -1;
+    else
+        return Integer.parseInt(s);
+}</pre>
+</td><td><pre>
+invF :: Maybe String -> Integer
+invF Nothing  = -1
+invF (Just s) = read s
+</pre>
+</td></tr>
+
+<tr><td><pre>
+Arrays.asList(new String[] {"x", "y", "z"})
+</pre>
+</td><td><pre>
+[ "x", "y", "z" ]
+</pre>
+</td></tr>
+
+<tr><td><pre>
+l.get(3)
+</pre>
+</td><td><pre>
+l!3
+</pre>
+</td></tr>
+
+<tr><td><pre>
+List<String> decorated = new ArrayList<String>();
+for(String s : undecorated)
+    decorated.add("(" + s + ")");
+</pre>
+</td><td><pre>
+decorated = [ "(" + s + ")" | s <- undecorated ]
+</pre>
+or
+<pre>
+decorated = map (\s -> "(" + s + ")") undecorated
+</pre>
+</td></tr>
+
+<tr><td><pre>
+List<String> nonempty = new ArrayList<String>();
+for(String s : l)
+    if(!s.isEmpty())
+        nonempty.add(l);
+</pre>
+</td><td><pre>
+decorated = [ s | s <- l, s != "" ]
+</pre>
+or
+<pre>
+decorated = filter (\s -> s != "") l
+</pre>
+</td></tr>
+
+<tr><td><pre>
+List<List<String>> listOfLists;
+List<String> flattened 
+    = new ArrayList<String>();
+for(List<String> l : listOfLists)
+    for(String s : l)
+        flattened.add(s);
+</pre>
+</td><td><pre>
+flattened = [ s | l <- listOfLists, s <- l ]
+</pre>
+or
+<pre>
+flattened = sum listOfLists
+</pre>
+or
+<pre>
+flattened = join listOfLists
+</pre>
+</td></tr>
+
+<tr><td><pre>
+throw new RuntimeException("Unhandled case.");
+</pre>
+</td><td>
+<pre>fail "Unhandled case."</pre>
+</td></tr>
+
+
+<tr><td><pre>
+<b>try</b> {
+    ...
+    <b>throw</b> new ExceptionX(...);
+    ...
+} <b>catch</b>(ExceptionX e) {
+    ...
+} <b>finally</b> {
+    ...
+}
+</pre>
+</td><td>
+Currently no correspondence. Exceptions need to be thrown and catched in Java code.
+</td></tr>
+
+<tr><td><pre>
+<b>synchronized</b>(obj) {
+    ...
+}
+</pre>
+</td><td>
+Currently no correspondence. Synchronization must be done in Java code.
+</td></tr>
+
+<tr><td><pre>
+<b>final static class</b> Vec3 {
+    public final double x;
+    public final double y;
+    public final double z;
+    
+    public Vec3(double x, 
+                double y, 
+                double x) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+}
+</pre>
+</td><td><pre>
+<b>data</b> Vec3 = Vec3 Double Double Double
+</pre>
+
+In future also:
+
+<pre>
+<b>data</b> Vec3 = Vec3 {
+  x :: Double,
+  y :: Double,
+  z :: Double
+}
+</pre>
+</td></tr>
+
+<tr><td><pre>
+public static interface Num {}
+public static class Int implements Num {
+    public static final int value;
+    public Int(int value) {
+        this.value = value;
+    }  
+}
+public static class Real implements Num {
+    public static final double value;
+    public Real(double value) {
+        this.value = value;
+    } 
+}
+</pre>
+</td><td><pre>
+data Num = Int Integer
+          | Real Double
+</pre></td></tr>
+
+<tr><td><pre>
+public static Num add(Num a_, Num b_) {
+    if(a_ instanceof Int) {
+        Int a = (Int)a_;
+        if(b_ instanceof Int) {
+            Int b = (Int)b_;
+            return new Int(a.value + b.value);
+        }
+        else if(b_ instanceof Real) {
+            Real b = (Real)b_;
+            return new Real(a.value + b.value);
+        }
+    }
+    else if(a_ instanceof Real) {
+        Real a = (Real)a_;
+        if(b_ instanceof Int) {
+            Int b = (Int)b_;
+            return new Real(a.value + b.value);
+        }
+        else if(b_ instanceof Real) {
+            Real b = (Real)b_;
+            return new Real(a.value + b.value);
+        }
+    }
+    throw new IllegalArgumentException();
+}
+</pre>
+</td><td><pre>
+add :: Num -> Num -> Num
+add (Int a)  (Int b)  = Int (a + b)
+add (Int a)  (Real b) = Real (fromInteger a + b)
+add (Real a) (Int b)  = Real (a + fromInteger b)
+add (Real a) (Real b) = Real (a + b)
+</pre></td></tr>
+
+<tr><td><pre>
+public static interface Bijection<A,B> {
+    B forward(A v);
+    A backward(B v);
+}
+
+Bijection<Integer,Integer> inc = 
+new Bijection<Integer,Integer> {
+   public Integer forward(Integer v) {
+       return v + 1;
+   }
+   public Integer backward(Integer v) {
+       return v - 1;
+   }
+}
+</pre>
+</td><td><pre>
+data Bijection a b = 
+    Bijection (a -> b) (b -> a)
+    
+forward (Bijection f _) v = f v 
+backward (Bijection _ f) v = f v
+
+inc = Bijection (\v -> v + 1) (\v -> v - 1)
+</pre>
+
+In future:
+
+<pre>
+data Bijection a b = Bijection {
+    forward :: a -> b,
+    backward :: b -> a
+}
+
+inc = Bijection {
+    forward v = v + 1,
+    backward v = v - 1
+}
+</pre>
+</td></tr>
+</table>
+
+=== Longer examples ===
+
+<table border="1">
+<tr><td><pre>
+publid static int findIndex(List<String> strings, String target) {
+    int low=0, high=xs.size();
+    while(high-low > 1) {
+        int middle = (low + high)/2;
+        int cmp = xs.get(middle).compareTo(target);
+        if(cmp < 0)
+            low = middle;
+        else if(cmp > 0)
+            high = middle;
+        else
+            return middle;
+    }
+}
+</pre>
+</td><td><pre>
+findIndex :: [ String ] -> String -> Integer
+findIndex strings target = loop 0 (length strings) 
+  where
+    loop low high 
+    | high - low > 1 = do
+        middle = (low + high) `div` 2
+        cmp = compare (xs!middle) target
+        if cmp < 0
+        then loop middle high
+        else if cmp > 0
+        then loop low middle
+        else middle
+    | otherwise = low 
+</pre>
+</td></tr>
 </table>
\ No newline at end of file