Opened 20 months ago

Closed 8 months ago

Last modified 8 months ago

#14670 closed bug (fixed)

-XRebindableSyntax needs return?

Reported by: jackkelly Owned by:
Priority: normal Milestone: 8.10.1
Component: Compiler Version: 8.2.2
Keywords: RebindableSyntax, ApplicativeDo Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case: rebindable/T14670
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The documentation for -XRebindableSyntax ( https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#rebindable-syntax-and-the-implicit-prelude-import ) reads:

“Do” notation is translated using whatever functions (>>=), (>>), and fail, are in scope (not the Prelude versions). List comprehensions, mdo (The recursive do-notation), and parallel array comprehensions, are unaffected.

The following code fails to compile (also confirmed to fail on GHC 8.0.2):

{-# LANGUAGE RebindableSyntax #-}

module Lib where

import Prelude (IO)

foo :: IO ()
foo = do
  pure ()

It fails with this error:

/home/kel317/z/src/Lib.hs:9:3: error:
    Not in scope: ‘return’
    Perhaps you want to add ‘return’ to the import list
    in the import of ‘Prelude’ (src/Lib.hs:5:1-19).
  |
9 |   pure ()
  |   ^^^^^^^

To my reading, either something funky is going on with the way the do-notation is desugared, or the documentation needs to be corrected.

Change History (11)

comment:1 Changed 20 months ago by bgamari

Milestone: 8.6.1
Test Case: rebindable/T14670

Indeed that is quite curious. My first thought was perhaps ApplicativeDo was involved, but it's not enabled.

comment:2 Changed 20 months ago by dfeuer

I see that in compiler/rename/RnExpr.hs there's a "TODO I don't know how to get this right for rebindable syntax", but I don't think any of that is supposed to be used without ApplicativeDo. I haven't yet been able to find a place where ApplicativeDo checking obviously leaks out elsewhere.

comment:3 Changed 20 months ago by Ben Gamari <ben@…>

In 765ba657/ghc:

testsuite: Add testcase for #14670

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14670

Differential Revision: https://phabricator.haskell.org/D4314

comment:4 Changed 20 months ago by simonpj

Owner: set to simonmar

Simon: this is your bailiwick.

comment:5 Changed 16 months ago by simonmar

Keywords: ApplicativeDo added

comment:6 Changed 15 months ago by bgamari

Milestone: 8.6.18.8.1

These won't be addressed by GHC 8.6.

comment:7 Changed 9 months ago by osa1

Milestone: 8.8.18.10.1

Bumping milestones of low-priority tickets.

comment:8 Changed 8 months ago by josef

Resolution: worksforme
Status: newclosed

This is fixed. With the latest GHC I get:

Lib.hs:9:3: error:
    • Variable not in scope: pure :: () -> IO ()
    • Perhaps you want to add ‘pure’ to the import list
      in the import of ‘Prelude’ (Lib.hs:5:1-19).
  |
9 |   pure ()
  |   ^^^^

I'm closing this ticket. Reopen if you disagree.

comment:9 Changed 8 months ago by jackkelly

This still fails for me on GHC 8.6.3, which is the latest I see on https://www.haskell.org/ghc . If I've missed a later version, or you've confirmed a fix on GHC HEAD, then please re-close:

$ ghci Test.hs 
GHCi, version 8.6.3: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Test             ( Test.hs, interpreted )

Test.hs:7:3: error:
    Not in scope: ‘return’
    Perhaps you want to add ‘return’ to the import list
    in the import of ‘Prelude’ (Test.hs:4:1-19).
  
7 |   pure ()
  |   ^^^^^^^
Failed, no modules loaded.
Prelude> 
$ cat Test.hs
{-# LANGUAGE RebindableSyntax #-}

module Test where
import Prelude (IO)
foo :: IO ()
foo = do
  pure ()

comment:10 Changed 8 months ago by jackkelly

Owner: simonmar deleted
Resolution: worksforme
Status: closednew

comment:11 Changed 8 months ago by ulysses4ever

Resolution: fixed
Status: newclosed

jackkelly, when josef wrote “latest GHC”, he probably meant HEAD, not the latest released version. This really works as expected with HEAD.

It would be interesting to find out which commit fixed it. I tried to git bisect but submodules don't cooperate with me (unsurprisingly). I got:

fatal: repository '../hadrian.git' does not exist

I tried various combinations of make maintainer-clean / boot-configure / git submodule update --recursive.

Last edited 8 months ago by ulysses4ever (previous) (diff)
Note: See TracTickets for help on using tickets.