[Haskell-cafe] Why does Haskell not infer most general type?
nominolo at googlemail.com
Tue Apr 6 17:18:40 EDT 2010
Yes, it has to do with mutually recursive bindings. If you add a type
signature, you break the mutual recursion. Mutually recursive
functions are type-checked together and then generalised. Similarly,
polymorphic recursion cannot be inferred either, but is possible by
adding a type signature.
On 6 April 2010 20:56, Job Vranish <job.vranish at gmail.com> wrote:
> Is haskell supposed to always infer the most general type (barring
> I found a simple case where this is not true:
> f _ = undefined
> _ = y :: Int -> Int
> y x = undefined
> _ = f x
> Haskell infers the types of 'y' and 'f' as:
> f :: Int -> a
> y :: Int -> Int
> This confused me at first, but after thinking about it a while it seemed to
> make sense. But then my friend John pointed out that you can add type sigs
> for 'f' and 'y':
> f :: a -> b
> y :: a -> b
> and have it still typecheck!
> This thoroughly confused me.
> Why does haskell not infer the most general type for these functions? Is it
> a limitation of the algorithm? a limitation of the recursive let binding?
> Any insight would be appreciated :)
> - Job
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Push the envelope. Watch it bend.
More information about the Haskell-Cafe