[Haskell-cafe] data structures question
Tamas K Papp
tpapp at Princeton.EDU
Wed Aug 30 09:11:35 EDT 2006
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
More information about the Haskell-Cafe
mailing list