[Haskell-cafe] Functional Dependencies and multiparametertypeclasses

Harald ROTTER harald.rotter at sagem.com
Mon Aug 24 07:51:03 EDT 2009


Thanks for the quick response. Your explanation is so much clearer than
ghc's error messages :-))

Harald.


|---------+------------------------------>
|         |           Miguel Mitrofanov  |
|         |           <miguelimo38 at yandex|
|         |           .ru>               |
|         |                              |
|         |                              |
|         |           24.08.2009 13:29   |
|         |           Delivered date:    |
|         |           24.08.2009 13:31   |
|         |                              |
|---------+------------------------------>
  >------------------------------------------------------------------------------------------------------------|
  |                                                                                                            |
  |     To:       Harald ROTTER <harald.rotter at sagem.com>                                                      |
  |     cc:       haskell-cafe at haskell.org                                                                     |
  |     Subject:  Re: [Haskell-cafe] Functional Dependencies and multiparameter     typeclasses                |
  >------------------------------------------------------------------------------------------------------------|




> However, I do not really understand the cause of the original problem.
Why
> do I need the functional dependency to make this work ?

Suppose you have an instance:

instance Pixel MyPixel where...
instance Image MyImage MyPixel where
   width i = countPixels i
   ...

And somebody (not necessarily you) makes another instance:

instance Pixel CustomPixel where...
instance Image MyImage CustomPixel where
   width i = 0
   ...

Now, take any image

im :: MyImage

Then you'd expect that

width im :: Int

But now there are TWO implementations of "width :: MyImage -> Int" and
no way for compiler to figure out which one to use.

GHC sort of foresees this problem. By adding a functional dependency you
instruct it to forbid the second declaration, when the first one is
present, thus removing the problem.





" Ce courriel et les documents qui y sont attaches peuvent contenir des informations confidentielles. Si vous n'etes  pas le destinataire escompte, merci d'en informer l'expediteur immediatement et de detruire ce courriel  ainsi que tous les documents attaches de votre systeme informatique. Toute divulgation, distribution ou copie du present courriel et des documents attaches sans autorisation prealable de son emetteur est interdite." 

" This e-mail and any attached documents may contain confidential or proprietary information. If you are not the intended recipient, please advise the sender immediately and delete this e-mail and all attached documents from your computer system. Any unauthorised disclosure, distribution or copying hereof is prohibited."


More information about the Haskell-Cafe mailing list