From 8e5b862c9171af8af7c6c0d0456ae67a9e737633 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 27 Aug 2017 00:40:55 +0200 Subject: privmsgFromPlugin: Rewrite using MaybeT monad transformer OMG it works!!! This took me a week of off-and-on tinkering, learning, procrastinating, and struggling. So awesome that it's finally working! The `liftMaybe` was key, learned that from: https://stackoverflow.com/questions/8684252/how-to-inject-a-maybe-value-into-maybet This article on monad transformers by 'kqr' also helped quite a bit: https://github.com/kqr/gists/blob/master/articles/gentle-introduction-monad-transformers.md A Wikibooks article on the same was somewhat useful: https://en.wikibooks.org/wiki/Haskell/Monad_transformers And this was an interesting look at Alternatives, which I didn't end up using but was interesting nonetheless: http://www.parsonsmatt.org/2016/11/18/clean_alternatives_with_maybet.html When I learned about monad transformers I thought: "Yes! This is what I need to clean up the `privmsgFromPlugin` function.". I wasn't liking the nested `case` statements there, and since everything was a `Maybe`, I thought, why can't we chain the `Maybe`s like we're supposed to be able to with monads? Well, turns out we can. It just involved a lot of tricky `lift`ing. This gets rid of the nesting, resulting in a much cleaner- looking function. So cool! --- sorbot.cabal | 1 + 1 file changed, 1 insertion(+) (limited to 'sorbot.cabal') diff --git a/sorbot.cabal b/sorbot.cabal index 69bc228..6761349 100644 --- a/sorbot.cabal +++ b/sorbot.cabal @@ -35,6 +35,7 @@ library , sqlite-simple , text , text-show + , transformers default-language: Haskell2010 executable sorbot-exe -- cgit v1.2.3