Is it possible to interact with arbitrary Monad instances incrementally at the GHCi prompt?
You can enter “do” commands interactively:
Prelude> x <- return 5
But as far as I can tell, everything is forced into the IO () Monad. What if I want to interact with an arbitrary Monad instead?
Am I forced to write the entire sequence of commands inside a giant do { ... } and/or use the infix operators directly? That’s okay, but I’d much prefer to “enter” an arbitrary monad and interact with it a line at a time.
Possible?
Sure you can. Just annotate your type.
e.g. for the
Maybe Monad:will result in
Or take the list monad:
will result in
Of course you can also play around inside the monad:
which will result in
Just 7