<div dir="ltr">Hmm, this is very helpful - didn't know it existed. Thanks very much, I'll check it out!<div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-family:arial;font-size:small">Tim <br></div><div style="font-family:arial;font-size:small"><br></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Thu, Jun 23, 2016 at 7:41 AM, David McBride <span dir="ltr"><<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><font color="#cccccc">The problem isn't with array, but rather your index. Ix instances are always sorted in ascending order, as you might imagine. You can however, use your own index in arrays and they can be indexed in whatever order you like.<br><br><br></font></div><div><font color="#cccccc">{-# LANGUAGE GeneralizedNewtypeDeriving #-}<br><br>import Data.Array<br>import Data.Ix<br><br>newtype MyIx = MyIx Int deriving (Eq, Num, Show)<br><br>instance Ord MyIx where<br> compare (MyIx a) (MyIx b) =<br> case compare a b of<br> LT -> GT<br> GT -> LT<br> EQ -> EQ<br><br>instance Ix MyIx where<br> range (MyIx a, MyIx b) = map MyIx $ reverse [b..a]<br> index (MyIx a, MyIx b) (MyIx c) = a - c<br> inRange (MyIx a, MyIx b) (MyIx c) = c <= a && c >= b<br></font></div><div><font color="#cccccc"><br>blah :: Array MyIx Char<br>blah = array (3,0) [(0,'a'),(1,'b'),(2,'c'),(3,'d')]<br><br>Warning: I only very lightly tested the above code.<br></font></div><div><font color="#cccccc"><br>You can mix your index and normal indexes to get the row / col ordering you are hoping for.<br><br>blah2 :: [((MyIx, Int), Char)] -> Array (MyIx, Int) Char<br>blah2 = array ((3,0),(0,3))<br><br></font></div><font color="#cccccc">Finally, if you are really looking for something that is designed to be a matrix, you might try one of several libraries that are out there, like hmatrix.<br><br></font></div><font color="#cccccc">Hopefully this helps.</font></div></blockquote></div></div></div>