小编qub*_*tal的帖子

在where子句中键入签名

我写了一个类似的函数,Data.Enumerator.List.mapIterateeEnumerator一个不同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.

haskell enumerator parametric-polymorphism

13
推荐指数
2
解决办法
2285
查看次数

将ByteString转换为Int的最佳方法是什么?

尝试读取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)

haskell bytestring

9
推荐指数
2
解决办法
7056
查看次数

是否有必要在类声明的类上下文中指定每个超类?

ArrowListhxt包中的类具有以下声明:

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...?

haskell

7
推荐指数
1
解决办法
247
查看次数

如何使用YASnippet在代码段中展开代码段?

YASnippet网站上,我注意到以下描述yas/triggers-in-field:

如果非零,则yas/next-field-key可以触发堆叠扩展,这是另一个代码段扩展内的代码片段扩展.否则, yas/next-field-key只是尝试继续下一个字段.

我不清楚如何实现这一目标.

我假设在设置之后:#expand-env: ((yas/triggers-in-field #t))每当我在字段中键入一个缩写并按下Tab它时它会扩展,但事实并非如此.

emacs code-snippets yasnippet

7
推荐指数
1
解决办法
1564
查看次数

如何在Emacs(noX)中调整左边距?

目前,文本正好在终端窗口的左边缘,这有点令人讨厌.我希望有一个小的边距,没有行号或视线.我知道边缘,但边缘模式似乎只在GUI版本中工作.理想情况下,我希望根据窗口大小动态调整边距,使特定宽度的文本主体居中,然后正确填充.

emacs

5
推荐指数
1
解决办法
3652
查看次数

是(map f)== concatMap(map f.(:[]))?

我为类定义了流函数(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)

haskell arrows

4
推荐指数
1
解决办法
290
查看次数