我正在尝试installed application credentials的例子 在gogol package。
以下是示例(仅从已安装的应用程序凭据页面复制):
{-# 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
当我编译代码时,我得到的错误如下:
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
所以我在我的代码中添加了这两行:
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
然后,再次编译。它显示以下错误消息:
• 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)
我不知道为什么会出错。p
的类型与formURL
的类型相同。
-- https://hackage.haskell.org/package/gogol-0.1.1/docs/Network-Google-Auth.html#v:formURL
formURL :: AllowScopes (s :: [Symbol]) => OAuthClient -> proxy s -> Text
我误解了什么吗?
更新
我使用的版本是lts-7.19。 从lts-7.19更改为lts-8.0后,它可以正常工作。
lts-7.19的ghc版本是8.0.1。 lts-8.0 one是8.0.2。 以下是ghc-8.0.2-released的一些注释。
答案 0 :(得分:4)
使用lts-8.0
和.cabal
build-depends: base
, gogol
, gogol-core
, process
, text
您需要{-# LANGUAGE OverloadedStrings #-}
和import GHC.TypeLits
,其中Symbol
已定义。
{-# 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"