0

I am working inside a sandbox with ghc 7.10.3 and I have this simple code:

main :: IO ()
main = do
  args <- getArgs
  case args of
    [ newOauthConsumerKey, newOauthConsumerSecret ] -> do
      let appOauth = newOAuth { oauthServerName       = "api.twitter.com"
                              , oauthConsumerKey    = newOauthConsumerKey
                              , oauthConsumerSecret = newOauthConsumerSecret
                              }
  ... 

when I compile it with these dependencies in my cabal file:

base
, authenticate-oauth
, http-conduit
, aeson
, text

I keep on get (after cleaning and rebuilding the sandbox) the following errors:

src/Test/Main.hs:60:55:
    Couldn't match type ‘[Char]’
                   with ‘bytestring-0.10.6.0:Data.ByteString.Internal.ByteString’
    Expected type: bytestring-0.10.6.0:Data.ByteString.Internal.ByteString
      Actual type: String
    In the ‘oauthConsumerKey’ field of a record
    In the expression:
      newOAuth
        {oauthServerName = "api.twitter.com",
         oauthConsumerKey = newOauthConsumerKey,
         oauthConsumerSecret = newOauthConsumerSecret}

src/Test/Main.hs:61:55:
    Couldn't match type ‘[Char]’
                   with ‘bytestring-0.10.6.0:Data.ByteString.Internal.ByteString’
    Expected type: bytestring-0.10.6.0:Data.ByteString.Internal.ByteString
      Actual type: String
    In the ‘oauthConsumerSecret’ field of a record
    In the expression:
      newOAuth
        {oauthServerName = "api.twitter.com",
         oauthConsumerKey = newOauthConsumerKey,
         oauthConsumerSecret = newOauthConsumerSecret}

I have already googled and checked different similar answers but I cannot make it work. Any idea?

Solution

The problem was due to the fact that in the code there was an import for import Data.Text that includes a pack which is different from the pack required for Data.ByteString.Char8. Once I have included it, it worked.

Randomize
  • 8,651
  • 18
  • 78
  • 133

1 Answers1

3

The fields oauthConsumerKey and oauthConsumerSecret are supposed to contain ByteStrings and not Strings which is what getArgs returns. You need to use pack to convert your newOauthConsumer* values.

gallais
  • 11,823
  • 2
  • 30
  • 63
  • I have already tried it and it didn't work (forgot to write it the question). If you use a hardcoded string inside the newOAuth it will work. – Randomize Dec 21 '15 at 19:18