[Haskell-cafe] Limits of deduction

Christopher L Conway cconway at cs.nyu.edu
Mon May 14 09:40:52 EDT 2007


On 5/14/07, Roberto Zunino <zunino at di.unipi.it> wrote:
> Also, using only rank-1:
>
> polyf :: Int -> a -> Int
> polyf x y = if x==0 then 0
>              else if x==1 then polyf (x-1) (\z->z)
>              else polyf (x-2) 3
>
> Here passing both 3 and (\z->z) as y confuses the type inference.

Actually, I tried this in ghci... Should this work?

polyf.hs:
polyf x y = if x==0 then 0
            else if x==1 then polyf (x-1) (\z->z)
            else polyf (x-2) 3

NOTE: no type signature

Prelude> :l polyf
[1 of 1] Compiling Main             ( polyf.hs, interpreted )
Ok, modules loaded: Main.
*Main> :t polyf
polyf :: forall a t1 t.
(Num (t1 -> t1), Num a, Num t) =>
a -> (t1 -> t1) -> t

The inference assigns y the type (t1 -> t1) even though it is assigned
the value 3?

Regards,
Chris


More information about the Haskell-Cafe mailing list