[Haskell-cafe] Why does Haskell not infer most general type?
job.vranish at gmail.com
Tue Apr 6 17:18:34 EDT 2010
So in Haskell 98, would the added constraints result in a type error?
On Tue, Apr 6, 2010 at 5:12 PM, Ross Paterson <ross at soi.city.ac.uk> wrote:
> On Tue, Apr 06, 2010 at 03:56:32PM -0400, Job Vranish wrote:
> > f _ = undefined
> > where
> > _ = y :: Int -> Int
> > y x = undefined
> > where
> > _ = f x
> Because f and y are mutually recursive, their types are inferred together,
> so y gets the type Int -> Int (as given), which forces f :: Int -> a.
> If you add the type signature f :: a -> b, you break the cycle: that
> type is used in inferring the type of y (namely a -> b), which is then
> used in checking the typeof f. Ditto if you add y :: a -> b instead.
> (This is not Haskell 98, but the implementations have done this for
> years, and it will be in Haskell 2010.)
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe