Accessing the row variable within the function

66 views Asked by At

My understanding of row polymorphism in ML is that we can access the row variable within the function.

fun f {x : real, y : real, R} = {x = 2 * x, y = 2 * y, R};
 => (* f : {x : real, y : real, _ : ..a} -> {x : real, y : real, _ : ..a} *)

f {x = 2.0, y = 3.0, z = 4.0}; 
=> (* it = {x = 4.0, y = 6.0, z = 4.0}; *)

Just curious if this is possible in PureScript.

1

There are 1 answers

0
stholzm On BEST ANSWER

I assume you want to update some properties of a record without discarding the other properties:

f :: forall r. { x :: Int, y :: Int | r } -> { x :: Int, y :: Int | r }
f r = r { x = r.x * 2, y = r.y * 2 }