You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to add syntactic sugar to re-use a variable in from, constraining the new variable. Consider the following expression to compute all paths of length 2:
(*
1 -> 2 -> 3
| ^ ^
| | |
+--> 4 ---+
*)
val edges = [(1, 2), (2, 3), (1, 4), (4, 2), (4, 3)];
from (x, y) in edges,
(y2, z) in edges
where y = y2
group x, z;
val it = [{x=4,z=3},{x=1,z=2},{x=1,z=3}] : {x:int, z:int} list
It is inconvenient to have to declare y2 and then immediately constrain it to equal y. With the new same operator, the following would be equivalent:
from (x, y) in edges,
(same y, z) in edges
group x, z;
The text was updated successfully, but these errors were encountered:
same is not just for within from. Here is its use in a function:
fun f (1, 1) = 0
| f (x, same x) = x
| f (x, y) = x + y;
val f = fn : int * int -> int
f (1, 1);
val it = 0: int;
f (2, 2);
val it = 2: int;
fun (2, 3);
val it = 5: int;
fun f (1, 1) = 0
| f (x, x2 if x = x2) = x
| f (x, y) = x + y;
(The effect is not identical: the pattern guard (x, x2 if x = x2) would add x and x2 to scope, whereas (x, same x) would only add x to scope.)
But in Standard ML and current Morel, you would have to expand as follows:
- fun f (1, 1) = 1
= | f (x, y) = if (x = y) then x else x + y;
val f = fn : int * int -> int
- f (1, 1);
val it = 1 : int
- f (2, 2);
val it = 2 : int
- f (2, 3);
val it = 5 : int
It would be useful to add syntactic sugar to re-use a variable in
from
, constraining the new variable. Consider the following expression to compute all paths of length 2:It is inconvenient to have to declare
y2
and then immediately constrain it to equaly
. With the newsame
operator, the following would be equivalent:The text was updated successfully, but these errors were encountered: