<div dir="ltr">Crickey. You're still the man, lol :)<div class="gmail_extra"><br></div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div style="font-family:arial;font-size:small"><br></div></div></div></div><div class="gmail_quote">On Tue, Mar 24, 2015 at 6:13 AM, Bob Hutchison <span dir="ltr"><<a href="mailto:hutch-lists@recursive.ca" target="_blank">hutch-lists@recursive.ca</a>></span> wrote:<font color="#cccccc"><br></font><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font color="#cccccc"><br>
> On Mar 23, 2015, at 10:38 PM, Timothy Washington <<a href="mailto:twashing@gmail.com">twashing@gmail.com</a>> wrote:<br>
><br>
<br>
[snip]<br>
<span class=""><br>...<br>
<br>
</span>You seem set on lenses. So if you write that move function like this (in case anyone’s wondering, I happen to know this isn’t a homework question):<br>
<span class=""><br>
data Piece = X | O | E deriving Show<br>
<br>
</span>move :: a -> b1 -> ASetter a b a1 b1 -> b<br>
move board position piece = board & position .~ piece<br>
<br>
This’ll work. But how are you going to get the position? If you’re given an integer based coordinate, as you seem to want from your definitions of Position, then you’re going to have to do something ugly.<br></font></blockquote><div><br></div><div>This is a good point. I'm not particularly attached to lenses. That was just the conclusion I reached, in order to reach into and manipulate my original nested lists. I didn't see a way to do nested list updates in Data.List, <a href="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-List.html">on hackage</a>. But now I see the difference between that and <a href="https://hackage.haskell.org/package/array-0.5.0.0/docs/Data-Array.html">Data.Array</a> (indexable, etc).</div><div><br></div><div>I'll come back to Lenses later on, just because now I'm curious. I'm happy for the Position to be "<b>data Position = <i>SomeLensType</i> <i>SomeLensType</i> deriving Show</b>", where "<b>:t _2 => SomeLensType</b>". Or something else that accommodates lens' data types.... but baby steps :)</div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font color="#cccccc">Why not just go with an array and be done with it? Something like this (with your original definition of Piece):<br>
<br>
import Data.Array<br>
<span class=""><br>
data Piece' = X | O | E deriving Show<br>
</span>type Position' = (Int,Int)<br>
type Board' = Array Position’ Piece'<br>
<br>
board' :: Board'<br>
board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]]<br>
<span class=""><br>
move' :: Board' -> Piece' -> Position' -> Board'<br>
</span>move' board piece pos = board // [(pos, piece)]<br></font></blockquote><div><br></div><div>This works swimmingly. So excellent point. </div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font color="#cccccc">If you want a slightly less ugly of looking at the board<br>
<br>
import qualified Data.List.Split as S<br>
<br>
pp board = mapM_ print $ S.chunksOf 3 $ elems board<br>
<br>
will display the board something like:<br>
<br>
[E,E,E]<br>
[E,E,E]<br>
[E,E,E]<br>
<br>
I hope I didn’t say too much.<br></font></blockquote><div><br></div><div>Not at all. These are exactly the kinds of hints that I need. In fact, with the <i><font color="#0000ff"><b>//</b></font></i> and <i><b><font color="#0000ff">array</font></b></i> functions, this makes a lot of sense. And I used that and the board beautifier chunk, to create this. </div><div><br></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><div>import Data.Array</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>import qualified Data.List.Split as S</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><br></div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>data Piece' = X | O | E deriving Show</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>type Position' = (Int,Int)</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>type Board' = Array Position' Piece'</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><br></div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>board' :: Board'</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]]</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><br></div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>ppb' :: Board' -> IO()</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>ppb' b = mapM_ print $ S.chunksOf 3 $ elems b</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><br></div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>move' :: Board' -> Piece' -> Position' -> Board'</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>move' board piece pos = board // [(pos, piece)]</div></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Now, I can pass in the board, piece, and position, to get my expected result.</div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>λ> board'</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>array ((1,1),(3,3)) [((1,1),E),((1,2),E),((1,3),E),((2,1),E),((2,2),E),((2,3),E),((3,1),E),((3,2),E),((3,3),E)]</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>λ> let b1 = move' board' <b><i><font color="#0000ff">X</font></i></b> (1,3)</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>λ> b1 </div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>array ((1,1),(3,3)) [((1,1),E),((1,2),E),((1,3),X),((2,1),E),((2,2),E),((2,3),E),((3,1),E),((3,2),E),((3,3),E)]</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>λ> ppb' b1 </div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>[E,E,<b><i><font color="#0000ff">X</font></i></b>]</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>[E,E,E]</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>[E,E,E] </div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font color="#cccccc">Cheers,<br>
Bob</font></blockquote><div><br></div><div style="font-family:arial"><br></div><div style="font-family:arial">Cool ! </div><div style="font-family:arial">Cheers :) </div><div style="font-family:arial"><br class="">Tim Washington </div><div style="font-family:arial"><a href="http://interruptsoftware.com/" target="_blank">Interruptsoftware.com</a> </div><div> </div></div></div></div>