digitalmars.D - Monads in D
- Atila Neves (25/25) Jun 11 2016 I give you a facsimile of a Haskell do block:
- ArturG (5/10) Jun 11 2016 im not an expert but is it something similar to this idea[1] as
- Atila Neves (4/18) Jun 11 2016 Right, but that's only the Maybe monad. I was trying out monads
- qznc (8/11) Jun 11 2016 I also tried this. Instead of Write and State, I tried to model
- Atila Neves (11/22) Jun 11 2016 I was thinking of doing that as well and was going to model the
- deadalnix (9/34) Jun 11 2016 Honestly, the whole bind/return is just a giant NIH. >>> and >>=
- Max Samukha (2/6) Jun 11 2016 The guy is good.
- Timon Gehr (3/12) Jun 12 2016 I don't see the point of this criticism. Different language makes sense
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (6/8) Jun 12 2016 I think he had a point, but his explanation was harder to follow
- Max Samukha (3/6) Jun 12 2016 Because IO is just one of many applications of the monad concept?
- Timon Gehr (2/7) Jun 12 2016 Most of the tutorials are not actually very good.
- Atila Neves (6/17) Jun 13 2016 That was awesome.
I give you a facsimile of a Haskell do block: with(Maybe!int) { return_(5).bind!(a => return_(a + 1)).shouldEqual(just(6)); nothing.bind!(a => return_(a + 1)).shouldEqual(nothing); return_(8).bind!(a => nothing).bind!(a => return_(a + 1)).shouldEqual(nothing); } with(Maybe!string) { return_("foo").bind!(a => return_(a ~ "bar")).shouldEqual(just("foobar")); nothing.bind!(a => return_(a ~ "bar")).shouldEqual(nothing); return_("foo").bind!(a => return_(a ~ "bar")).bind!(a => nothing).shouldEqual(nothing); } Why? Because I could, I don't plan on using this for anything serious. I think "with" is my favourite D feature right now. I also wrote the Writer and State monads (not that D needs them): https://github.com/atilaneves/felix I tried overloading `>>>` for bind (closest overloadable operator to `>>=`) but it went horribly wrong. I always get problems when I try to pass lambdas as runtime values instead of template parameters. Atila
Jun 11 2016
On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:Why? Because I could, I don't plan on using this for anything serious. I think "with" is my favourite D feature right now. I also wrote the Writer and State monads (not that D needs them): https://github.com/atilaneves/felix Atilaim not an expert but is it something similar to this idea[1] as it seems to be used in a similar way. [1] http://forum.dlang.org/thread/ltalqpmpscdoziserqqx forum.dlang.org
Jun 11 2016
On Saturday, 11 June 2016 at 14:57:11 UTC, ArturG wrote:On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:Right, but that's only the Maybe monad. I was trying out monads in general. AtilaWhy? Because I could, I don't plan on using this for anything serious. I think "with" is my favourite D feature right now. I also wrote the Writer and State monads (not that D needs them): https://github.com/atilaneves/felix Atilaim not an expert but is it something similar to this idea[1] as it seems to be used in a similar way. [1] http://forum.dlang.org/thread/ltalqpmpscdoziserqqx forum.dlang.org
Jun 11 2016
On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:Why? Because I could, I don't plan on using this for anything serious. I think "with" is my favourite D feature right now. I also wrote the Writer and State monads (not that D needs them):I also tried this. Instead of Write and State, I tried to model the Functor > Applicative > Monad > MonadFail type hierarchy. I found no way for a good "template inheritance" construct. Overall, I quickly forgot about it, because it looks ugly and seems to have no advantage. Thinking more conceptually, Monads should be somewhat related to input ranges, as both model a linear sequence.
Jun 11 2016
On Saturday, 11 June 2016 at 16:50:15 UTC, qznc wrote:On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:I was thinking of doing that as well and was going to model the hierarchy like so: alias isFunctor = isInputRange; enum isApplicative(alias T, U...) = isFunctor!T && is(typeof() { ... })); enum isMonad(alias T, U...) = isApplicative!(T, U) && is(typeof(() { ... }));Why? Because I could, I don't plan on using this for anything serious. I think "with" is my favourite D feature right now. I also wrote the Writer and State monads (not that D needs them):I also tried this. Instead of Write and State, I tried to model the Functor > Applicative > Monad > MonadFail type hierarchy. I found no way for a good "template inheritance" construct. Overall, I quickly forgot about it, because it looks ugly and seems to have no advantage.Thinking more conceptually, Monads should be somewhat related to input ranges, as both model a linear sequence.Monads are related to input ranges because every monad is a functor, and input ranges are functors. Atila
Jun 11 2016
On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:I give you a facsimile of a Haskell do block: with(Maybe!int) { return_(5).bind!(a => return_(a + 1)).shouldEqual(just(6)); nothing.bind!(a => return_(a + 1)).shouldEqual(nothing); return_(8).bind!(a => nothing).bind!(a => return_(a + 1)).shouldEqual(nothing); } with(Maybe!string) { return_("foo").bind!(a => return_(a ~ "bar")).shouldEqual(just("foobar")); nothing.bind!(a => return_(a ~ "bar")).shouldEqual(nothing); return_("foo").bind!(a => return_(a ~ "bar")).bind!(a => nothing).shouldEqual(nothing); } Why? Because I could, I don't plan on using this for anything serious. I think "with" is my favourite D feature right now. I also wrote the Writer and State monads (not that D needs them): https://github.com/atilaneves/felix I tried overloading `>>>` for bind (closest overloadable operator to `>>=`) but it went horribly wrong. I always get problems when I try to pass lambdas as runtime values instead of template parameters. AtilaHonestly, the whole bind/return is just a giant NIH. >>> and >>= are its symptoms. There is a reason why nobody understands jack shit about monad even after 10s of tutorial when they aren't even hard in any way: because haskell and alike have made all that is in their power to obfuscate what is a monad. I could go on, but this guy already did it way better that I can: https://www.infoq.com/presentations/functional-pros-cons The part about monad starts 25mins in.
Jun 11 2016
On Saturday, 11 June 2016 at 18:27:19 UTC, deadalnix wrote:I could go on, but this guy already did it way better that I can: https://www.infoq.com/presentations/functional-pros-cons The part about monad starts 25mins in.The guy is good.
Jun 11 2016
On 11.06.2016 20:27, deadalnix wrote:I don't see the point of this criticism. Different language makes sense to different people.Honestly, the whole bind/return is just a giant NIH. >>> and >>= are its symptoms. There is a reason why nobody understands jack shit about monad even after 10s of tutorial when they aren't even hard in any way: because haskell and alike have made all that is in their power to obfuscate what is a monad. I could go on, but this guy already did it way better that I can: https://www.infoq.com/presentations/functional-pros-cons The part about monad starts 25mins in.
Jun 12 2016
On Sunday, 12 June 2016 at 15:33:31 UTC, Timon Gehr wrote:I don't see the point of this criticism. Different language makes sense to different people.I think he had a point, but his explanation was harder to follow than this one: http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/mark.pdf Input world, output modified world... Geez, why doesn't tutorials on Monads say that before they try to explain it with code?
Jun 12 2016
On Sunday, 12 June 2016 at 16:46:13 UTC, Ola Fosheim Grøstad wrote:Input world, output modified world... Geez, why doesn't tutorials on Monads say that before they try to explain it with code?Because IO is just one of many applications of the monad concept?
Jun 12 2016
On 12.06.2016 20:28, Max Samukha wrote:On Sunday, 12 June 2016 at 16:46:13 UTC, Ola Fosheim Grøstad wrote:Most of the tutorials are not actually very good.Input world, output modified world... Geez, why doesn't tutorials on Monads say that before they try to explain it with code?Because IO is just one of many applications of the monad concept?
Jun 12 2016
On Saturday, 11 June 2016 at 18:27:19 UTC, deadalnix wrote:On Saturday, 11 June 2016 at 14:26:20 UTC, Atila Neves wrote:That was awesome. I didn't mean to imply I think monads are great and that `>>=` and `return` are great names. I just wanted to see how far I could take in D. For the lulz. Atila[...]Honestly, the whole bind/return is just a giant NIH. >>> andjack shit about monad even after 10s of tutorial when they aren't even hard in any way: because haskell and alike have made all that is in their power to obfuscate what is a monad. I could go on, but this guy already did it way better that I can: https://www.infoq.com/presentations/functional-pros-cons The part about monad starts 25mins in.[...]
Jun 13 2016