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
  where
  distribute :: f (g a) -> g (f a)

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

The last one can probably be simplified, but here's what I have https://gist.github.com/Lysxia/0f6ef064af8dbf2f39f518d12b77531b

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

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:

```math
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

Hazem

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

Sridhar Ratnakumar

Someone post this in fpslack :-P