
From: A Neighborhood of Infinity Monday, August 07, 2006 You Could Have Invented Monads! (And Maybe You Already Have.) http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html The following part: do let x = 7 y <- Writer (x+1,"inc\n") z <- Writer (2*y,"double\n") Writer (z-1,"dec\n") The notation is very suggestive. When we write y <- ... it's as if we can pretend that the expression on the right hand side is just x+1 and that the side-effect just looks after itself. Why pretend? Couldn't the syntax be: do let x = 7 y <- x+1, Writer ("inc\n") z <- 2*y, Writer ("double\n") z-1, Writer ("dec\n") Or some other delimiter than the comma? I'm thinking this syntax might be easier to understand. :)

On Monday 13 December 2010 22:06:41, caseyh@istar.ca wrote:
Why pretend? Couldn't the syntax be:
do let x = 7 y <- x+1, Writer ("inc\n") z <- 2*y, Writer ("double\n") z-1, Writer ("dec\n")
Or some other delimiter than the comma?
Doesn't work for other monads, I think (nor for the general x <- someWriter foo). How would that translate to [], State, IO, ...?

On Mon, 13 Dec 2010, caseyh@istar.ca wrote:
do let x = 7 y <- x+1, Writer ("inc\n") z <- 2*y, Writer ("double\n") z-1, Writer ("dec\n")
Or some other delimiter than the comma?
You can simply define your own syntax using an infix operator, say: a # str = Writer (a, str) do let x = 7 y <- x+1 # "inc\n" z <- 2*y # "double\n" z-1 # "dec\n"
participants (3)
-
caseyh@istar.ca
-
Daniel Fischer
-
Henning Thielemann