I have been developing some code that uses Data.Array to use multidimensional arrays,
now I want to put those arrays into a data type so I have something like this
data MyType = MyType { a :: Int, b :: Int, c :: Array }
Data.Array has type:
(Ix i, Num i, Num e) => Array i e
Where “e” can be of any type not just Num.
I am convinced I am missing a concept completely.
How do I accomplish this?
What is special about the Data.Array type that is different from Int, Num, String etc?
Thanks for the help!
Arrayis not a type. It’s a type constructor. It has kind* -> * -> *which means that you give it two types to get a type back. You can sort of think of it like a function. Types likeIntare of kind*. (Numis a type class, which is an entirely different thing).You’re declaring
cto be a field of a record, i.e.,cis a value. Values have to have a type of kind*. (There are actually a few more kinds for unboxed values but don’t worry about that for now).So you need to provide two type arguments to make a type for
c. You can choose two concrete types, or you can add type arguments toMyTypeto allow the choice to be made elsewhere.References