<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="">Hi,</div><div class="">In the end I used a set to hold tuples of int pairs (row, col) and manipulated them</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">type By = Int </div><div class="">type Row = Int </div><div class="">type Col = Int </div></div><div class=""><br class=""></div><div class=""><div class="">type Pixels = Set (Row, Col)</div><div class=""><br class=""></div><div class="">data Screen = Screen</div><div class=""><br class=""></div><div class=""> { maxX :: Col,</div><div class=""> maxY :: Row,</div><div class=""> pixels :: Pixels</div><div class=""> }</div></div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Mike</div><br class=""><div><blockquote type="cite" class=""><div class="">On 24 Dec 2016, at 14:37, Magnus Therning <<a href="mailto:magnus@therning.org" class="">magnus@therning.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">How did it go?<div dir="auto" class=""><br class=""></div><div dir="auto" class="">When I solved that AoC problem I ended up using the matrix package: <a href="http://hackage.haskell.org/package/matrix" class="">http://hackage.haskell.org/package/matrix</a></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">/M</div><div dir="auto" class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On 19 Dec 2016 7:31 pm, "mike h" <<a href="mailto:mike_k_houghton@yahoo.co.uk" class="">mike_k_houghton@yahoo.co.uk</a>> wrote:<br type="attribution" class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" 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" target="_blank" class="">https://adventofcode.com/2016/<wbr class="">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 class=""><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" target="_blank" class="">michael@orlitzky.com</a>> wrote:</font></div><font size="4" class=""><br class="m_-1037435723290963001Apple-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" target="_blank" class="">https://hackage.haskell.org/<wbr class="">package/vector</a><br class="">[2] <a href="https://hackage.haskell.org/package/repa" target="_blank" class="">https://hackage.haskell.org/<wbr class="">package/repa</a><br class=""><br class="">______________________________<wbr class="">_________________<br class="">Beginners mailing list<br class=""><a href="mailto:Beginners@haskell.org" target="_blank" class="">Beginners@haskell.org</a><br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/beginners</a><br class=""></font></div></div></blockquote></div><br class=""></div></div><br class="">______________________________<wbr class="">_________________<br class="">
Beginners mailing list<br class="">
<a href="mailto:Beginners@haskell.org" class="">Beginners@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/beginners</a><br class="">
<br class=""></blockquote></div></div>
_______________________________________________<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=""></div></blockquote></div><br class=""></body></html>