[Haskell-cafe] Why does Haskell not infer most general type?

Job Vranish 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?

- Job

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
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100406/58c471b5/attachment.html


More information about the Haskell-Cafe mailing list