[Haskell-cafe] overloaded overloading?
Brad Larsen
brad.larsen at gmail.com
Tue Jan 12 19:25:00 EST 2010
Alberto,
On Tue, Jan 12, 2010 at 7:17 PM, Alberto G. Corona <agocorona at gmail.com> wrote:
> 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 ()
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
In the code for `sample', you give a type signature to x, `IO a'.
However, the `a' there is different from the `a' in the signature for
`sample'.
Perhaps ScopedTypeVariables
<http://www.haskell.org/haskellwiki/ScopedTypeVariables> will help?
Sincerely,
Brad
More information about the Haskell-Cafe
mailing list