[Haskell-cafe] Re: data structures question
Tamas K Papp
tpapp at Princeton.EDU
Fri Sep 1 05:52:03 EDT 2006
On Thu, Aug 31, 2006 at 11:09:07AM +0400, Bulat Ziganshin wrote:
> Hello Benjamin,
>
> Wednesday, August 30, 2006, 11:40:09 PM, you wrote:
>
> > Matthias Fischmann wrote:
> >> The trick is that Int is not the only index data type, but tuples of
> >> index data types are, too. Do this:
> >>
> >> | type Point = (State, State, Int)
> >> | type TypeV = Array State Double
> >> |
> >> | matrix :: TypeV
> >> | matrix = array bounds values
> >> | where
> >> | ...
>
> > Surely you meant to say
>
> > | type TypeV = Array Point Double
>
> which will require 128 gigs of memory for 32-bit cpus and even
> slightly more for 64-bit ones :)
Bulat,
Can you please explain this? The following code works fine for me,
and I don't have that much RAM ;-) It seems I am not getting
something.
import Data.Array
data State = Low | High deriving (Eq,Ord,Ix,Show)
other :: State -> State
other High = Low
other Low = High
type Point = (State,State,Int)
type TypeV = Array Point Double
f (Low,Low,a) = a
matrix = array ((Low,Low,0),(Low,Low,4)) [(i,f(i)) | i <- range ((Low,Low,0),(Low,Low,4))]
Thank you,
Tamas
More information about the Haskell-Cafe
mailing list