Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:08:55+00:00 2026-06-06T12:08:55+00:00

I had the idea to write a matrix division in Haskell as Muliply A*

  • 0

I had the idea to write a matrix division in Haskell as Muliply A* Inverse B.

I wrote some code to do that, but the compiler had the idea to stop me. It shows the following error:

Invalid type signature :MatrixDivision :: Matrix-> Matrix-> Matrix at line 86:1
Should be of (variable)::(Type) 

What do I wrong? This is the code:

import List

type Vector = [Int]
type Matrix = [Vector]

--basic constructions for vectors

zeroVector :: Int -> Vector
zeroVector n = replicate n 0

--basic operations for vectors

dotProduct :: Vector -> Vector -> Int
dotProduct v w = sum ( zipWith (*) v w )

vectorSum :: Vector -> Vector -> Vector
vectorSum = zipWith (+)

vectorScalarProduct :: Int -> Vector -> Vector
vectorScalarProduct n vec = [ n * x | x <- vec ]

--basic constructions for matrices

-- elemMatrix n i j v   is the n-by-n elementary matrix with
-- entry  v  in the (i,j) place
elemMatrix :: Int -> Int -> Int -> Int -> Matrix
elemMatrix n i j v =
  [ [ entry row column | column <- [1..n] ] | row <- [1..n] ]
  where
    entry x y
    | x == y           = 1
    | x == i && y == j = v
    | otherwise        = 0

idMatrix :: Int -> Matrix
idMatrix n = elemMatrix n 1 1 1

zeroMatrix :: Int -> Int -> Matrix
zeroMatrix i j = replicate i (zeroVector j)

--basic operations for matrices

matrixSum :: Matrix -> Matrix -> Matrix
matrixSum = zipWith vectorSum

matrixScalarProduct :: Int -> Matrix -> Matrix
matrixScalarProduct n m = [ vectorScalarProduct n row | row <- m ]

matrixProduct :: Matrix -> Matrix -> Matrix
matrixProduct m n = [ map (dotProduct r) (transpose n) | r <- m ]

{- The determinant and inverse functions given here are only for examples
of Haskell syntax.  Efficient versions using row operations are implemented
in RowOperations.hs .-}

--determinant using cofactors

remove :: Matrix -> Int -> Int -> Matrix
remove m i j 
  | m == [] || i < 1 || i > numRows m || j < 1 || j > numColumns m =
    error "(i,j) out of range"
  | otherwise = transpose ( cut (transpose ( cut m i ) ) j )

determinant :: Matrix -> Int
determinant [] = error "determinant: 0-by-0 matrix"
determinant [[n]] = n
determinant m = sum [ (-1)^(j+1) * (head m)!!(j-1) * determinant (remove m 1    j) | j <- [1..(numColumns m) ] ]

--inverse

cofactor :: Matrix -> Int -> Int -> Int
cofactor m i j = (-1)^(i+j) * determinant (remove m i j)

cofactorMatrix :: Matrix -> Matrix
cofactorMatrix m = [ [ (cofactor m i j) | j <- [1..n] ] | i <- [1..n] ]
  where
    n = length m

inverse :: Matrix -> Matrix
inverse m = transpose [ [ quot x ( determinant m) |
  x <- row ] | row <- (cofactorMatrix m) ]

--Matrix Division

MatrixDivision :: Matrix -> Matrix -> Matrix 
MatrixDivision  m n = matrixProduct m inverse(n)

I wrote the full code to give more information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:08:58+00:00Added an answer on June 6, 2026 at 12:08 pm

    At the expression level, names beginning with an Uppercase letter are reserved for data constructors.

    Your MatrixDivision should be called matrixDivision

    See Section 2.4 of the Haskell Report.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a crazy (but so crazy that it just might work) idea where
I've had an idea for some time now to write a trading platform application
I had an idea that I could write a query to find all the
I had an idea that would require me be able to send and receive
I had this idea and my first reaction after having it was That's a
Recently a compiler warning and (very useful) hint prompted me to write the code
I have created an application that does the following: Make some calculations, write calculated
We currently have some code to extract digits from an int, but I need
I just had the idea of writing a function in MySQL that I can
I recently had an idea to create my own String class to make using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.