#1897: Ambiguous types and rejected  type signatures
----------------------------------------+-----------------------------------
    Reporter:  guest                    |        Owner:  chak       
        Type:  bug                      |       Status:  reopened   
    Priority:  normal                   |    Milestone:  6.10 branch
   Component:  Compiler (Type checker)  |      Version:  6.9        
    Severity:  normal                   |   Resolution:             
    Keywords:                           |   Difficulty:  Unknown    
    Testcase:                           |           Os:  Linux      
Architecture:  x86                      |  
----------------------------------------+-----------------------------------
Changes (by simonpj):

  * summary:  Type families: type signature rejected => Ambiguous types and
              rejected  type signatures

Old description:

> 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  ([email protected])

New description:

 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  ([email protected])

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1897#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to