How to chain `<-`?

Hello,

I have this piece of code:

  trgls     <- trianglesIO
  triangles <- newIORef trgls

How can I get triangles from trianglesIO in one line?

2 Likes

I’ve found: triangles <- trianglesIO >>= newIORef.

3 Likes

You can also use the flipped version to keep the information flow direction right to left:

  triangles <- newIORef =<< trianglesIO

The .. <- .. is built in syntax while >>= and =<< are normal operators which could have be defined by users. User defined operators will always be more flexible than built in syntax.

4 Likes

Alternatively, use more exact names:

  initial <- initTriangles
  current <- newIORef initial
1 Like