小编W. *_*ins的帖子

无法将预期类型"Int"与实际类型"m0 Int"匹配

我目前正在努力学习Haskell.以下功能:

findPivot :: [[Double]] -> Int
findPivot matrixA =
    do
        let firstCol = (transpose(matrixA)!!0)
        let maxColValue = maximum firstCol
        let pivotIndex = elemIndex maxColValue firstCol
        return (fromJust(pivotIndex))
Run Code Online (Sandbox Code Playgroud)

应该采用表示矩阵的二维2D列表,并确定哪一行在第一列中具有最大值.我知道有一些低效的部分,例如使用列表来表示矩阵和使用转置,但我遇到的问题涉及以下编译器错误:

Couldn't match expected type `Int' with actual type `m0 Int'
In the return type of a call of `return'
In a stmt of a 'do' block: return (fromJust (pivotIndex))
In the expression:
  do { let firstCol = (transpose (matrixA) !! 0);
       let maxColValue = maximum firstCol;
       let pivotIndex = elemIndex maxColValue firstCol; …
Run Code Online (Sandbox Code Playgroud)

haskell types compiler-errors maybe

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

标签 统计

compiler-errors ×1

haskell ×1

maybe ×1

types ×1