[Haskell-cafe] Re: Is this related to monomorphism restriction?

Iavor Diatchki iavor.diatchki at gmail.com
Mon Dec 22 20:59:19 EST 2008


Hi,

On Sun, Dec 21, 2008 at 11:45 AM, Luke Palmer <lrpalmer at gmail.com> wrote:
> 2008/12/21 Iavor Diatchki <iavor.diatchki at gmail.com>
>>
>>
>> g :: TestClass a => a -> Integer
>> g = fst (a :: (a -> Integer, a -> Integer))
>
> Which I believe needs to be written:
>
> g :: forall a. TestClass a => a -> Integer
> g = fst (a :: (a -> Integer, a -> Integer))
>

quite right!  sorry for not testing my code.
-iavor


>>
>> Here we are using another GHC extension called "scoped type variables"
>> to associate the "a" in the type signature of "g" with the "a" in the
>> type annotation for the value "a".
>>
>> Hope that this helps,
>> Iavor
>>
>>
>>
>>
>> On Sun, Dec 21, 2008 at 9:21 AM, Maurí­cio <briqueabraque at yahoo.com>
>> wrote:
>> >>> Why isn't the last line of this code allowed?
>> >>> f :: (TestClass a) => a -> Integer
>> >>> f = const 1
>> >>> a = (f,f)
>> >>> g = fst a
>> >>> The only thing I can think about is monomorphism
>> >>> restriction, but it's allowed (...)
>> >
>> >> (...) The reason is that a has type
>> >> a :: (TestClass a, TestClass b) => (a,b)
>> >> and then when we take 'fst' of this value (as in g) we get
>> >
>> >> g :: (TestClass a, TestClass b) => a
>> >> which is an ambiguous type, (...)
>> >
>> > Is there some version (i.e., set of extensions) of
>> > Haskell where this would be allowed?
>> >
>> > _______________________________________________
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe at haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>


More information about the Haskell-Cafe mailing list