#5248: Infer type context in a type signature
----------------------------------------+-----------------------------------
Reporter: gidyn | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler (Type checker) | Version: 7.0.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: GHC rejects valid
program
----------------------------------------+-----------------------------------
Old description:
> If I have code such as
>
> {{{
> class Foo f where
> foo :: a -> f a
>
> data Bar f a = Foo f => Bar {bar :: f a}
>
> instance Foo (Bar f) where
> foo a = Bar (foo a)
> }}}
>
> GHC will demand Foo f => on the instance declaration, even though this
> can be inferred from the definition of Bar.
>
> I understand ''why'' this is happening, but it should not be necessary to
> repeat information already given. Some code violates DRY dozens of times
> because of this limitation.
New description:
If I have code such as
{{{
class Foo f where
foo :: a -> f a
data Bar f a = Foo f => Bar {bar :: f a}
instance Foo (Bar f) where
foo a = Bar (foo a)
}}}
GHC will demand `Foo f =>` on the instance declaration, even though this
can be inferred from the definition of Bar.
I understand ''why'' this is happening, but it should not be necessary to
repeat information already given. Some code violates DRY dozens of times
because of this limitation.
--
Comment(by simonpj):
I'm sorry but that's the way Haskell is. You could imagine some form like
{{{
instance (...) => Foo (Bar f) where
foo a = ...
}}}
meaning "please infer the context for me". This would be useful for type
signatures more generally. For example:
{{{
f :: (...) => [a] -> String
f xs = show (sum xs)
}}}
Here the full type signature would be
{{{
f :: (Num a, Show a) => [a] -> String
}}}
This has come up before but I can't find a ticket for it, so I'll treat
this as it.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5248#comment:1>
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