4 ms·
Follow-on question, are there any useful monadic constructs not tied to collections (including optional as you said)?
by jbooth 11y ago
Follow-on question, are there any useful monadic constructs not tied to collections (including optional as you said)?
- AdieuToLogic 11y agoFutures are another example.
- jbooth 11y agoI'd call a Future a threadsafe queue with one element going thru it IMO, it's just as much of a collection as Optional.
- AdieuToLogic 11y agoThat's the beautiful thing about types which satisfy the Monad laws. Because both Future and Option (in Scala if not other languages) satisfy these laws, I think it perfectly valid to consider a Future to be collection type with a cardinality of 0 or 1 that also abstracts latency.
- jbooth 11y agoYeah, but I can do that without category theory, it's just obvious. I still don't understand what 'monad' offers over 'flatMappable' besides the ability to use 'endofunctor' in the same sentence.
- dragonwriter 11y ago> I still don't understand what 'monad' offers over 'flatMappable' Its several characters and syllables shorter, and doesn't appeal to an intuition which is distant from many of the productive uses of construct.
- dllthomas 11y agoParsers is an obvious example.
- tel 11y agoSilly and wonderful there is always data Fake a = Fake which is trivially a monad instance Monad Fake where return _ = Fake Fake >>= f = Fake yet it clearly contains nothing.
- efnx 11y agoIs Maybe tied to collections? State? Reader? Cont? What about Eff from extensible-effects? I use these every day.
- dllthomas 11y agoAs mentioned elsewhere here, Maybe is naturally considered a container of zero-or-one elements. The others are good examples, though.
- dragonwriter 11y agoIO, State, Parsers, and STM are useful monads for which the collection metaphor doesn't seem to be particularly helpful.
- jbooth 11y agoSTM's a good one. I'd consider I/O and State as solving a self-inflicted problem -- I can have side-effect-creating I/O and State in just plain C with barely any type system.
- lmm 11y agoFuture, Either, Writer, and Free are the non-collection ones I use most often.