[Haskell-cafe] New version of itself

Erik Hesselink hesselink at gmail.com
Mon Jun 6 08:20:45 UTC 2016


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 <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.
>
>
>
> 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


More information about the Haskell-Cafe mailing list