[Haskell-cafe] overloaded overloading?

Alberto G. Corona agocorona at gmail.com
Tue Jan 12 19:17:17 EST 2010


Hi,

I sometimes strumble on the same quiestion that forces me to insert
functions that process objects of a certain class inside their class
definition.  This occurs when a computation uses the object internally,
neiter as parameter or as a return value or in the case of existential
types. An example of the first:


class Example a where
    irec ::  IO a
    pr :: a →  IO String
    sample2 ::  a  →   IO ()
    sample2 _  =   do
      x ←  irec :: IO a
      pr x
      return ()

sample :: Example a ⇒ a  →   IO ()
sample _  =   do
  x ←  irec :: IO a
  pr x
  return ()


With the flag -fglasgow-exts, the following error below appears in sample.
without the flag, the error appears in both sample and sample2. I´m too lazy
to find what concrete extension is involved and why, anyhow, in the case
of sample, the compiler must generate a new type a1 with no context.

    Could not deduce (Example a1) from the context ()
      arising from a use of `irec' at Control\Workflow\Users.hs:73:7-10
    Possible fix:
      add (Example a1) to the context of an expression type signature
    In a stmt of a 'do' expression: x <- irec :: IO a
    In the expression:
        do x <- irec :: IO a
           pr x
           return ()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100112/949a358e/attachment.html


More information about the Haskell-Cafe mailing list