Monads get fmap
from Functor
typeclass. Why comonads don't need a cofmap
method defined in a Cofunctor
class?
相关问题
- Understanding do notation for simple Reader monad:
- Making Custom Instances of PersistBackend
- Haskell: What is the differrence between `Num [a]
- applying a list to an entered function to check fo
- Haskell split a list into two by a pivot value
相关文章
- Is it possible to write pattern-matched functions
- Haskell underscore vs. explicit variable
- Top-level expression evaluation at compile time
- Stuck in the State Monad
- foldr vs foldr1 usage in Haskell
- List of checkboxes with digestive-functors
- Const and non-const functors
- How does this list comprehension over the inits of
Functor
is defined as:Cofunctor
could be defined as follows:So, both are technically the same, and that's why
Cofunctor
does not exist. "The dual concept of 'functor in general' is still 'functor in general'".Since
Functor
andCofunctor
are the same, both monads and comonads are defined by usingFunctor
. But don't let that make you think that monads and comonads are the same thing, they're not.A monad is defined (simplifying) as:
whether a comonad (again, simplified) is:
Note the "symmetry".
Another thing is a contravariant functor, defined as:
Actually, you're wrong: there is one!
https://hackage.haskell.org/package/acme-cofunctor
For reference,
Note that given
extract
andextend
you can producefmap
andduplicate
, and that givenreturn
and>>=
you can producefmap
,pure
,<*>
, andjoin
. So we can focus on justpure
+>>=
andextract
+extend
.I imagine you might be looking for something like
Since the
Monad
class makes it easy to "put things in" while only allowing a sort of hypothetical approach to "taking things out", andComonad
does something opposed to that, your request initially sounds sensible. However, there is a significant asymmetry between>>=
andextend
that will get in the way of any attempt to defineunmap
. Note in particular that the first argument of>>=
has typem a
. The second argument ofextend
has typew a
—nota
.