Re:Swift Functors, Applicatives, and Monads in Pictures
by jbooth on Tuesday July 14, 2015 @10:53PM
(#9889457)
Follow-on question, are there any useful monadic constructs not tied to collections (including optional as you said)?
[ Parent
| on HN ]
Re:Swift Functors, Applicatives, and Monads in Pictures
by dragonwriter on Wednesday July 15, 2015 @02:04AM
(#9889939)
IO, State, Parsers, and STM are useful monads for which the collection metaphor doesn't seem to be particularly helpful.
Re:Swift Functors, Applicatives, and Monads in Pictures
by jbooth on Wednesday July 15, 2015 @11:12AM
(#9891679)
STM'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.
Re:Swift Functors, Applicatives, and Monads in Pictures
by efnx on Wednesday July 15, 2015 @12:56AM
(#9889794)
Is Maybe tied to collections? State? Reader? Cont?
What about Eff from extensible-effects? I use these every day.
Re:Swift Functors, Applicatives, and Monads in Pictures
by dllthomas on Wednesday July 15, 2015 @03:03AM
(#9890091)
As mentioned elsewhere here, Maybe is naturally considered a container of zero-or-one elements. The others are good examples, though.
Re:Swift Functors, Applicatives, and Monads in Pictures
by dllthomas on Tuesday July 14, 2015 @11:02PM
(#9889482)
Parsers is an obvious example.
Re:Swift Functors, Applicatives, and Monads in Pictures
by lmm on Wednesday July 15, 2015 @06:34AM
(#9890592)
Future, Either, Writer, and Free are the non-collection ones I use most often.
Re:Swift Functors, Applicatives, and Monads in Pictures
by tel on Tuesday July 14, 2015 @11:06PM
(#9889494)
Silly 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.
Re:Swift Functors, Applicatives, and Monads in Pictures
by lmm on Wednesday July 15, 2015 @12:03PM
(#9892062)
Grandparent asked for useful though :P
Re:Swift Functors, Applicatives, and Monads in Pictures
by tel on Wednesday July 15, 2015 @03:39PM
(#9893579)
Who says Fake isn't useful? It's very useful for stating that nothing can happen :)
Re:Swift Functors, Applicatives, and Monads in Pictures
by AdieuToLogic on Tuesday July 14, 2015 @11:09PM
(#9889507)
Futures are another example.
Re:Swift Functors, Applicatives, and Monads in Pictures
by jbooth on Wednesday July 15, 2015 @12:06PM
(#9892074)
I'd call a Future a threadsafe queue with one element going thru it IMO, it's just as much of a collection as Optional.
Re:Swift Functors, Applicatives, and Monads in Pictures
by AdieuToLogic on Wednesday July 15, 2015 @01:28PM
(#9892713)
That'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.
Re:Swift Functors, Applicatives, and Monads in Pictures
by jbooth on Wednesday July 15, 2015 @03:02PM
(#9893345)
Yeah, 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.
Re:Swift Functors, Applicatives, and Monads in Pictures
by dragonwriter on Wednesday July 15, 2015 @03:07PM
(#9893366)
> 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.