[Ur] Memory allocation for purely functional code

Sergey Mironov grrwlf at gmail.com
Sun Mar 29 04:52:18 EDT 2015


Hi. I have written some purely functional code [1] to assist me in
solving the chomp [2] game (I'm not over, please don't spoil the
answer).  The main part of the code is the simple recursive solver
[gres]

https://github.com/grwlf/brick/blob/6e046c70c98e7d4bfb4cb058364238f1470a08b2/Brick.ur#L181

The function takes possible move (a point), a Game (size of board *
list of moves) and returns whether this move will result in Winning or
Loosing the game. Internally, gres calls [gmap] function which
iterates over possible valid moves for game given.

The problem is memory consumption. Calling [gres] on an empty 7x3
board on a server side results in allocation of 512M! It is far beyond
my estimations. I thought the 21-depth call stack would be the worst
case here. What memory allocation mechanism does Ur/Web use for making
nested purely-functional calls? What can I do to reduce the memory
consumption?

Regards,
Sergey




[1] - https://github.com/grwlf/brick/blob/master/Brick.ur
[2] - http://en.wikipedia.org/wiki/Chomp



More information about the Ur mailing list