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,349
    • Issues 5,349
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 572
    • Merge requests 572
  • 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
  • #5913
Closed
Open
Issue created Mar 04, 2012 by mnislaih@trac-mnislaih

Type class dictionary call loops at runtime

The following code works fine in 7.0.3 but crashes at runtime with <loop> in 7.2.x and 7.4.1 :

{-# LANGUAGE UndecidableInstances #-}


class         L0 a where l0 :: a -> a
class L0 a => L1 a where l1 :: a -> a
class L1 a => L2 a where l2 :: a -> a


data Worksfine = Worksfine deriving Show
instance                                   L0 Worksfine where l0 = id
instance                                   L1 Worksfine where l1 = l2
instance {- undecidable -} L1 Worksfine => L2 Worksfine where l2 = l0


data WorksfineToo = WorksfineToo deriving Show
instance                                      L0 WorksfineToo where l0 = id
instance {- undecidable -} L2 WorksfineToo => L1 WorksfineToo where l1 = l2
instance {- undecidable -} L1 WorksfineToo => L2 WorksfineToo where l2 = id


-- l1 LoopsAtRuntime = <loop>
-- l2 LoopsAtRuntime = <loop>
data LoopsAtRuntime = LoopsAtRuntime deriving Show
instance                                        L0 LoopsAtRuntime where l0 = id
instance {- undecidable -} L2 LoopsAtRuntime => L1 LoopsAtRuntime where l1 = l2
instance {- undecidable -} L1 LoopsAtRuntime => L2 LoopsAtRuntime where l2 = l0

main = do
  print (l1 WorksfineToo)
  print (l2 WorksfineToo)
  print (l1 LoopsAtRuntime)
  print (l2 LoopsAtRuntime)
Edited Mar 09, 2019 by mnislaih
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking