[Haskell-cafe] type inference question
Lennart Augustsson
lennart at augustsson.net
Thu Oct 8 12:10:21 EDT 2009
Indeed, the types
foo :: forall a . (Num a) => a -> (Int, Float)
and
foo :: (forall a . (Num a) => a) -> (Int, Float)
are quite different.
The first one say, I (foo) can handle any kind of numeric 'a' you (the
caller) can pick. You (the caller) get to choose exactly what type you
give me.
The second one says, I (foo) require you (the caller) to give me an
numeric 'a' that I can use any way I want. You (the caller) don't get
to choose what type you give me, you have to give me a polymorphic
one.
-- Lennart
On Thu, Oct 8, 2009 at 5:35 PM, Bulat Ziganshin
<bulat.ziganshin at gmail.com> wrote:
> Hello Cristiano,
>
> Thursday, October 8, 2009, 7:14:20 PM, you wrote:
>
>> Could you explain why, under NoMonomorphismRestriction, this typechecks:
>
>> let a = 1 in (a + (1 :: Int),a + (1 :: Float))
>
>> while this not:
>
>> foo :: Num a => a -> (Int,Float)
>> foo k = (k + (1 :: Int), k + (1.0 :: Float))
>
> i think it's because type is different:
>
> foo :: (forall a. (Num a) => a) -> (Int,Float)
>
> in first equation it probably inferred correctly
>
>
>
> --
> Best regards,
> Bulat mailto:Bulat.Ziganshin at gmail.com
>
More information about the Haskell-Cafe
mailing list