该函数形式为:
accelerate :: Float -> [Particle] -> [Particle]
“Particle”是一种数据类型,包含质量、位置向量和速度向量,“Float”参数表示模拟中相应时间步长的增量。
我想得到一些关于在计算列表中每个粒子相对于其他粒子的速度时可以使用的可能函数的建议。
我能想到的一个可能的方法是:
assume there is another function 'velocityCalculator' which has the following definition:
velocityCalculator :: Particle -> Particle -> (Float,Float)
apply foldl; using the above function as the binary operator, a particle and the list of particles as the arguments, i.e.
foldl velocityCalculator particle particleList
iterate through the list of particle, applying foldl to each element and building the new list containing the particles with the updated velocities
请注意 -> 我只是寻求建议,而不是答案!
谢谢!