[Haskell-beginners] Can ghc compiler Optimize the several calls to
Same function
nicholas.ulysses
nicholas.ulysses at gmail.com
Mon Nov 8 08:08:28 EST 2010
It's my code to do some recursive things, focus on function 'group'.
---- cow.hs
year1 [y1,y2,y3,y4x] = y1
year2 [y1,y2,y3,y4x] = y2
year3 [y1,y2,y3,y4x] = y3
year4x [y1,y2,y3,y4x] = y4x
cow_group_sum year = sum (group year)
--look here--
group 1 = [1,0,0,0]
group (year+1) = [(year4x (group year)), (year1 (group year)),
(year2 (group year)), ((year4x (group year)) + (year3 (group year)))]
main = print (cow_group_sum 50)
---- end
Every time 'group' was called, the (group year) function was called 4
times . when call (group 30), it takes tens seconds to finish.
I have tried 'ghc -O3', but it's still 'lazy' on this thing.
Map-Reduce seems to be the answer to the question. But I want to make
sure that ghc CAN or CANNOT do the Optimize for Dynamic Programming?
----------------
xingbo wu
More information about the Beginners
mailing list