I am trying to invent an embeeded language for measurement instruments. To
do this, I modeled an instrument after the robot language in The Haskell
School of Expression.

For my instrument:

newtype Vi a = Vi (ViState -> (ViState, a))

I have defined:

(||*) :: Vi Bool -> Vi Bool -> Vi Bool
b1 ||* b2 = do
                p <- b1
                if p then return True else b2

However, I also need to create another instrument:

newtype Dvm a = Dvm (DvmState -> (DvmState, a))

I would like to use the (||*) operator for both Dvm and Vi:

vi ||* dvm

In other words, I need to make logical expressions using two different
monads. How do I write the definition of (||*) to take different monads?

Should I make a new class from Monad, say InstrumentMonad, define my state
monads with it, then write:

(||*) :: (InstrumentMonad a) => a Bool -> a Bool -> a Bool
b1 ||* b2 = do
                p <- b1
                if p then return True else b2

Mike




Reply via email to