4 ms·
I was hoping for a few concrete examples of where comonads can be useful. I have found the need for monads fairly often in my code but I've never found any reas
by laureny 13y ago
I was hoping for a few concrete examples of where comonads can be useful. I have found the need for monads fairly often in my code but I've never found any reason to use a comonad.
- brandonbloom 13y agoInductive data types are defined by how they are constructed, while coinductive types are defined by how they are deconstructed (or observed). It's object instantiation vs field destructuring/patten matching. Turns out that OOP and protocols give you uniform deconstruction of objects (like destructuring first/rest from a sequence). Co-monads are basically objects!
- danidiaz 13y agoThis link offers three examples: http://www.haskellforall.com/2013/02/you-could-have-invented-comonads.html http://www.haskellforall.com/2013/02/you-could-have-invented... (altough I find the object analogy to be unhelpful.) I think the more striking example is the first: "builders" with a default starting value form a comonad, which is the dual of the Writer monad. A Haskell implementation can be found in package 'comonad-transformers' as the 'Traced' comonad. Infinite streams also form a comonad ('Data.Stream.Infinite' from the 'streams' package).