0

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.

RAbraham
  • 5,956
  • 8
  • 45
  • 80

1 Answers1

2

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 }
stholzm
  • 3,395
  • 19
  • 31