[Haskell-cafe] foreach

Twan van Laarhoven twanvl at gmail.com
Mon Sep 18 18:26:07 EDT 2006

> Couldn't '\' delimit a subexpression, as parentheses do? Would there be 
> any ambiguity in accepting code like State \s -> (s, s) instead of 
> requiring State $ \s -> (s, s), or taking

Looking at the Haskell 98 language definition it seems that a whole 
class of these expressions are disallowed inside function applications:
 > exp10   ->     \ apat1 ... apatn -> exp
 >         |     let decls in exp
 >         |     if exp then exp else exp
 >         |     case exp of { alts }
 >         |     do { stmts }
 >         |     fexp

This means that none of the following are legal Haskell declarations, 
even though they are unambiguous:
 > a = State \s -> (s, s)
 > b = map let f x = x + 1 in f
 > c = return if a then b else c
 > d = catch do x <- getLine
 >              return x

It can be argued that this is mostly obfuscation, and that it can 
sometimes be confusing, especially with let and do, but it saves on the 
amount of parentheses or $s. What was the original reasoning for 
disallowing these more complex expressions as the rightmost argument in 
an fexp? Or was this simply not considered?


More information about the Haskell-Cafe mailing list