简体   繁体   中英

Creating UArray Int (Complex Double) in Haskell

I am attempting to have a UArray Int (Complex Double) . This signature is fine, however when I try to access a specific index using (!) I receive an error. Here is the code I am attempting to use:

test :: UArray Int (Complex Double) -> Complex Double
test arr = arr ! 0

and the error I am getting:

No instance for (IArray UArray (Complex Double)) arising from a use of `!'
Possible fix:
  add an instance declaration for (IArray UArray (Complex Double))
In the expression: arr ! 0
In an equation for `test': test arr = arr ! 0

This worked fone for UArray Int Double and I am curiouis as to why this does not work for (Complex Double). Thanks in advance for the help.

From the Data.Array.Unboxed documentation , there seem to be instances of IArray with UArray just for types like Char , Double or Int , not polymorphic. If you need to store values of other types, you should use boxed Array .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM