Ticket #1897 (closed bug: fixed)
Ambiguous types and rejected type signatures
| Reported by: | guest | Owned by: | chak |
|---|---|---|---|
| Priority: | low | Milestone: | 7.2.1 |
| Component: | Compiler (Type checker) | Version: | 6.9 |
| Keywords: | Cc: | andres@…, dsf@…, hackage.haskell.org@… | |
| Operating System: | Linux | Architecture: | x86 |
| Type of failure: | None/Unknown | Difficulty: | Unknown |
| Test Case: | typecheck/should_compile/T1897a, indexed_types/should_compile/T1897b | Blocked By: | |
| Blocking: | #5296 | Related Tickets: |
Description (last modified by simonpj) (diff)
This ticket collects a bunch of examples where GHC
- Rejects a function with a type signature but, if the type signature is removed, accepts the function and infers precisely the type that was originally specified.
- Accepts type signatures that are utterly ambiguous; that is, the function could never be called, or only in the presence of bizarre instance declarations.
- Rejects definitions that clearly have a unique typing.
Original example: the following programm does not compile:
{-# LANGUAGE TypeFamilies #-}
import Control.Monad
import Data.Maybe
class Bug s where
type Depend s
next :: s -> Depend s -> Maybe s
start :: s
isValid :: (Bug s) => [Depend s] -> Bool
isValid ds = isJust $ foldM next start ds
Error:
GHCi, version 6.9.20071105: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( GHC-Bug.hs, interpreted )
Bug.hs:13:39:
Couldn't match expected type `Depend a'
against inferred type `Depend s'
Expected type: [Depend a]
Inferred type: [Depend s]
In the third argument of `foldM', namely `ds'
In the second argument of `($)', namely `foldM next start ds'
Failed, modules loaded: none.
When one elides the type signature the program compiles yielding the offending signature:
Prelude> :r [1 of 1] Compiling Main ( GHC-Bug.hs, interpreted ) Ok, modules loaded: Main. *Main> :t isValid isValid :: (Bug a) => [Depend a] -> Bool
Compiler version: 6.9.20071105
Best regards,
Harald Holtmann (haskell@…)
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

