'Mutable field structure in Haskell without Lens

I want to write a function that generates a structure that has fields of mutable values.

Originally, I wrote in TypeScript and the code is as follows:

const Foo = <A>(a: A) =>
  ({
    x: a,             //mutable
    y: someFunction   //mutable
  });

Basically, the type of x is always A, and y is A -> A even they are mutable.

I just need a simple setter and getter function to mutate the fields, and preferably want to use just ST-monad and don't want to depend on libraries such as Lens.

The closest thing I've found so far is ST mutable array Data.Array.MArray, but this one is for arrays not structures.

What is simple smart approach do you recommend?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source