Couldn't match expected type `Int' with actual type `m0 Int'

W. K. Hudgins

I am currently struggling to learn Haskell. The following function:

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

Is supposed to take a 2D-list of doubles, representing a matrix, and determine which row has the maximum value in the first column. I know there are some inefficient parts, for example using a list for represent the matrix and using transpose, but the problem I am encountering involves the following compiler error:

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;
       return (fromJust (pivotIndex)) }

I'm not sure what the m0 means but I assume it means monadic. So, I think this means that the function is returning a monadic int. Any help in understanding this problem and how to solve it would be immensely appreciated.

Thanks.

jamshidh

do and return are related to monads. When you use them, you tell the compiler that you intend to use monads.

Your function type is non-monadic. This tells the compiler that you do not intend to use monads. The compiler is just warning you of this discrepancy.

You can use let outside of do, but the sytax is a bit different

findPivot matrixA = 
            let 
                firstCol = (transpose(matrixA)!!0)
                maxColValue = maximum firstCol
                pivotIndex = elemIndex maxColValue firstCol
            in fromJust(pivotIndex)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Couldn't match expected type `Int' with actual type [Int]

From Dev

Couldn't match expected type `Int' with actual type [Int]

From Dev

Couldn't match expected type `()' with actual type `Int'

From Dev

Couldn't match expected type `()' with actual type `Int'

From Dev

Couldn't match expected type ‘(Int, Int)’ with actual type ‘[t0]’

From Dev

Couldn't match expected type `IO ()' with actual type `a0 -> m0 a0'

From Dev

Couldn't match expected type `IO ()' with actual type `a0 -> m0 a0'

From Dev

Couldn't match expected type `Maybe (String, Int, String)' with actual type `([Char], t0, [Char])'

From Dev

Couldn't match expected type `Maybe (String, Int, String)' with actual type `([Char], t0, [Char])'

From Dev

Haskell Couldn't match expected type ‘[(Char, b0)]’ with actual type ‘(Char, Int)’

From Dev

gtk2hs: Couldn't match expected type ‘IO [Int]’ with actual type ‘[Int]’

From Dev

How to convert (Integer, Int, Int ) to Day. Couldn't match expected type ‘Day’ with actual type ‘(Integer, Int, Int)’

From Dev

Couldn't match expected type with actual type

From Dev

Couldn't match expected type ‘[a]’ with actual type ‘a’

From Dev

Haskell "Couldn't match expected type ‘a’ with actual type ‘[a0]’"

From Dev

error Couldn't match expected type ‘Char’ with actual type ‘[Char]’

From Dev

Couldn't match expected type ‘r’ with actual type ‘Horse’

From Dev

Couldn't match expected type ‘a’ with actual type ‘Double’:

From Dev

Haskell 'Couldn't match expected type with actual type'

From Dev

Couldn't match expected type `a` with actual type `Integer`

From Dev

why it shows this error: Couldn't match expected type `[a]' with actual type `a'?

From Dev

Couldn't match expected type ‘Post’ with actual type ‘Route App’

From Dev

Couldn't match type `float' with `Int'

From Dev

Haskell powerset function - How to avoid Couldn't match expected type `IO t0' with actual type `[[Integer]]'

From Dev

Haskell powerset function - How to avoid Couldn't match expected type `IO t0' with actual type `[[Integer]]'

From Dev

"Couldn't match type `Maybe' with `IO' Expected type: IO String Actual type: Maybe String" In Haskell

From Dev

"Couldn't match type `Maybe' with `IO' Expected type: IO String Actual type: Maybe String" In Haskell

From Dev

Couldn't match expected type 'Control.Monad.Trans.Reader.ReaderT MongoContext IO a0' with actual type 'IO ()'

From Dev

Haskell readFile: Couldn't match expected type ‘[String]’ with actual type ‘IO String’

Related Related

  1. 1

    Couldn't match expected type `Int' with actual type [Int]

  2. 2

    Couldn't match expected type `Int' with actual type [Int]

  3. 3

    Couldn't match expected type `()' with actual type `Int'

  4. 4

    Couldn't match expected type `()' with actual type `Int'

  5. 5

    Couldn't match expected type ‘(Int, Int)’ with actual type ‘[t0]’

  6. 6

    Couldn't match expected type `IO ()' with actual type `a0 -> m0 a0'

  7. 7

    Couldn't match expected type `IO ()' with actual type `a0 -> m0 a0'

  8. 8

    Couldn't match expected type `Maybe (String, Int, String)' with actual type `([Char], t0, [Char])'

  9. 9

    Couldn't match expected type `Maybe (String, Int, String)' with actual type `([Char], t0, [Char])'

  10. 10

    Haskell Couldn't match expected type ‘[(Char, b0)]’ with actual type ‘(Char, Int)’

  11. 11

    gtk2hs: Couldn't match expected type ‘IO [Int]’ with actual type ‘[Int]’

  12. 12

    How to convert (Integer, Int, Int ) to Day. Couldn't match expected type ‘Day’ with actual type ‘(Integer, Int, Int)’

  13. 13

    Couldn't match expected type with actual type

  14. 14

    Couldn't match expected type ‘[a]’ with actual type ‘a’

  15. 15

    Haskell "Couldn't match expected type ‘a’ with actual type ‘[a0]’"

  16. 16

    error Couldn't match expected type ‘Char’ with actual type ‘[Char]’

  17. 17

    Couldn't match expected type ‘r’ with actual type ‘Horse’

  18. 18

    Couldn't match expected type ‘a’ with actual type ‘Double’:

  19. 19

    Haskell 'Couldn't match expected type with actual type'

  20. 20

    Couldn't match expected type `a` with actual type `Integer`

  21. 21

    why it shows this error: Couldn't match expected type `[a]' with actual type `a'?

  22. 22

    Couldn't match expected type ‘Post’ with actual type ‘Route App’

  23. 23

    Couldn't match type `float' with `Int'

  24. 24

    Haskell powerset function - How to avoid Couldn't match expected type `IO t0' with actual type `[[Integer]]'

  25. 25

    Haskell powerset function - How to avoid Couldn't match expected type `IO t0' with actual type `[[Integer]]'

  26. 26

    "Couldn't match type `Maybe' with `IO' Expected type: IO String Actual type: Maybe String" In Haskell

  27. 27

    "Couldn't match type `Maybe' with `IO' Expected type: IO String Actual type: Maybe String" In Haskell

  28. 28

    Couldn't match expected type 'Control.Monad.Trans.Reader.ReaderT MongoContext IO a0' with actual type 'IO ()'

  29. 29

    Haskell readFile: Couldn't match expected type ‘[String]’ with actual type ‘IO String’

HotTag

Archive