From ae6949327ed8bd8cfa528da7741333274203af44 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 11 Sep 2017 00:53:30 +0200 Subject: gitHubCommit: Fix type error Oh my goodness, it works!!!!!!! I've been wrestling with this for the past week and a half, and it finally works! Here's the compiler error I was getting: sorbot/src/Plugin/GitHubCommit.hs:25:12: error: • Couldn't match type ‘Control.Monad.Trans.Reader.ReaderT r0 m1’ with ‘Bot’ Expected type: Bot t0 Actual type: Control.Monad.Trans.Reader.ReaderT r0 m1 t0 • In a stmt of a 'do' block: cfg <- asks language In the expression: do { cfg <- asks language; return (defaultPlugin {matchRegex = "^[0-9a-f]{40}$", perform = gitHubCommitAction, command = "", description = translate (lang cfg) GitHubCommitDescription}) } In an equation for ‘gitHubCommit’: gitHubCommit = do { cfg <- asks language; return (defaultPlugin {matchRegex = "^[0-9a-f]{40}$", perform = gitHubCommitAction, command = "", description = translate (lang cfg) GitHubCommitDescription}) } The problem ended up being that I was using the wrong `ask` & `asks` functions. After a lot of searching online and reading articles and things about how to set up `ReaderT` configuration, I finally started looking at some code, from a "language:Haskell newtype app readert" search on GitHub. Reading different code bits, I tried to compare with what I had already, kept reading. Finally I noticed that the imports were different, and I tried getting `ask` not from the transformer library, and it worked!! OMG! So glad. --- src/Plugin/GitHubCommit.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs index a1e5ce4..335c664 100644 --- a/src/Plugin/GitHubCommit.hs +++ b/src/Plugin/GitHubCommit.hs @@ -7,7 +7,8 @@ module Plugin.GitHubCommit import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Class (lift) -import Control.Monad.Trans.Reader (ask, asks) +-- import Control.Monad.Trans.Reader (ask, asks) +import Control.Monad.Reader (ask, asks) import qualified Data.Text as T import Database.SQLite.Simple @@ -47,7 +48,7 @@ gitHubCommitAction message = do respond rs where - respond :: Bot (Either T.Text T.Text) + respond :: [RepoUrlRow] -> Bot (Either T.Text T.Text) respond [] = do cfg <- ask -- lang <- Cli.lang -- cgit v1.2.3