Skip to content

[SOLVED] Chapter 6 is mentioning an error which no longer occurs #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
theqp opened this issue Nov 22, 2020 · 1 comment
Open

[SOLVED] Chapter 6 is mentioning an error which no longer occurs #37

theqp opened this issue Nov 22, 2020 · 1 comment

Comments

@theqp
Copy link

theqp commented Nov 22, 2020

In "Chapter 6: Using Type Classes" at "The dreaded monomorphism restriction" it states that the following code results in an error.

myShow = show

But in ghci I get no error

GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
Prelude> myShow = show
Prelude>
@ehamberg
Copy link

@theqp I don't remember the details, but the monomorphism restriction is switched off in GHCi when interactively entering code. You should still get the error if you create a file and load it – like what's done in the book – instead of using GHCi interactively:

$ echo "myShow = show" > Monomorphism.hs
$ ghci
GHCi, version 8.10.1: https://www.haskell.org/ghc/  :? for help
Prelude> :load Monomorphism
[1 of 1] Compiling Main             ( Monomorphism.hs, interpreted )

Monomorphism.hs:1:10: error:
    • Ambiguous type variable ‘a0’ arising from a use of ‘show’
      prevents the constraint ‘(Show a0)’ from being solved.
      Relevant bindings include
        myShow :: a0 -> String (bound at Monomorphism.hs:1:1)
      Probable fix: use a type annotation to specify what ‘a0’ should be.
      These potential instances exist:
        instance Show Ordering -- Defined in ‘GHC.Show’
        instance Show Integer -- Defined in ‘GHC.Show’
        instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
        ...plus 22 others
        ...plus 12 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the expression: show
      In an equation for ‘myShow’: myShow = show
  |
1 | myShow = show
  |          ^^^^

@theqp theqp changed the title Chapter 6 is mentioning an error which no longer occurs [SOLVED] Chapter 6 is mentioning an error which no longer occurs Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants