0

I am trying to build a static Array in Haskell with a custom Enum Index type and have implemented the required functions like this:

data Ind = One | Two | Three | Four deriving (Eq,Ord,Enum,Show)

instance Ix Ind where
  range (m,n)             = [m..n]
  inRange (m,n) i         = m <= i && i <= n
  index b i | inRange b i = fromEnum i
            | otherwise   = -1
  rangeSize (m,n) = (index (m,n) n ) + 1

With this I am now trying to build a matrix type:

type Row a    = Array Ind a
type Matrix a = Array Ind Row a

However, I am getting this error on the Matrix type:

 Illegal type "Array Ind Row a" in constructor application

Could anybody explain to me what this error means and what I am doing wrong?

3
  • 1
    Perhaps you meant type Matrix a = Array Ind (Row a)? Commented Apr 15, 2019 at 11:50
  • Ohh yes indeed, thanks! What a stupid mistake Commented Apr 15, 2019 at 12:15
  • 2
    you could also write ... deriving (Eq,Ord,Enum,Show, Ix ). Commented Apr 15, 2019 at 12:29

1 Answer 1

3

The error message is unhelpful, but you just need to add some brackets:

type Matrix a = Array Ind (Row a)

You're saying that the element type should be Row a. Without the brackets, it's trying to pass Row and a as separate type arguments — which doesn't work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.