# data structures question

13 messages
Open this post in threaded view
|

## data structures question

 Hi, Having read some tutorials, I would like to start using Haskell "for real", but I have some questions about data structures. The mathematical description of the problem is the following: assume there is a function V(a,b,theta), where a and b can have two values, High or Low, and theta is a number between zero and n (n is given). The range of V is the real numbers. Then there is an algorithm (called value iteration, but that's not important) that takes V and produces a function of the same type, called V'.  The algorithm uses a mapping that is not elementwise, ie more than the corresponding values of V are needed to compute a particular V'(a,b,theta) -- things like V(other a,b,theta) and V(a,b,theta+1), where data State = Low | High other :: State -> State other High = Low other Low = High Question 1: V can be represented as a 3-dimensional array, where the first two indices are of type State, the third is Int (<= n).  What data structure do you suggest in Haskell to store V?  Is there a multidimensional array or something like this? Let's call this structure TypeV. Question 2: I would like to write valueit :: TypeV -> TypeV valueit V = mapondescartesproduct [Low,High] [Low,High] [0..n] mapV where             -- mapV would calculate the new V' using V             -- mapV :: State -> State -> Int -> Double to fill the new data structure.  How to do this sensibly? Thanks, Tamas _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: data structures question

Open this post in threaded view
|

## Re: data structures question

Open this post in threaded view
|

## Re: data structures question

 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 Cheers, Ben _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Re: data structures question

 Benjamin Franksen 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 > > Cheers, > Ben And type Value = Double newtype PointNat = PointNat Int deriving (...Ix) type Point = (State,State,PointNat) Or even type TypeVof a = Array PointNat a type TypeV = TypeVof Value I did not even run the code I wrote through ghci, I was just showing what it could look like. And stop calling me Shirley. _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Re: data structures question

 In reply to this post by Ben Franksen-2 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 :) -- Best regards,  Bulat                            mailto:[hidden email] _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Re: data structures question

 On Thursday 31 August 2006 09:09, 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 :) Wow, that's bad. But then the situiation isn't really much better with a simple Array Int Double, values of which would always use up all my memory. Surely you don't mean that ;) Ben _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Re: data structures question

Open this post in threaded view
|

## Re: Re: Re: data structures question

 > > And stop calling me Shirley. > Could you please be a bit more explicit? Have I offended anyone? This is a reference to a joke from the movie Airplane: "Surely, you can't be serious." "I am serious, and stop calling me Shirley." I imagine it meant nothing personal.   Jared. -- http://www.updike.org/~jared/reverse ")-:" _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Re: Re: data structures question

Open this post in threaded view
|

## Re: Re: Re: data structures question

 Chris Kuklewicz wrote: > Benjamin Franksen wrote: >> Chris Kuklewicz wrote: >>> I did not even run the code I wrote through ghci, I was just showing >>> what it could look like. >>> >>> And stop calling me Shirley. [...] >> Could you please be a bit more explicit? Have I offended anyone? Or else, >> how do I have to understand this comment other than as a rebuke? And how >> comes you answer this as if you were the one who posted the code, and not >> a person named Matthias Fischmann? > > Sorry for the misunderstanding.  No one has been offended or given > offense. > The Surely/Shirley is a reference to the classic 1980 motion picture > "Airplane!" in which the humor includes a repeated motif [1]: > >> Rumack: Mr. Striker, the passengers are getting worse. You must land >> soon. Ted Striker: Surely there must be something you can do. >> Rumack: I'm doing everything I can... and stop calling me Shirley. > >> Ted Striker: Surely you can't be serious. >> Rumack: I am serious... and don't call me Shirley. > > Nothing was offensive or arrogant.I just saw it as an opportunity to > reference the joke. Ahh, I'm very glad to hear that. It seems the misunderstanding was completely on my part. Did a little research and found quite a number for websites citing dialogs from this movie. I begin to understand that it must have been cult... > I am sorry my other posting was off topic.  Sometimes I contribute what > occurs to me instead of what is relevant. I can happily live with that ;-) (although I'd still be interested what prompted you to post this code which I admittedly did not fully understand). And sorry for dragging this (completely off-topic) stuff out here on the list. I'll shut up now. Cheers, Ben _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe