我正在尝试用 Haskell Servant 复制这个curl 请求
curl -v -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Client-ID: someapikey' \
-X GET 'https://api.twitch.tv/kraken/clips/top?game=Overwatch&period=week&trending=false&limit=3'
Run Code Online (Sandbox Code Playgroud)
使用 Twitch API。文档在这里
这就是我到目前为止所得到的
type Game = Text
type Cursor = Text
type Language = Text
type Limit = Int
type Period = Text
type Trending = Bool
type Application = Text
type ClientID = Text
type SearchClips = "kraken"
:> "clips"
:> "top"
:> QueryParam "game" Game
:> QueryParam "cursor" Cursor
:> QueryParam "language" Language
:> QueryParam "limit" Limit
:> …Run Code Online (Sandbox Code Playgroud) 如果foldl给出一个函数(+)和一个列表,[1..10]它将生成一个最终数字.
我想要的是什么
[1,2,3,4,5,6,7,8,9,10]
Run Code Online (Sandbox Code Playgroud)
输出将是三角数系列.
但给出一个像这样的清单
[3, 5, 1, 4, 7, 8, 10]
Run Code Online (Sandbox Code Playgroud)
输出将是
[3, 8, 9, 13, 20, 28, 38]
Run Code Online (Sandbox Code Playgroud)
我这样做的方法是使用生成一个新列表
sum (take x) list
x当前指数在哪里
并将其附加到新列表.
有没有更好的方法呢?
我正在hspec做一些基本的测试。
我有一个argsParser给定一些参数的函数,返回或更确切地说打印其有效性。
argsParser :: [String] -> IO ()
argsParser args | null args = print "no args provided"
| not $ null args && length args < 2 = print "no file name provided"
| length args > 2 == print "too many arguments"
| otherwise = goAhead args
Run Code Online (Sandbox Code Playgroud)
问题是我不确定如何IO ()与另一个进行比较IO ()。
我以为可能liftIO会有所帮助
x <- liftIO $ print "something"
y <- liftIO $ print "anything"
Run Code Online (Sandbox Code Playgroud)
我懂了
x == y = …Run Code Online (Sandbox Code Playgroud)