Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,253
    • Issues 5,253
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 562
    • Merge requests 562
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #4809
Closed
Open
Issue created Nov 30, 2010 by JeremyShaw@trac-JeremyShaw

MonoLocalBinds and type classes cause infinite loop

The following program gets stuck in a loop and prints no output when run:

{-# LANGUAGE MonoLocalBinds #-}
module Main where

import IdentityT (IdentityT(..), XML, runIdentityT)
import XMLGenerator (XMLGenT(..), XMLGen(genElement), Child, EmbedAsChild(..), unXMLGenT)
import System.IO (BufferMode(..), hSetBuffering, stdout)

page :: XMLGenT (IdentityT IO) XML
page = genElement (Nothing, "ul") [] [ asChild (asChild "foo")]
    where
--       item :: XMLGenT (IdentityT IO) [Child (IdentityT IO)]                                                                                                                          
       item = (asChild $ asChild (return "bar" :: XMLGenT (IdentityT IO) String))

main :: IO ()
main =
    do hSetBuffering stdout LineBuffering
       r <- runIdentityT (unXMLGenT page)
       print r

I believe this is due to a compiler bug. There are five things you can do to make it run successfully (i.e., not loop) -- none of which ought to have an effect. Doing any one of the five works though.

Note that 'item' in the 'page' where clause is not actually used anywhere, but three of the five things involve changes to that clause.

  1. remove the 'where' clause in 'page' entirely. After all it is not needed.
  2. uncomment the type signature for 'item'
  3. remove one of the calls to 'asChild' in item.
  4. remove one of the calls to 'asChild' in page.
  5. remove the MonoLocalBinds pragma.

I considered the possibility that the loop might be cause by asChild calls forming a loop depending on how the types are inferred. However, each call to asChild does a putStrLn. Since there is no output when the loop occurs, I believe that the execution is not even getting that far.

Doing --dump-ds, does show the loop. But I could figure out anything useful from seeing the loop in the desugared code.

The looping seems to occur whether compiled or using GHCi and at all optimization levels.

This bug prevents HSP, and therefore Happstack and SeeReason from moving to GHC 7.

I have attached 3 files. The above file, IdentityT.hs and XMLGenerator.hs. The latter two come from HSP/Happstack, but have been stripped down to the bare essentials.

Trac metadata
Trac field Value
Version 7.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking