Consider the code below : <div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>{-# LANGUAGE MultiParamTypeClasses,FlexibleInstances,FunctionalDependencies,UndecidableInstances,FlexibleContexts #-}</div>
</div><div><div>class Foo a c | a -> c</div></div><div><div>instance Foo Int Float </div></div><div><div>f :: (Foo Int a) => Int -> a </div></div><div><div>f = undefined</div></div><div><br></div></blockquote>Now when I see the inferred type of f in ghci </div>
<div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>> :t f</div></blockquote></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>> f :: Int -> Float</div><div><br></div>
</blockquote>Now If I add the following code </div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>g :: Int -> Float </div><div>g = undefined </div><div><br></div><div>h :: (Foo Int a) => Int -> a </div>
<div>h = g</div></div></blockquote><div><br></div>I get the error </div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>Could not deduce (a ~ Float)</div></blockquote><div><br></div><div>I am not able to understand what has happened here ? The restriction "Foo Int a" should have restricted the type of h to "Int -> Float" as shown in the inferred type of f.</div>
<br clear="all"><div><br></div>- Satvik
</div>