
Since `Mealy a` is an instance of `Applicative` you can do:
(&&) <$> m1 <*> m2
It's also a monad, so do notation would also work.
Erik
On 6 June 2016 at 10:00, martin
Carl,
thanks for pointing me towards mealy machines.
Maybe you can help me with this one: I am trying to compose two mealy machines into one. Suppose I have
m1 :: Mealy a Bool m2 :: Mealy a Bool
now I want a combinded mealy machine which outputs True when both m1 and m2 return True and False otherwise. I can write this using runMealy. But this looks awkward, because it is a bare-bones implementation and doesn't make use of any of the typeclasses Mealy is a member of. I.e. the machines package is basically not used at all.
Am 06/04/2016 um 07:10 PM schrieb Carl Howells:
That's basically a Mealy machine. See https://hackage.haskell.org/package/machines-0.6/docs/Data-Machine-Mealy.htm...
newtype Logger a l = Logger (Mealy (a, Log l) (Log l))
Not quite an exact isomorphism since (,) is lifted, but it's close.
You're not actually doing anything weird there. That's a pretty standard functional representation of a state machine.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe