Weirdsli category - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Asad Saeeduddin

What laws do I need for Distributive to make the Category instance below lawful?

data Weirdsli w m a b = Weirdsli { runWeirdsli :: w a -> m b }

class Distributive f g
  distribute :: f (g a) -> g (f a)

instance (Comonad w, Monad m, Distributive w m) => Category (Weirdsli w m)
  id = Weirdsli $ pure . extract
  Weirdsli f . Weirdsli g = Weirdsli $ (>>= f) . distribute . (g <<=)

The last one can probably be simplified, but here's what I have

    distribute (fmap_w pure x) = pure x.

    fmap_m extract (distribute u) = extract u.

    ((distribute . (g <<=)) =<< distribute (f <<= x))
    distribute (((g =<<) . distribute) <<= (f <<= x))
GitHub Gist: instantly share code, notes, and snippets.

Code-golfing the last one:

(=<<) (distribute . (<<=) g) . distribute
distribute ((<<=) ((=<<) g . distribute))
Asad Saeeduddin

hmm, very interesting. so the first two are distribute . fmap pure = pure and fmap extract . distribute = extract

Asad Saeeduddin

diagrammatically that's like:

WρW11ηWMΔMWW \xrightarrow{\rho} W \odot 1 \xrightarrow{1 \odot \eta} W \odot M \xrightarrow{\Delta} M \odot W

Wλ1Wη1MWW \xrightarrow{\lambda} 1 \odot W \xrightarrow{\eta \odot 1} M \odot W

it's frustratingly close to something like a bimonoid, but it's not quite that

Sandy Maguire

how did you make this diagram

Asad Saeeduddin

you can just write:

1 + 1 = 2

and get:

1+1=21 + 1 = 2

Asad Saeeduddin

btw you can look at the source for anyone's comments, there's a little menu on the right


This is really cool! (Especially the source view feature!) Thanks!

Sridhar Ratnakumar

Someone post this in fpslack :-P