reset password
Author Message
rabbott
Posts: 1649
Posted 14:55 Oct 28, 2016 |

In this project you are expected to understand the type declarations for all the Tic Tac Toe functions (as well as the other type declarations) and to explain the intent of the functions, i.e., what they do.  (You are not expected to be able to explain how the functions accomplish their jobs.) A good way to explain the intent of a function is to generate some sample inputs and outputs and to discuss the relationship between an input and its corresponding output.

lishenyu
Posts: 103
Posted 16:42 Oct 29, 2016 |

hi professor,

from this piece of code here:

makeOutputStrings = \game ->  errMsgs game
                                  ++ makeBoardStrings (board game)
                                  ++ [gameStatus game]

why does '(board game)' work here?  why we can use "game" in the code while the data type we have defined  is "Game"? Thanks!

rabbott
Posts: 1649
Posted 17:21 Oct 29, 2016 |

Try

> :t board
board :: Game -> Board

So board requires a Game as an argument. The actual argument to board is the lambda parameter game, which appears in all three lines of the code as written. It could have been g or any other identifier. 

It would be nice to be able to write this function in point-free notation. But given what has to be computed I don't see a way to do that.

The type of makeOutputStrings is Game -> [String]. So the argument must be a Game.

Last edited by rabbott at 17:23 Oct 29, 2016.