6 Replies - 3390 Views - Last Post: 19 October 2012 - 08:20 PM

#1 time4f5  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 57
  • Joined: 02-December 11

Haskell before Monads for I/O

Posted 14 October 2012 - 03:17 PM

Hi all, I'm working on an assignment and I'm trying to research how Haskell managed I/O before monads were added in Version 1.3. I'm not looking for someone to answer it as much as I could use someone to point me in the right direction. I've googled it but can't seem to find a good site. Just wondering if you may know of one. thanks in advance.
Is This A Good Question/Topic? 0
  • +

Replies To: Haskell before Monads for I/O

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Haskell before Monads for I/O

Posted 14 October 2012 - 11:55 PM

if I understand correctly, they still had 'do' blocks. do blocks can force strict evaluation with a specific order.

but I'm not exactly sure. you might try asking on the Haskell IRC channel, someone there would almost definitely know.

A quick Google search doesn't yield much for me. someone on the IRC might even be able to show you a page that might have other citations.

This post has been edited by ishkabible: 15 October 2012 - 12:01 AM

Was This Post Helpful? 1
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2133
  • View blog
  • Posts: 3,269
  • Joined: 21-June 11

Re: Haskell before Monads for I/O

Posted 15 October 2012 - 02:07 AM

According to Tackling the Awkward Squad [PDF], before IO was introduced, the main function took a lazy list of Response values as its input and produced a lazy list of Request as its output. Each time an element of the output list was produced, the corresponding request (like "read input from/write output to screen/file", "invoke application" etc.) would be executed and, if applicable, the corresponding response value would be added to the input list.

View Postishkabible, on 15 October 2012 - 08:55 AM, said:

if I understand correctly, they still had 'do' blocks. do blocks can force strict evaluation with a specific order.


do-blocks are defined in terms of monads. So if they did exist before, we'd still need to know what they were defined in terms of to make sense of their semantics.

That said I don't think they did exist before monads as I don't see a straight-forward way to desugar them using the Request/Response model described above. Also everyone always complains about how clumsy the old-system was to use - if the old system had do-notation, it could have been used exactly like the new one.

This post has been edited by sepp2k: 15 October 2012 - 02:07 AM

Was This Post Helpful? 1
  • +
  • -

#4 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Haskell before Monads for I/O

Posted 18 October 2012 - 07:29 AM

ya, that sounds better. I just thought it was a construct of the language to allow one expression to be evaluated before the other and that it was just defined in terms of monods later to allow for more elegant and more advanced features.
Was This Post Helpful? 1
  • +
  • -

#5 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: Haskell before Monads for I/O

Posted 19 October 2012 - 07:16 AM

Hmm. Technically, in order to have a monad, all you need is a return function and a bind function. The typeclass and do-notation makes it easier, but a language does not need to know about monads in order for the programmer to use them. For instance, a friend and I recently wanted to make some parser combinators in SML for parsing regexes, and so we implemented bind and return for our parser functions and started using them as monads. So in theory, Haskell always had monads. I have no idea if they were used for I/O before do-notation, though.
Was This Post Helpful? 1
  • +
  • -

#6 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2133
  • View blog
  • Posts: 3,269
  • Joined: 21-June 11

Re: Haskell before Monads for I/O

Posted 19 October 2012 - 09:33 AM

View PostTayacan, on 19 October 2012 - 04:16 PM, said:

Hmm. Technically, in order to have a monad, all you need is a return function and a bind function. The typeclass and do-notation makes it easier, but a language does not need to know about monads in order for the programmer to use them.


Sure, you can implement things like the list monad, the maybe monad or a parser monad without language support (though you will need a sufficiently expressive type system if you want to be able to write functions that work on any type of monad), but that's not really the issue here. The issue is defining the IO monad. That's one that you can't build yourself without having some equivalent (or unsafe) IO system in place already (which Haskell did not).

This post has been edited by sepp2k: 19 October 2012 - 09:33 AM

Was This Post Helpful? 2
  • +
  • -

#7 time4f5  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 57
  • Joined: 02-December 11

Re: Haskell before Monads for I/O

Posted 19 October 2012 - 08:20 PM

Thanks all, you have been very helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1