[Haskell-cafe] Sugar for function application

Tillmann Rendel rendel at informatik.uni-marburg.de
Wed Mar 24 05:30:12 EDT 2010

Brandon S. Allbery KF8NH wrote:
> On Mar 23, 2010, at 13:39 , Ertugrul Soeylemez wrote:
>> layout-style syntactic sugar for function application.
>> Here is an example of what it might look like:
>>  function $$ anArgument
>>              sin (x^2)
>>              anotherArgument
>>              f $ x + 3
> Doesn't layout already do this?
>   function arg1
>            arg2
>            arg3

The layout rule is only triggered by a limited set of keywords (like do, 
where, let, ...), and Ertugrul's proposal is to add a keyword for 
function applicaton to this set.

I like this idea, because it would enable non-monadic embedded DSLs to 
use layout.

For example, consider setting properties in wxHaskell:

   layoutSet myButton $$
     text := "Ok"
     on action := doSomething

instead of

   set myButton
     [ text := "Ok"
     , on action := doSomething

Of course, this would need some type hackery à la PrintF to make set 
accept multiple arguments, and the proliferation of such type hackery 
may seem unfortunate. On the other hand, the hackery could possibly be 
encapsulated in a combinator like

   polyvariadic :: Poly a b c => ([a] -> b) -> c

so that layoutSet can be implemented as

   layoutSet widget = polyvariadic (set widget).


More information about the Haskell-Cafe mailing list