0

I'm trying to use the do-notation together with IO from agda-stdlib, but, strangely, the type of _>>_ uses : {B : Set a} (m₁ : ∞ (IO B)) (m₂ : ∞ (IO A)) → IO A. Because of that, I need to interleave s between applications, but this makes the usage awkward. For example, s are necessary to build a program that prints a line:

main : IO ⊤
main = do
  ♯ (putStrLn "hi")
  ♯ (return tt)

Moreover, extending it with more lines fail to check. I have to abandon the do-notation, like this:

main : IO ⊤
main = 
  ♯ (♯ putStrLn "hi" >> 
    ♯ putStrLn "ho") >>
    ♯ return tt

Which looks terrible. I could redefine _>>_ and _>>=_:

_>>_ : {A : Set} {B : Set} (m₁ : (IO B)) (m₂ : (IO A)) → IO A
_>>_ a b = (♯ a) IO.>> (♯ b)

But I'm assuming that's not what I'm expected to do. So, am I missing something? What is the proper way to use it?

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286

1 Answers1

1

The implementation of IO in the standard library predates the addition of do-notation in Agda, so it was not written with do-notation in mind. Ulf's Agda prelude has a more up-to-date implementation of IO that does support do-notation.

Jesper
  • 2,781
  • 13
  • 14