This feels like cargo culting. The point of IO isn't the RealWorld stuff (that's an implementation technique, and not even really true these days as IO offers all sorts of other facilities), the point is that it's a way to get the language's type system to help you distinguish between accidental control flow and essential control flow ( http://www.lihaoyi.com/post/WhatsFunctionalProgrammingAllAbo... ). Without the type system it's a lot of ceremony for no benefit.
I do agree that the RealWorld stuff is there to enforce control flow, but that is exactly one of the things that we needed. I also realise that the modern GHC optimizes such things away, so there is no RealWorld!
Regards implementation, as the type system available in XQuery is much more limited than that of Haskell, I had to choose some mechanism to represent an IO. Actually representing it as a state transforming function that operates on the RealWorld, as was done in the design of the IO Monad for Haskell, seems to work pretty well.
I appreciate that your implementation follows the Haskell one. But the point of IO isn't the implementation, it's to make it easier to maintain code that interacts with the real world. That's the part that feels cargo-culty to me (having gone down the same path in Python once): if the type system can't actually enforce that your monads are composed correctly then you pay the same cost you would in Haskell but don't get the main benefit.
It's an outstandingly well-written introduction, but it only goes so far; a more formal treatment (an inevitably longer one, off topic in a discussion of I/O) would be needed to understand what, exactly, can be done with monads and how they differ from other types.
This post is really nice, but the author doesn't actually explain 'monads.' He does give a good explanation of the IO type in Haskell and the various combinators offered (including the monadic ones).
Site feedback: That blue bar at the top make it looks like your page hasn't loaded. If I want to see how far I've read, I will just look to the right side at the scrollbar.
Aha, nice! I have wondered about doing something similar before.
As part of a module on XML for my MSc I decided to go maximum overkill, and created in XSLT a simple key-value lookup, a breadth-first node search algorithm, and a simple TAP-based test suite to make sure it all worked properly. Almost looked at seeing how much of the Functional Data Structures book I could cram into XSLT for my dissertation before choosing something a little less ambitious.
That is a good writeup, a fun read! I love Haskell but I tend to use a small subset of the language. This means that I am effective when working in my own Haskell projects but reading and understanding other people’s code takes time and effort.