小编Ale*_*lov的帖子

如何使用镜头列表?

我可以使用Traversal列表吗?以下代码:

f::[Int] -> [[Int]]
f l = [l & i .~ 1 |  i<-[ix 0], (l^? i) == Just 0]
Run Code Online (Sandbox Code Playgroud)

产生错误:

  • Couldn't match type ‘Const (Data.Monoid.First Int) [Int]’
                     with ‘Identity [Int]’
      Expected type: ASetter [Int] [Int] Int Integer
        Actual type: Getting (Data.Monoid.First Int) [Int] Int
    • In the first argument of ‘(.~)’, namely ‘i’
      In the second argument of ‘(&)’, namely ‘i .~ 1’
      In the expression: l & i .~ 1
Run Code Online (Sandbox Code Playgroud)

看看这个问题,我想我需要以某种方式明确地给我一个类型,但我的每一次尝试都失败了.

haskell traversal haskell-lens

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

标签 统计

haskell ×1

haskell-lens ×1

traversal ×1