<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><font size="4" class="">Thanks for the pointers - I’ll take a look.</font></div><div class=""><font size="4" class=""><br class=""></font></div><div class=""><font size="4" class="">The background to this is one of the puzzles on Advent Of Code 2016 Q.8.</font></div><div class=""><a href="https://adventofcode.com/2016/day/8" class="">https://adventofcode.com/2016/day/8</a></div><div class=""><br class=""></div><div class=""><font size="4" class="">There are (several hundred) sequential operations on a grid 50 x 6 - initially all zeroes</font></div><div class=""><font size="4" class="">e.g. </font></div><div class=""><font size="4" class="">rotate row y=0 by 4 </font></div><div class=""><font size="4" class="">rect 2x1 — sets sub grid from (0,0) to (2,1) to all 1s</font></div><font size="4" class="">rotate column x=35 by 1</font><div class=""><font size="4" class=""><br class=""></font></div><div class=""><font size="4" class="">I’m fine about parsing the input to a data structure and executing them i.e. </font></div><div class=""><font size="4" class=""><br class=""></font></div><div class=""><font size="4" class=""><div class="">evalExpr :: Expr -> Screen -> Screen — screen is essentially [[Int]]</div><div class="">evalExpr e s =</div><div class=""> case e of</div><div class=""> (Rect r c ) -> evalRect r c s</div><div class=""> (RotRow r by) -> evalRotRow r by s</div><div class=""> (RotCol c by) -> evalRotCol c by s</div><div class=""> (NOP ) -> id s</div><div class=""><br class=""></div><div class="">rotating a row was simple enough, code to rotate column a bit untidy and not very nice. The </div><div class="">evalRect - which sets values to one in the rectangle of size r x c starting at (0,0) top left - triggered the original question.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">At this point my knowledge of Haskell is being pushed (which is good) but I have a feeling that </div><div class="">my approach is not ‘correct’ once it gets beyond the parsing. Should each of the evalRect, evalRotRow and evalRotCol be called with a Screen (i.e. the grid at the root of this question)?</div><div class="">Is the state monad a fit for this problem?</div><div class="">Should I change my approach or is using vector the way forward?</div><div class=""><br class=""></div><div class="">Many thanks</div><div class=""><br class=""></div><div class="">Mike</div></font><font size="4" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></font></div><div class=""><font size="4" class=""><br class=""></font><div><blockquote type="cite" class=""><div class=""><font size="4" class="">On 19 Dec 2016, at 15:27, Michael Orlitzky <<a href="mailto:michael@orlitzky.com" class="">michael@orlitzky.com</a>> wrote:</font></div><font size="4" class=""><br class="Apple-interchange-newline"></font><div class=""><div class=""><font size="4" class="">On 12/19/2016 08:10 AM, mike h wrote:<br class=""></font><blockquote type="cite" class=""><font size="4" class="">Hi,<br class=""><br class="">I’m looking a problem where I have an NxN grid of ints. I need a<br class="">function like setValue x y newVal<br class=""><br class="">I have tried using [[Int]] but it does become messy when splitting ,<br class="">dropping and then ++ back together.<br class=""><br class="">What other options are available to represent a mutable grid?<br class=""><br class=""></font></blockquote><font size="4" class=""><br class="">Mutable vectors (from the vector[1] package) are an obvious choice. When<br class="">I had to do something similar, I wound up going all the way to repa[2],<br class="">which magically turns all of your grid operations into parallel ones.<br class=""><br class=""><br class="">[1] <a href="https://hackage.haskell.org/package/vector" class="">https://hackage.haskell.org/package/vector</a><br class="">[2] <a href="https://hackage.haskell.org/package/repa" class="">https://hackage.haskell.org/package/repa</a><br class=""><br class="">_______________________________________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners<br class=""></font></div></div></blockquote></div><br class=""></div></body></html>