tekul / jose-jwt

Haskell implementation of JOSE/JWT standards
BSD 3-Clause "New" or "Revised" License
35 stars 22 forks source link

Example in README.md does not work #17

Closed tomoyat1 closed 7 years ago

tomoyat1 commented 7 years ago
Configuring GHCi with the following packages: 
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /tmp/ghci24350/ghci-script
Prelude> import Jose.Jws
Prelude Jose.Jws> import Jose.Jwa
Prelude Jose.Jws Jose.Jwa> hmacEncode HS384 "somehmackey" "my JSON message"

<interactive>:3:18: error:
    • Couldn't match expected type ‘Data.ByteString.Internal.ByteString’
                  with actual type ‘[Char]’
    • In the second argument of ‘hmacEncode’, namely ‘"somehmackey"’
      In the expression: hmacEncode HS384 "somehmackey" "my JSON message"                       In an equation for ‘it’:                                                                      it = hmacEncode HS384 "somehmackey" "my JSON message"

<interactive>:3:32: error:
    • Couldn't match expected type ‘Data.ByteString.Internal.ByteString’
                  with actual type ‘[Char]’
    • In the third argument of ‘hmacEncode’, namely ‘"my JSON message"’
      In the expression: hmacEncode HS384 "somehmackey" "my JSON message"
      In an equation for ‘it’:
          it = hmacEncode HS384 "somehmackey" "my JSON message"

I get a type error for the two "strings" I pass to hmacEncode. Am I doing something wrong, or is the documentation old?

tomoyat1 commented 7 years ago

I needed to enable OverloadedStrings to make it work. Perhaps a line like

:set -XOverloadedStrings

before the first import would make the example more friendly to newcomers? (I'm quite new to the language)

tekul commented 7 years ago

Good idea. I always use OverloadedStrings in ghci, so I don't really think about it. I added it to make things clearer.