Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cochoice instance for Mealy #98

Open
shachaf opened this issue Mar 21, 2018 · 4 comments
Open

Cochoice instance for Mealy #98

shachaf opened this issue Mar 21, 2018 · 4 comments

Comments

@shachaf
Copy link
Collaborator

shachaf commented Mar 21, 2018

Retracing some paths in Process Algebra defines a trace/feedback operator for Mealy machines that connects an output back to an input. This is like ArrowLoop but with a sum instead of a product. It can be implemented like this:

trace :: forall e a b. Mealy (Either e a) (Either e b) -> Mealy a b
trace m0 = Mealy $ \x -> go m0 (Right x)
  where
    go :: Mealy (Either e a) (Either e b) -> Either e a -> (b, Mealy a b)
    go (Mealy f) x = case f x of
      (Left e, m) -> go m (Left e)
      (Right y, m) -> (y, trace m)

Maybe this would be useful for other machines as well.

@shachaf
Copy link
Collaborator Author

shachaf commented Mar 21, 2018

Oh, this would be a Cochoice instance. Which it looks like Mealy doesn't have. Probably worth adding.

@shachaf shachaf changed the title Define trace/feedback operator Cochoice instance for Mealy Mar 28, 2018
@ekmett
Copy link
Owner

ekmett commented Apr 2, 2018

Did we finally find a use for Cochoice?

@ekmett
Copy link
Owner

ekmett commented Apr 2, 2018

That is a rather sensible instance even.

@ekmett
Copy link
Owner

ekmett commented Apr 2, 2018

Ah, it's the (->) instance in disguise if you view Mealy a b, morally as a [a] -> b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants