Closed heilkn closed 4 years ago
A list is a perfect example of monoid and functor for example. Or optional of monoid as well. As for the unit - yeah, I already got a negative comment about that :) and it is me being a bit lazy. I need to move it out from functor to pointed functor or applicative.
For the coroutines - we'll see how they would be adopted. In their core they are too much of a "something that can go wrong", but I hope that cppcoro (or something similar) would become a gold standard and it would allow to use c++ coroutines without fear to shoot yourself in the foot. For async monadic behavior though I'm kinda ok with my another project - asynqro, that provides monadic Futures (with API similar to one you could find in Scala) and custom task scheduler that uses them. It is already being used in couple of proprietary projects and seems so far so good last I check with them.
I see now what you mean. Still, list is not a monoid but a functor which assigns any type "a" a new type "[a]" that is a monoid.
One last comment optional is not a monoid. It lacks the binary operation.
Could you care to elaborate please? Both Haskell and Scala.Cats provide monoid instances for lists and for optionals of monoids (For Scala AFAIR it is for optional of semigroup, but it doesn't really matter in this case).
List (or std::vector/std::list to be more precise) has both mappend (concatenation) and mempty (empty list). It follows monoid laws. Why it is not a monoid then?
The same is for optional of monoids (cefal instantiates monoid only for that case of course).
Hi, sorry for not answering so long. I am a little nitpicky on the definition here. Since list is a functor, it is an arrow between categories. Monoids on the other side are objects of a category. This why I said list and monoids are of different kind. On the other hand, every concrete instances of a list is indeed a monoid.
Kind regards
Konstantin
You are definitely right about concrete instances of the list. But in C++ you can't have just a std::vector, you need to instantiate this type with some inner type, i.e. make it concrete instance of std::vector. So, in this case by saying that we have monoid instance for vector - we are saying of course that we are having it for each instance of vector, not for templated class itself
Hello,
this project is a very nice idea. Thank you for sharing.
I have read the readme file and was left wondering about your definition of functor. What is unit and which laws does it obey. Furthermore, I am asking myself how a type can satisfy functor+monoid. You mentioned this in the from optional conversion. I am asking, because the kind of functor is -> and that of monoid is *.
Kind regards
Konstantin
Ps, since you like functional programming. Try coroutines. You can implement some monadic bindings with it. However, a general monad seems to be not possible. At least I found no way to clone the state of a coroutine. This would be required to invoke the continuation more than one time as for the list monad for example.