[Haskell-cafe] Automatically infer Newtype instance

adam vogt vogt.adam at gmail.com
Wed Apr 9 19:24:58 UTC 2014

On Wed, Apr 9, 2014 at 2:06 PM, Alexander Solla <alex.solla at gmail.com> wrote:
>> instance (Newtype a b, Newtype b c) => Newtype a c where
>>   pack = (pack :: b -> c)
>>            . (pack :: a -> b)
>> Did I get those types right?  They look free to me.
> Actually, I'm not sure if that will work. How will GHC know which b to
> choose for the pair a and c, unless there are functional dependencies on a
> and c?

Hi Alex,

If there was no fundep on Newtype, that 'b' could also be inferred
when the 'a' is actually Int, and we have an instance:

instance (b ~ Key) => Newtype Int b

You tend to need many type annotations when you have types that look
like they are ambiguous but turn out to be unambiguous because of your
particular instances: https://ghc.haskell.org/trac/ghc/ticket/8477


More information about the Haskell-Cafe mailing list