Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,322
    • Issues 4,322
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 368
    • Merge Requests 368
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #1090

Closed
Open
Opened Jan 08, 2007 by kirsten@trac-kirsten

Bad monomorphism-restriction-related type error message

Consider the following program:

module Small2 where

printFormatted :: IO ()
printFormatted = 
  let myPrint :: (a -> String) -> a -> IO ()
      myPrint f s = putStr (f s)
    --  myShow :: Show a => a -> IO ()
      myShow = myPrint show in
            myShow 1 >> myShow "foo"

If I compile this I get:

> ghc --make -no-recomp -c small2.hs 

[1 of 1] Compiling Small2           ( small2.hs, small2.o )

small2.hs:9:19:
    No instance for (Num [Char])
      arising from the literal `1' at small2.hs:9:19
    Possible fix: add an instance declaration for (Num [Char])
    In the first argument of `myShow', namely `1'
    In the first argument of `(>>)', namely `myShow 1'
    In the expression:
	let
	  myPrint :: (a -> String) -> a -> IO ()
	  myPrint f s = putStr (f s)
	  myShow = myPrint show
	in (myShow 1) >> (myShow "foo")

The fix, of course, is to either add -fno-monomorphism-restriction or to uncomment the type signature for myShow, but it took me a while to figure that out. It would be much better if the error message would suggest adding a type signature for myShow. As it is, the suggestion to add an instance for Num [Char] is none too helpful.

Trac metadata
Trac field Value
Version 6.6
Type Bug
TypeOfFailure OtherFailure
Priority lowest
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Multiple
Architecture Multiple
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#1090