Skip to content
  • Ziyang Liu's avatar
    7d426148
    Allow `return` in more cases in ApplicativeDo · 7d426148
    Ziyang Liu authored and Marge Bot's avatar Marge Bot committed
    The doc says that the last statement of an ado-block can be one of
    `return E`, `return $ E`, `pure E` and `pure $ E`. But `return`
    is not accepted in a few cases such as:
    
    ```haskell
    -- The ado-block only has one statement
    x :: F ()
    x = do
      return ()
    
    -- The ado-block only has let-statements besides the `return`
    y :: F ()
    y = do
      let a = True
      return ()
    ```
    
    These currently require `Monad` instances. This MR fixes it.
    Normally `return` is accepted as the last statement because it is
    stripped in constructing an `ApplicativeStmt`, but this cannot be
    done in the above cases, so instead we replace `return` by `pure`.
    
    A similar but different issue (when the ado-block contains `BindStmt`
    or `BodyStmt`, the second last statement cannot be `LetStmt`, even if
    the last statement uses `pure`) is fixed in !6786.
    7d426148
    Allow `return` in more cases in ApplicativeDo
    Ziyang Liu authored and Marge Bot's avatar Marge Bot committed
    The doc says that the last statement of an ado-block can be one of
    `return E`, `return $ E`, `pure E` and `pure $ E`. But `return`
    is not accepted in a few cases such as:
    
    ```haskell
    -- The ado-block only has one statement
    x :: F ()
    x = do
      return ()
    
    -- The ado-block only has let-statements besides the `return`
    y :: F ()
    y = do
      let a = True
      return ()
    ```
    
    These currently require `Monad` instances. This MR fixes it.
    Normally `return` is accepted as the last statement because it is
    stripped in constructing an `ApplicativeStmt`, but this cannot be
    done in the above cases, so instead we replace `return` by `pure`.
    
    A similar but different issue (when the ado-block contains `BindStmt`
    or `BodyStmt`, the second last statement cannot be `LetStmt`, even if
    the last statement uses `pure`) is fixed in !6786.
Loading