gpt4 book ai didi

haskell gogol - 已安装的应用程序凭据示例 : Couldn't match kind ‘[Symbol]’ with ‘*’

转载 作者:行者123 更新时间:2023-12-04 18:59:10 24 4
gpt4 key购买 nike

我正在尝试 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 是 8.0.2。
以下是 ghc-8.0.2-released 的一些笔记.

最佳答案

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"

关于haskell gogol - 已安装的应用程序凭据示例 : Couldn't match kind ‘[Symbol]’ with ‘*’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42189666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com