[Haskell-cafe] Re: Sugar for function application

Ertugrul Soeylemez es at ertes.de
Sun Mar 28 19:49:20 EDT 2010

Tillmann Rendel <rendel at informatik.uni-marburg.de> wrote:

> 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).

I could think of a layout-based keyword to construct Alternative values,
which wouldn't require type hackery.  Something like this:


which would be equivalent to

  a <|> b <|> c

Then you could write:

  layoutSet myButton $ acat
    [text := "Ok"]
    [on action := doSomething]

Occasionally this would be very useful for parsers:

  numericWord = acat
    try $ 1 <$ string "one"
    try $ 2 <$ string "two"
    try $ 3 <$ string "three"

This together with layout-based function application could be great
syntactical features.  Firstly it would be strictly optional, so you
could still program without or with less layout, if you prefer.
Secondly you could get rid of a number of other keywords this way, most
notably the 'if', 'then' and 'else' keywords.

Some people like 'then' and 'else'.  So instead of completely removing
them, you can turn them into functions instead:

  newtype Then a = Then a
  newtype Else a = Else a

  if :: Bool -> Then a -> Else a -> a
  then :: a -> Then a
  else :: a -> Else a

  if condition $$
    then thisIfTrue
    else thisIfFalse

The benefit is that 'if', 'then' and 'else' aren't keywords anymore and
can be used for other purposes in narrow scopes.  Sometimes this would
be useful.


nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list