[Haskell-cafe] Dealing with incoherent instances
coffeemug at gmail.com
Wed Dec 27 10:10:53 EST 2006
Ah, so the moment something is passed through a polymorphic function
its type information is lost... This seems like a bug in the
specification/implementation, no? This is most certainly not the
desired behavior. It seems like the compiler has all the information
it needs but still can't select the right instance.
Are there ways to get around this problem?
On 12/27/06, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> 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