ekmett / machines

Networks of composable stream transducers
Other
339 stars 46 forks source link

Added instance Distributive (Moore a) #72

Closed mitchellwrosen closed 8 years ago

ekmett commented 8 years ago

Interesting. This is effectively using it as a representable functor, represented by a list of inputs.

mitchellwrosen commented 8 years ago

Interesting? I stole the idea and implementation from your comment about Cofree! :)

acowley commented 8 years ago

This is how @ekmett compliments himself.

ekmett commented 8 years ago

Amusingly, I realized after the fact that I'd already written the more general statement elsewhere. I just hadn't really considered the consequences here.

Note: Mealy is also distributive (it is represented by a NonEmpty a).

ekmett commented 8 years ago

(and both should be instances of the profunctor equivalents as well)

mitchellwrosen commented 8 years ago

For the categorically uninclined who happen upon this ticket, can you clarify what you mean by

using Moore as a representable functor, represented by a list of inputs

My understanding is you're saying there's an isomorphism

to :: Moore a b -> ([a] -> b)
to (Moore b _) [] = b
to (Moore _ f) (x:xs) = to (f x) xs

from :: ([a] -> b) -> Moore a b
from f = Moore (f []) (\a -> from (\as -> f (a:as)))

but I don't see what it has to do with this Distributive instance.

ekmett commented 8 years ago

The short version is this: Every distributive functor is representable, Distributive is constrained by Haskell 98 though to not actually tell you what the representation is.

treeowl commented 8 years ago

Can this be made an instance of Representable? On Dec 2, 2015 1:59 AM, "Edward Kmett" notifications@github.com wrote:

The short version is this: Every distributive functor is representable, Distributive is constrained by Haskell 98 though to not actually tell you what the representation is.

— Reply to this email directly or view it on GitHub https://github.com/ekmett/machines/pull/72#issuecomment-161202252.

ekmett commented 8 years ago

Since this pull request I've already gone ahead and done so in HEAD.