Thank you for your reply. So what you are saying is that I actually don't need Monads to perform the tasks Monads supports ? Thank you very much. Regards Skagen ______________________________________________________ Går mail for langsomt for dig? Så prøv Yahoo! Messenger - her kan du i løbet af få sekunder udveksle beskeder med de venner, der er online. Messenger finder du på adressen: http://dk.messenger.yahoo.com
So what you are saying is that I actually don't need Monads to perform the tasks Monads supports ?
Indeed. However, not using the Monadic do syntax results in hardly-readible code. For an explanation of how monads can be written in a functional way, see http://www.engr.mun.ca/~theo/Misc/haskell_and_monads.htm
Hello! On Thu, May 17, 2001 at 11:57:45AM +0200, Rijk-Jan van Haaften wrote:
So what you are saying is that I actually don't need Monads to perform the tasks Monads supports ?
Indeed. However, not using the Monadic do syntax results in hardly-readible code.
I don't really think so. The operator precedences for >> and >>= are quite okay, especially combined to the precedence of lambda binding. How is main = getLine >>= \line -> let number = read line in let result = number + 42 in print result less readable than main = do line <- getLine let number = read line let result = number + 42 print result ? Or main = putStr "Hello! What's your name?" >> getLine >>= \name -> putStrLn ("Hello, " ++ name ++ "!") compared to main = do putStr "Hello! What's your name?" name <- getLine putStrLn ("Hello, " ++ name ++ "!")
[...]
Yes, I use do syntax where appropriate (e.g. also for usual parser monads), however, the operator syntax can be written quite readably too. Kind regards, Hannah.
Rijk-Jan van Haaften >>= Hannah Schroeter:
... However, not using the Monadic do syntax results in hardly-readible code.
I don't really think so. The operator precedences for >> and >>= are quite okay, especially combined to the precedence of lambda binding.
...
main = do putStr "Hello! What's your name?"
...
Yes, I use do syntax where appropriate (e.g. also for usual parser monads), however, the operator syntax can be written quite readably too.
I would add that sometimes you may be interested in Monadic SEMANTICS at a more profound level, trying to hide it completely at the surface. Then, the <<do>> syntax is an abomination. The examples are already in the Wadler's "Essence". Imagine the construction of a small interpreter, a virtual machine which not only evaluates the expressions (belonging to a trivial Monad), but perform some side effects, or provides for exceptions propagated through a chain of Maybes. Then the idea is to * base the machine on the appropriate Monad * "lift" all standard operators so that an innocent user can write (f x) and never x >>= f (or even worse). The <<do>> construct in such a context resembles the programming in assembler, and calling it more readable is hmmmm... not very convincing. (My favourite example is the "time-machine" monad, a counter-clock-wise State Monad proposed once by Wadler, and used by myself to implement the reverse automatic differentiation algorithm. Understanding what's going on is difficult. The <<do>> syntax makes it *worse*.) Jerzy Karczmarczuk Caen, France
On 2001-05-18T08:56:57+0200, Jerzy Karczmarczuk wrote:
The examples are already in the Wadler's "Essence". Imagine the construction of a small interpreter, a virtual machine which not only evaluates the expressions (belonging to a trivial Monad), but perform some side effects, or provides for exceptions propagated through a chain of Maybes. Then the idea is to
* base the machine on the appropriate Monad * "lift" all standard operators so that an innocent user can write (f x) and never x >>= f (or even worse).
Perhaps you already know about Filinski's PhD thesis? He seems to have proven that we already have the "small interpreter" you want, inside of any programming language that supports call/cc and storing a function in a single storage cell. ML is such a programming language. You can define your own monads yet rely on implicit evaluation ordering in ML to do the lifting you want! -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig Learn Esperanto and make friends around the world http://www.esperanto.net
participants (5)
-
Hannah Schroeter -
Jerzy Karczmarczuk -
Ken Shan -
Mads Skagen -
Rijk-Jan van Haaften