Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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 4,825
    • Issues 4,825
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 448
    • Merge requests 448
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #4875

Closed
Open
Created Jan 01, 2011 by Stef Joosten@trac-Stef_Joosten

ghc misdiagnoses a compile time error concerning parameterized types

Please find the script HaskellBug.hs at the bottom of this message. Here is how to reproduce the behaviour in two steps.

Step 1: verify that Module HaskellBug produces the following error message:

[1 of 1] Compiling HaskellBug       ( HaskellBug.hs, interpreted )

HaskellBug.hs:12:22:
    `rel' is not applied to enough type arguments
    Expected kind `??', but `rel' has kind `* -> *'
    In the type `rel -> concept'
    In the class declaration for `Association'

Step 2: remove the definition of class Morphic r c and verify that the script is now error free.

You have now reproduced the symptoms.

Assessment: In this situation, ghc has diagnosed an error in the definition of class Association. This error was resolved by removing another definition, without altering the definition of class Association. This proves that the definition of class Association was correct in the first place. Therefore, ghc has made a mistake. It has diagnosed the error in the wrong location. I whould have expected an error message like

HaskellBug.hs:23:22:
    `r' is applied to too many type arguments
    Expected <something sensible here>
    In the type `r -> c'
    In the class declaration for `Morphic'

Epilog: I have taken the trouble to isolate the problem in a small script, because this error has caused serious havoc in a large Haskell project. Students, who were still learning about parameterized types, have systematically been 'fixing' the wrong code, because ghc has never pointed in the direction of the real error. In the end, they were unable to resolve their mistake. Besides haarvesting a frustrating experience with parameterized types, wasting two entire days before giving up, they have turned a large script upside down and introduced many more mistakes. That is why I think it is important to get this fixed.

Here is the script:

{-# OPTIONS  -XMultiParamTypeClasses  -XFunctionalDependencies -XFlexibleInstances #-}
module HaskellBug where

  data Relation c -- The basic Relation
     = Rel { relnm :: String -- The name of the relation
           , relsrc :: c -- Source concept
           , reltrg :: c -- ^Target concept
           }
       deriving Eq

  class (Eq concept)=> Association rel concept | rel -> concept where
    source, target :: rel -> concept      -- e.g. Declaration Concept -> Concept
    sign  :: rel -> (concept,concept)
    sign x = (source x,target x) 
    homogeneous :: rel -> Bool
    homogeneous s = source s == target s

  instance (Eq c)=>Association (Relation c) c where
    source = relsrc
    target = reltrg
    
  class (Eq c, Association r c) => Morphic r c where
    multiplicities :: r c -> [c]
    multiplicities _ = []
Edited Mar 09, 2019 by Ian Lynagh <igloo@earth.li>
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking