[Haskell-cafe] extending Do notation

silvio silvio.frischi at gmail.com
Tue May 20 17:50:11 UTC 2014


>   let x = stmtpart1 { exp } stmtpart2
>   more stuff x other things

that doesn't make sense stmts can only occure in a do not in a let

stmt 	-> 	exp ;
	| 	pat <- exp ;
	| 	let decls ;
	| 	;

> But what about lambdas:
> 
>   stmtpart1 (\x -> {exp}) stmtpart2
> 
> 
> And what about nested braces:
> 
>   stmtpart1 { something { more } whatever } stmtpart2
> 
> 
> There are lots of other cases to consider :)

Ok now we have finally come to implementation. I don't know a lot of
compiler internals but it could work something along those lines.

make "{ exp }" an expression.

if you are parsing a statement there needs to be some context so an an
expression can make use of the fact that it's in a do block. the
expression "{ exp }" tells the statement to do "newvarname <- exp" and
returns newvarname. Of course the order in which these "newvarname <-
exp" will get executed is the order in which the expression results are
returned, in other of the closing brackets. This should cover the lambda
question and the nested question.

silvio



More information about the Haskell-Cafe mailing list