[Haskell-cafe] Dealing with incoherent instances
Bulat Ziganshin
bulat.ziganshin at gmail.com
Wed Dec 27 09:37:58 EST 2006
Hello Vyacheslav,
Wednesday, December 27, 2006, 5:29:37 PM, you wrote:
> If I enable incoherent instances GHC always picks the general case
> which seems like the wrong thing to do. What I want it to do is delay
> comitting to an instance until it's processing a specific invocation
> of a polymorphic function. All the information is available at compile
> time but I found no way to do this.
are you seen http://haskell.org/haskellwiki/OOP_vs_type_classes ?
it contains example where compiler choose general instance just because
function calling polymorhic code don't get full dictionary of type. smth
like this:
class F a where
f :: a -> Int
instance (Num a) => F a
...
instance F Int
...
g :: (Num a) => a -> a
g x = f x
main = print (g (1::Int))
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list