haskell's prefix exprs

Brian Hulley brianh at metamilk.com
Tue Jul 10 06:52:05 EDT 2007


Christian Maeder wrote:
> Hi,
>
> I would like haskell to accept the following (currently illegal)
> expressions as syntactically valid prefix applications:
>
> f = id \ _ -> []
> g = id let x = [] in x
> h = id case [] of [] -> []
> i = id do []
> j = id if True then [] else []
>
> The rational is that expressions starting with a keyword should extend
> as far as possible (to the right and over several lines within their
> layout).
>   
On page 15/16 of the H98 report I think this could be achieved by:

exp10 ::= fexp

fexp ::= [fexp] keyexp

keyexp ::= \ apat ... -> exp | let ... | ... | aexp

> (In fact, maybe for haskell' "$" could be changed to a keyword.)
>   

Alternatively the # symbol could be removed from the pool of symbol 
chars and used to construct syntactic sugar so you could use

      f = id #$ \_ -> []

to mean exactly

      f = id (\_ -> [])

I think when the idea of $ arose originally people didn't at that time 
know about the many cases where the use of $ is not semantically 
equivalent to explict brackets, since this knowledge probably only arose 
later with the introduction of rank-n polymorphism. (Of course the need 
for #$ would be fixed with impredicative types as in MLF.)

Best regards,
Brian.


More information about the Glasgow-haskell-users mailing list