[Haskell-cafe] New version of itself

Chris Wong lambda.fairy at gmail.com
Mon Jun 6 08:24:27 UTC 2016

On Mon, Jun 6, 2016 at 8:00 PM, martin <martin.drautzburg at web.de> wrote:
> 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.

Hi Martin,

I'm not terribly familiar with machines, but since Mealy is an
Applicative you can try

    (&&) <$> m1 <*> m2

Hope this helps.

> 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.html
>> 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Chris Wong (https://lambda.xyz)

"I had not the vaguest idea what this meant and when I could not
remember the words, my tutor threw the book at my head, which did not
stimulate my intellect in any way." -- Bertrand Russell

More information about the Haskell-Cafe mailing list