RebindableSyntax warns `return` is not in scope when trying to call `pure`, but does not desugar between the two
The following (incorrect) program fails to compile:
{-# LANGUAGE RebindableSyntax #-}
import Prelude hiding (pure, return)
t = do
pure 5
Not in scope: ‘return’
Perhaps you want to remove ‘return’ from the explicit hiding list
in the import of ‘Prelude’ (/home/sandy/Bug.hs:3:1-40).
|
6 | pure 5
|
Notice that this error mentions return
not being in scope, despite trying to call pure
. This suggests to the user that there is some desugaring going on to transform pure into return (but there isn't!).
Changing the import of Prelude to no longer hide return
now gives the correct error:
import Prelude hiding (pure)
• Variable not in scope: pure :: Integer -> t
• Perhaps you want to remove ‘pure’ from the explicit hiding list
in the import of ‘Prelude’ (/home/sandy/Bug.hs:3:1-28).
|
6 | pure 5
| ^^^^
This is particularly confusing when pure
is in scope and would typecheck but return
is not. The error suggests that there is desugaring going on behind the scenes to turn pure
into return
via rebindable syntax.