<div dir="ltr"><div><div><div>Hi Tim,<br><br></div>Congrats on your choice of tic-tac-toe. I also believe it's a good toy to get your feet wet with haskell.<br><br></div>1. Your concerns about writing a "custom datatype" are best addressed by reading up on it. If you search for "haskell data type declarations", you'll find good material explaining the difference between "data", "newtype", and "type" declarations. You'll also understand the meaning of the error message and what "data constructor" refers to.<br><br></div>2. Functions defined on lists are here:<br><br><a href="https://hackage.haskell.org/package/base/docs/Data-List.html">https://hackage.haskell.org/package/base/docs/Data-List.html</a><br><cite class=""><br></cite><div><div><div>The update function you're looking for is (!!).<br><br></div><div><br><br></div></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">-- Kim-Ee</div></div>
<br><div class="gmail_quote">On Fri, Mar 13, 2015 at 6:02 AM, Timothy Washington <span dir="ltr"><<a href="mailto:twashing@gmail.com" target="_blank">twashing@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">To get started, I'm trying to implement a simple <i>tictactoe</i> game. And I would like to be able to represent a Piece on the board, as either the string "X" or "O". This is what I have so far. <div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>module Main where</div></div><div><div><br></div></div><div><div>data Piece = X | O</div></div><div><div>type Row = [Piece]</div></div><div><div>type Board = [Row]</div></div><div><div><br></div></div><div><div>-- put an X or O in a position</div></div><div><div>move :: Board -> Piece -> Board</div></div><div><div>move board piece = board</div></div><div><div>  </div></div><div><div>-- check win vertically</div></div><div><div>-- check win horizontally</div></div><div><div>-- check win diagonally</div></div><div><div><br></div></div><div><div>main :: IO ()</div></div><div><div>main = putStrLn "Hello World"</div></div></blockquote><div><br></div><div><br></div><div><b><i>A)</i></b> Now, I'd like to be able to <b><i>load code interactively</i></b>, preferably within emacs. However I don't have access to my types with <b><i>ghci</i></b> or <b><i>ghc-mod (Interactive-Haskell)</i></b>. In either case, this call fails with the below error.</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><br></div></div><div><div>let p = Piece X</div></div><div><div><font color="#990000"><interactive>:20:9-13: Not in scope: data constructor `Piece'</font></div></div></blockquote><div><div><br></div><div><b><i>B)</i></b> And how do I make a <b><i>custom datatype</i></b> that's one of two strings (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, so I know it can compile. But I'm confused as to where X or O is defined, and how I would supply it as an input. </div><div><br></div><div><b><i>C)</i></b> Finally, how do we update nested lists in Haskell. I want the move function to take a Board, Piece, and Position, and return a Board. I see some <a href="https://www.haskell.org/hoogle/?hoogle=update" target="_blank">results from Hoogle</a>. Is this where <a href="https://www.haskell.org/hoogle/?hoogle=lens" target="_blank">Lenses</a> or <a href="https://www.haskell.org/hoogle/?hoogle=zipper" target="_blank">Zippers</a> come into play?</div><div><br></div><div><br></div><div>Thanks </div><div><br></div><div><div><div dir="ltr"><div style="font-family:arial;font-size:small">Tim Washington </div><div style="font-family:arial;font-size:small"><a href="http://interruptsoftware.com" style="color:rgb(17,85,204)" target="_blank">Interruptsoftware.com</a> </div><div style="font-family:arial;font-size:small"><br></div></div></div></div>
</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>