Skip to main content
4 of 4
deleted 22 characters in body
Ben Sprott
  • 1.3k
  • 14
  • 23

What is the (Co)Monad for a Bag

A Bag is a data structure, like a list, that stores items with no concept of order. The only operations on the structure is to add an item and then iterate through the items with no guarantee as to the order of iteration. We see it in Sedgewick's Algorithms book. I am guessing this is a monad since it is very much like the list monad. What is the Monad for the bag? Is it a Comonad?

A more technical and mathematical definition for a bag would be a set with finite multiplicities. What is the monad for that? Is that functor also a comonad with suitable natural transformations?

Ben Sprott
  • 1.3k
  • 14
  • 23