[Haskell-cafe] Re: Sugar for function application

2010-03-28 Thread Ertugrul Soeylemez
Tillmann Rendel ren...@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:

  acat
a
b
c

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.


Greets
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://blog.ertes.de/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Sugar for function application

2010-03-25 Thread Heinrich Apfelmus
Tillmann Rendel wrote:
 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

You can abuse  do  notation to achieve that, by wrapping the list in a
suitable  Writer  monad

layoutSet myButton $ do
text = Ok
on action = doSomething

with

   (=) :: Property a - a - Writer Properties ()

It's ugly semantically but pleasant syntactically.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Sugar for function application

2010-03-23 Thread Maciej Piechotka
On Tue, 2010-03-23 at 22:23 -0400, Brandon S. Allbery KF8NH wrote:
 On Mar 23, 2010, at 13:39 , Ertugrul Soeylemez wrote:
  code look worse:  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
 


As I understend

function $$ sin x
y
z
is 
function (sin x) (y)

function sin x
 y
 z
is
function (sin) (x) (y) (z)

function $ sin x
   y
   z
is
function (sin (x) (y) (z))

Regards


signature.asc
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe