Changes between Version 1 and Version 2 of ApplicativeDo


Ignore:
Timestamp:
Oct 11, 2013 9:51:03 AM (6 months ago)
Author:
simonmar
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ApplicativeDo

    v1 v2  
    2020 2. Applicative syntax can be a bit obscure and hard to write. 
    2121    Do-notaiton is more natural, so we would like to be able to write 
    22     Applicative composition in do-notation where possible.  Do notation 
    23     can't be desugared into Applicative in general, but a certain 
    24     subset of it can be. 
     22    Applicative composition in do-notation where possible.  For example: 
     23{{{ 
     24(\x y z -> x*y + y*z + z*x) <$> expr1 <*> expr2 <*> expr3 
     25}}} 
     26    vs. 
     27{{{ 
     28do x <- expr1; y <- expr2; z <- expr3; return $ x*y + y*z + z*x 
     29}}} 
     30 
     31 3. Do-notation can't be desugared into Applicative in general, but a certain 
     32    subset of it can be.  For Applicatives that aren't also Monads, we would still like to 
     33    be able to use the do-notation, albeit with some restrictions, 
     34    and have an Applicative constraint inferred rather than Monad. 
    2535 
    2636Clearly we need Applicative to be a superclass of Monad for this to 
    2737work, hence this can only happen after the AMP changes have landed. 
     38 
     39Since in general Applicative composition might behave differently from monadic bind, any automatic desugaring to Applicative operations would be an opt-in extension: 
     40 
     41{{{ 
     42   {-# LANGUAGE ApplicativeDo #-} 
     43}}} 
    2844 
    2945== Stage 1 
     
    6076{{{ 
    6177  do 
     78    .. stmts1 .. 
    6279    x <- A 
    6380    y <- B 
    6481    z <- E[y] 
    65     .. more .. 
     82    .. stmts2 .. 
    6683}}} 
    6784 
     
    7087{{{ 
    7188  do 
     89    .. stmts1 .. 
    7290    (x,y) <- (,) <$> A <*> B 
    7391    z <- E[y] 
    74     .. more .. 
     92    .. stmts2 .. 
    7593}}} 
    7694