[GHC] #15016: Referencing a do-bound variable in a rec block with ApplicativeDo results in variable not in scope during type checking
GHC
ghc-devs at haskell.org
Mon Apr 9 14:42:17 UTC 2018
#15016: Referencing a do-bound variable in a rec block with ApplicativeDo results
in variable not in scope during type checking
-------------------------------------+-------------------------------------
Reporter: rjmk | Owner: sighingnow
Type: bug | Status: new
Priority: normal | Milestone: 8.4.3
Component: Compiler | Version: 8.2.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by sighingnow):
* owner: (none) => sighingnow
Comment:
I think the "not is scope" is by design. See more discussion under
ticket:4148. When we use `rec` in `do` blocks, rather than `mdo` blocks,
the outer variables won't be included into the scope of `rec` block.
The real problem is when there's no binding for `a` inside `rec` block,
the rhs `a` in `let b = a` will have the same name with the outer `a`.
For code:
{{{#!hs
}}}
The rename produces:
{{{#!hs
Lib.f :: MonadFix m_auv => m_auv ()
Lib.f
= do a_auw <- return () |
() <- do rec let b_aux = a_auw
return ()
return ()
}}}
But for code:
{{{#!hs
f :: MonadFix m => m ()
f = do
a <- return ()
rec
let b = a
a = ()
return ()
}}}
The rename produces:
{{{#!hs
Lib.f :: MonadFix m_auv => m_auv ()
Lib.f
= do a_auw <- return () |
() <- do rec let b_aux = a_auy
a_auy = ()
return ()
return ()
}}}
Indeed it's a bug. I'm optimistic to assign that to myself :) We also
should note this behavior of `rec` in documentation.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15016#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list