Giter VIP home page Giter VIP logo

Comments (4)

hlian avatar hlian commented on July 17, 2024

@ggranberry try this!

(False,  m) -> do
  anEither <- say m config
  case anEither of
    Left e -> putStrLn ("an error occurred! " <> show e)
    Right _ -> return ""

The problem here is that typeclasses generate bad errors :(

You should think of say as having type IO (Either RequestError ()), which uses the typeclass instance MonadError e (Either e). The reason the very generic mtl type exists is that you can use it in deeper monad stacks where perhaps there are more layers between the IO and the Either RequestError.

Your code is forcing GHC to infer say m config as IO a. Now IO does have a MonadError instance, except it's MonadError IOException -- the weird mismatch between IOException and RequestError is what's causing the problem here.

Hope that makes sense. Keep me updated! Thanks for using the library.

from linklater.

ggranberry avatar ggranberry commented on July 17, 2024

@hlian Thanks for the quick and detailed reply! Your comment was incredibly helpful and I'm mostly seeing why it is breaking right now. Though some of the some of the mtl type stuff was a bit above me as this is my first attempt at a small Haskell project.

I went ahead and tried to implement your suggestion and got the same error as before with a few extra ones added. It looks like say isn't being evaluated as IO (Either RequestError ()) from what I'm seeing.

/Users/ranberry/haskell/scraper/src/Notification/SlackBot.hs:38:19: error:
     Couldn't match type IOException
                     with Network.Linklater.Types.RequestError
        arising from a functional dependency between:
          constraint mtl-2.2.1:Control.Monad.Error.Class.MonadError
                        Network.Linklater.Types.RequestError IO
            arising from a use of say
          instance mtl-2.2.1:Control.Monad.Error.Class.MonadError
                      IOException IO
            at <no location info>
     In a stmt of a 'do' block: anEither <- say m config
      In the expression:
        do { anEither <- say m config;
             case anEither of {
               Left e -> putStrLn ("an error occurred! " <> show e)
               Right _ -> return "" } }
      In a case alternative:
          (False, m)
            -> do { anEither <- say m config;
                    case anEither of {
                      Left e -> putStrLn ("an error occurred! " <> show e)
                      Right _ -> return "" } }

/Users/ranberry/haskell/scraper/src/Notification/SlackBot.hs:40:9: error:
     Couldn't match expected type () with actual type Either a0 t0
     In the pattern: Left e
      In a case alternative:
          Left e -> putStrLn ("an error occurred! " <> show e)
      In a stmt of a 'do' block:
        case anEither of {
          Left e -> putStrLn ("an error occurred! " <> show e)
          Right _ -> return "" }

/Users/ranberry/haskell/scraper/src/Notification/SlackBot.hs:40:19: error:
     Couldn't match type () with T.Text
      Expected type: IO T.Text
        Actual type: IO ()
     In the expression: putStrLn ("an error occurred! " <> show e)
      In a case alternative:
          Left e -> putStrLn ("an error occurred! " <> show e)
      In a stmt of a 'do' block:
        case anEither of {
          Left e -> putStrLn ("an error occurred! " <> show e)
          Right _ -> return "" }

/Users/ranberry/haskell/scraper/src/Notification/SlackBot.hs:41:9: error:
     Couldn't match expected type () with actual type Either t1 t2
     In the pattern: Right _
      In a case alternative: Right _ -> return ""
      In a stmt of a 'do' block:
        case anEither of {
          Left e -> putStrLn ("an error occurred! " <> show e)
          Right _ -> return "" }```

from linklater.

hlian avatar hlian commented on July 17, 2024

@ggranberry silly me! i was missing a runExceptT call. i updated JPEGbot to illustrate the solution:

https://github.com/hlian/linklater/blob/master/examples/app/JointPhotographicExpertsGroupTonga.hs#L62

from linklater.

ggranberry avatar ggranberry commented on July 17, 2024

@hlian That did the trick, thanks!!

from linklater.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.