[Haskell-cafe] Use of uninstantiated type class

Maciej Marcin Piechotka uzytkownik2 at gmail.com
Sat Mar 5 12:46:23 CET 2011


On Sat, 2011-03-05 at 00:51 +0100, Yves Parès wrote:
> 
> 
> But I don't have an explicit type to put.
> I cound do:
> 
> data CtxFooInst
> instance CtxFoo CtxFooInst
> 
> and declare runFoo as this:
> 
> runFoo :: MyIO CtxFooInst a -> IO a
> 
> But I loose the ability to make functions that can run several
> contexts.
> 

He meant:

newtype MyIO c a = MyIO (IO a)

data CtxFooInst
instance CtxFoo CtxFooInst

runMyIO :: CtxFoo c => MyIO c a -> IO a
runMyIO (MyIO x) = x

someAction :: CtxFoo c => MyIO c ()
someAction = MyIO (PutStrLn "Foo")

main = runMyIO (someAction :: MyIO CtxFooInst ())

In such way you push the abstraction down to main but actions are
contex-independent.

Regards





More information about the Haskell-Cafe mailing list