4 ms·
Haskell I/O and XPath
- crb002 8y agoIt's never a good day when I have to pull out AWK and XSLT because that's all the server supports.
- peteretep 8y agoAha, 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.
- paulddraper 8y agoGood post, and clever technique. 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.
- kreetx 8y agoWow! Great article, and interesting info on Philip Wadler!
- ToJans 8y agoOn a side note: IMHO this article contains one of the most accessible explanations I have seen about monads.
- adamretter 8y agoCertainly not what I set out to achieve, but I am very chuffed to hear that. Thank you :-)
- HelloNurse 8y agoIt'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.
- tathougies 8y agoThis 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).
- lmm 8y agoThis 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/WhatsFunctionalProgrammingAllAbout.html http://www.lihaoyi.com/post/WhatsFunctionalProgrammingAllAbo... ). Without the type system it's a lot of ceremony for no benefit.
- adamretter 8y agoI 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 tried to follow closely and adapt both: 1) Section 7.3 "Monadic I/O" from "A History of Haskell", Hudak, Hughes, Peyton Jones and Wadler 2007 - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/07/history.pdf https://www.microsoft.com/en-us/research/wp-content/uploads/... 2) Section 4 "Implementing monadic I/O" from "Imperative functional programming", Wadler and Peyton Jones 1992 - https://www.microsoft.com/en-us/research/wp-content/uploads/1993/01/imperative.pdf https://www.microsoft.com/en-us/research/wp-content/uploads/...
- lmm 8y agoI 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.
- mark_l_watson 8y agoThat 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.
- agumonkey 8y agodidn't know Wadler was part of xquery et al .. interesting. good read