[Haskell-cafe] How Type inference work in presence of Functional Dependencies

satvik chauhan mystic.satvik at gmail.com
Thu Sep 13 11:18:24 CEST 2012


Consider the code below :

{-# LANGUAGE
MultiParamTypeClasses,FlexibleInstances,FunctionalDependencies,UndecidableInstances,FlexibleContexts
 #-}
class Foo a c | a -> c
instance Foo Int Float
f :: (Foo Int a) => Int -> a
f = undefined

Now when I see the inferred type of f in ghci

> :t f

> f :: Int -> Float

Now If I add the following code

g :: Int -> Float
g = undefined

h :: (Foo Int a) => Int -> a
h = g


I get the error

Could not deduce (a ~ Float)


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.


- Satvik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120913/3b85fec7/attachment.htm>


More information about the Haskell-Cafe mailing list