In Rohan's hosc package we currently have

class Transport t where
    send :: t -> OSC -> IO ()
    recv :: t -> IO OSC
    close :: t -> IO ()

The problem is, that all methods are bound to IO,
although it would be nice to run a SuperCollider program also offline
and only get a command stream file which can be sent to scsynth in 
non-realtime mode.

Recently I stumpled about nearly the same issue in the HTTP package.
There I had an idea, which can be applied to hosc, too:

class Monad m => Transporter m where
    send :: OSC -> m ()
    recv :: m OSC
    close :: m ()

instance (Transport t, MonadIO io) => Transporter (ReaderT t io) where
    send osc = ask >>= \t -> lift (liftIO (Transport.send t osc))
    ...

data Offline a = Offline (Writer ByteString a)

instance Transporter Offline where
    send osc = Offline (tell osc)
    ...


Then you can write your code in terms of Transporter monads.
You may add other class constraints, which provide say timing functions.
You can use combined monads, which allow control of both SuperCollider and 
some graphics engine, by using multiple class constraints.
This abstraction would also allow to write unit tests without IO access.

How about that?
_______________________________________________
haskell-art mailing list
[email protected]
http://lists.lurk.org/mailman/listinfo/haskell-art

Reply via email to