我有一个字符串列表,errors。我做了一些检查,如果有任何失败,我会在后面附加一条消息errors。像这样:
let errors = []
let errors' = errors ++ if (check1 fails) then ["check1 failed"] else []
let errors'' = errors' ++ if (check2 fails) then ["check2 failed"] else []
Run Code Online (Sandbox Code Playgroud)
当然,还有一种更惯用的方式来累积更改,errors而不必每次都生成新变量。我需要Data.IORef突显可变变量吗?似乎过分杀伤力。
如果仅删除撇号,则编译器将返回错误,因为它陷入了无限循环。
我正在尝试使用库的长度函数streaming-bytestring Data.ByteString.Streaming.Char8。
我看到返回值的类型为Of,但不清楚如何检查它。我试过使用case,但Not in scope: data constructor ‘O.Of’即使我对进行了合格的导入,编译器也会说Data.Functor.Of。
如何检查价值?
代码示例:
ghci> let bs = BSSC.string "tiger"
ghci> bs
Chunk "tiger" (Empty (()))
ghci> BSSC.length bs
6 :> ()
ghci> let len = BSSC.length bs
ghci> :t len
len :: Monad m => m (OO.Of Int ())
Run Code Online (Sandbox Code Playgroud) 我想换一个Data.Sequence在我自己newtype为了隐藏不必要的功能。
MyQueue.hs(省略了某些部分):
00 import Data.Sequence
10 newtype MyQueue a = Seq a
23 empty :: MyQueue a
24 empty = Data.Sequence.empty
Run Code Online (Sandbox Code Playgroud)
我收到以下错误。看来我无法返回Seq类型并将其作为我自己的类型传递。但是,如何将自己的函数映射到Data.Sequence中的函数?
MyQueue.hs:24:9: error:
• Couldn't match expected type ‘MyQueue a’
with actual type ‘Seq a4’
• In the expression: Data.Sequence.empty
In an equation for ‘empty’: empty = Data.Sequence.empty
• Relevant bindings include
empty :: MyQueue a (bound at MyQueue.hs:24:1)
Run Code Online (Sandbox Code Playgroud) 我正在编写一种使用该Range.setBackground(color)方法为Google电子表格中的单元格着色的脚本。我想使用一种预设的填充颜色,但是我很难找到确切的颜色代码。十六进制,RGB,我只想要一个正式列表。