conal / total-map

Finitely represented /total/ maps
Other
15 stars 6 forks source link

added Comonad instance. #9

Closed wygulmage closed 6 years ago

wygulmage commented 6 years ago

You'll probably want to check my work, so I left it in there.

Sorry about the messy diff; my editor deleted some trailing whitespace.

conal commented 6 years ago

Thanks for the pull request. I don't think this instance could satisfy my basic requirement, namely that the semantic function is a Comonad homomorphism. I've not played with Comonad homomorphisms, but I think they'd be defined as follows for a function h:

extract w == extract (h w)

h (fmap h (duplicate w)) == duplicate (h w)

Equivalently,

extract == extract . h

h . fmap h . duplicate == duplicate . h

In our case, h = (!) (the "semantic function").

Such homomorphisms prevent abstraction leaks and guarantee that the class laws hold, as described in my TCM paper and talk.

wygulmage commented 6 years ago

Thanks, Conal; when I'm sure I have something that follows the denotational semantics, I'll make another pull request.

wygulmage commented 6 years ago

If I understand what you're saying, the new instance should preserve (!) as a homomorphism to the Control.Comonad instance for functions by treating mempty as a left- and right-'identity key'.

wygulmage commented 6 years ago

Would it be worth including fmap . (!) for semigroupoid composition of maps?

conal commented 6 years ago

Great idea!