fantasyland / sweet-fantasies

sweet.js macros for Fantasy Land compatible structures.
34 stars 7 forks source link

Syntax for Applicatives #3

Closed jonifreeman closed 11 years ago

jonifreeman commented 11 years ago

Should we add syntax to apply Applicatives?

For instance:

/*  
  $ap f(x, y, z)

  Desugared: f.ap(x).ap(y).ap(z)

  $ap(f(100)(x, y, z)

  Desugared: f(100).ap(x).ap(y).ap(z)
*/
macro $ap {
  case $f:ident($x:expr (,) ...) => {
    $f $(.ap($x)) ...
  }
  case ($f:expr)($x:expr (,) ...) => {
    $f $(.ap($x)) ...
  }
}

Any comments?

markandrus commented 11 years ago

I like it : )

jonifreeman commented 11 years ago

I let this rest here for awhile. The syntax makes use of applicative idiom nicely readable but the original form is not bad either. So a conservatist in me says that don't add it :)

puffnfresh commented 11 years ago

I really like it. :+1:

jonifreeman commented 11 years ago

Added https://github.com/pufuwozu/sweet-fantasies/commit/d6f94cffb70c812955c5904ca7a6337479ed1c72