我写了一个类似的函数,Data.Enumerator.List.map
它Iteratee
与Enumerator
一个不同Stream
类型的函数兼容.
import Data.Enumerator
test :: Monad m => (ao -> ai) -> Iteratee ai m b -> Iteratee ao m b
test f iter = go $$ iter
where go (Continue k) = continue $
\stream -> go $$ k (fmap f stream)
go (Yield res _) = yield res EOF
Run Code Online (Sandbox Code Playgroud)
如果我省略了类型签名go
,这将工作得很好.但是,我想包括它,但我无法确定正确的签名应该是什么.这是我认为它应该是:
go :: Monad m => Step ai m b -> Iteratee ao m b
但这不起作用.
我需要一些关于找到正确类型签名的建议go
.
尝试读取ByteString时,我总是遇到以下错误:
Prelude.read: no parse
以下是在浏览器中呈现时会导致此错误的代码示例:
factSplice :: SnapletSplice App App
factSplice = do
mbstr <- getParam "input" -- returns user input as bytestring
let str = maybe (error "splice") show mbstr
let n = read str :: Int
return [X.TextNode $ T.pack $ show $ product [1..n]]
Run Code Online (Sandbox Code Playgroud)
或者更简单:
simple bs = read (show bs) :: Int
Run Code Online (Sandbox Code Playgroud)
出于某种原因,在show bs
结果字符串包含引号之后.所以为了绕过错误我必须删除引号然后read
它.我使用从互联网复制的以下功能来执行此操作:
sq :: String -> String
sq s@[c] = s
sq ('"':s) | last s == '"' = init …
Run Code Online (Sandbox Code Playgroud) ArrowList
hxt包中的类具有以下声明:
class (Arrow a, ArrowPlus a, ArrowZero a, ArrowApply a) => ArrowList a where
...
在ArrowPlus
类被声明为:
class ArrowZero a => ArrowPlus a where
...
在ArrowZero
类被声明为:
class Arrow a => ArrowZero a where
...
该ArrowApply
课程被宣布为:
class Arrow a => ArrowApply a where
......
为什么它不能写成:
class (ArrowPlus a, ArrowApply a) => ArrowList a where
...?
在YASnippet网站上,我注意到以下描述yas/triggers-in-field
:
如果非零,则
yas/next-field-key
可以触发堆叠扩展,这是另一个代码段扩展内的代码片段扩展.否则,yas/next-field-key
只是尝试继续下一个字段.
我不清楚如何实现这一目标.
我假设在设置之后:#expand-env: ((yas/triggers-in-field #t))
每当我在字段中键入一个缩写并按下Tab它时它会扩展,但事实并非如此.
目前,文本正好在终端窗口的左边缘,这有点令人讨厌.我希望有一个小的边距,没有行号或视线.我知道边缘,但边缘模式似乎只在GUI版本中工作.理想情况下,我希望根据窗口大小动态调整边距,使特定宽度的文本主体居中,然后正确填充.
我为类定义了流函数(SF)的left
/ right
方法,ArrowChoice
如下所示:
newtype SF a b = SF { runSF :: [a] -> [b] }
instance ArrowChoice SF where
left (SF f) =
SF $ map (either (\x -> Left . head $ f [x]) Right)
right (SF f) =
SF $ map (either Left (\x -> Right . head $ f [x]))
Run Code Online (Sandbox Code Playgroud)
ghci中的一些测试看起来好像一切都很好:
?> let lst = [Left 'c', Right 2, Left 'a', Right 3, Left 't']
?> let foo = SF $ map …
Run Code Online (Sandbox Code Playgroud)