Ticket #3700 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

Being instance of Monoid is not checked

Reported by: boris Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 6.10.3
Keywords: Monoid, Writer Cc:
Operating System: Windows Architecture: x86
Type of failure: Other Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

It is possible pass not only instances of Monoid to tell function and load the file with GHCi. GHCi shows type f :: (MonadWriter? ((a -> b) -> [a] -> [b]) m) => t -> m ()

f _ = tell map

However, if code is

f = tell map

GHCi shows type error(no instance) as expected.

It seems very strange that type correctness depends on number of parameters for function that is not used anywhere.

Change History

Changed 3 years ago by rwbarton

I don't think this is a bug. GHCi should accept the first declaration because later (say in another module) someone might define an instance Monoid ((a -> b) -> [a] -> [b]) and then want to call the function f. The second declaration is rejected due to the monomorphism restriction: since f is not defined via a function binding, GHCi must choose a monomorphic type for f immediately and it has no way to satisfy the Monoid instance. If you turn off the monomorphism restriction by entering :set -XNoMonomorphismRestriction, you will find that both definitions are accepted.

Changed 3 years ago by boris

  • status changed from new to closed
  • resolution set to invalid
Note: See TracTickets for help on using tickets.