Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell gogol - Installed Application Credentials example : Couldn't match kind ‘[Symbol]’ with ‘*’

Tags:

types

haskell

I'm trying the example of installed application credentials in gogol package.

Here is the example(just copied from installed application credentials page):

{-# LANGUAGE ScopedTypeVariables #-}
import Data.Proxy     (Proxy (..))
import Data.Text      as T
import Data.Text.IO   as T
import System.Exit    (exitFailure)
import System.Info    (os)
import System.Process (rawSystem)
redirectPrompt :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> IO (OAuthCode s)
redirectPrompt c p = do
    let url = formURL c p
    T.putStrLn $ "Opening URL " `T.append` url
    _ <- case os of
        "darwin" -> rawSystem "open"     [unpack url]
        "linux"  -> rawSystem "xdg-open" [unpack url]
    _        -> T.putStrLn "Unsupported OS" >> exitFailure
    T.putStrLn "Please input the authorisation code: "
    OAuthCode <$> T.getLine

While I compiled the code, I got the errors as follow:

Illegal kind signature: ‘s’
  Perhaps you intended to use KindSignatures
In the type signature for ‘redirectPrompt’

Illegal kind: ‘[Symbol]’ Perhaps you intended to use DataKinds

so I added these 2 lines in my code:

{-# LANGUAGE KindSignatures    #-}
{-# LANGUAGE DataKinds         #-} 

Then, compiled again. It shows the following error messages:

• Couldn't match kind ‘[Symbol]’ with ‘*’
  When matching the kind of ‘proxy’
• In the second argument of ‘formURL’, namely ‘p’
  In the expression: formURL c p
  In an equation for ‘url’: url = formURL c p
• Relevant bindings include
    p :: proxy s (bound at app/Main.hs:36:18)
    redirectPrompt :: OAuthClient -> proxy s -> IO (OAuthCode s)
      (bound at app/Main.hs:36:1)

I have no idea why it gets wrong.. The p's type looks like as same as formURL require one.

-- https://hackage.haskell.org/package/gogol-0.1.1/docs/Network-Google-Auth.html#v:formURL
formURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> Text

Do I misunderstand something?

Updated

The version I used was lts-7.19. After changing from lts-7.19 to lts-8.0, it works.

The ghc version of lts-7.19 is 8.0.1. The lts-8.0 one is 8.0.2. Here is some notes of ghc-8.0.2-released.

like image 468
R Beckett Avatar asked Feb 12 '17 15:02

R Beckett


1 Answers

Works with lts-8.0 and the right dependencies in .cabal

 build-depends:    base
                 , gogol
                 , gogol-core
                 , process
                 , text

You need {-# LANGUAGE OverloadedStrings #-} and import GHC.TypeLits where Symbol is defined.

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE KindSignatures    #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds         #-}

module Main where

import Network.Google.Auth
import GHC.TypeLits

import Data.Proxy     (Proxy (..))
import Data.Text      as T
import Data.Text.IO   as T
import System.Exit    (exitFailure)
import System.Info    (os)
import System.Process (rawSystem)

redirectPrompt :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> IO (OAuthCode s)
redirectPrompt c p = do
 let url = formURL c p
 T.putStrLn $ "Opening URL " `T.append` url
  _ <- case os of
        "darwin" -> rawSystem "open"     [unpack url]
        "linux"  -> rawSystem "xdg-open" [unpack url]
        _        -> T.putStrLn "Unsupported OS" >> exitFailure
T.putStrLn "Please input the authorisation code: "
OAuthCode <$> T.getLine 

main = print "working"
like image 162
Jonathan Portorreal Avatar answered Sep 18 '22 18:09

Jonathan Portorreal