reset password
Author Message
rabbott
Posts: 1649
Posted 15:18 Oct 28, 2016 |

Because lambda functions are so central to functional programming, I've re-expressed many of the TicTacToe and TicTacToeHistory programs as lambda functions. This doesn't change anything about the types of the functions or how they work.

The idea is to illustrate that functions can be defined independently of assigning names to them. 

In functions whose definitions depended on guards or patterns I could not re-write the functions without more significant changes, which I didn't make. 

I was unable to re-write minimax as a lambda function. This had nothing to do with guards or patterns. Do you see why? Try it and find out.

Just noticed that the same problem arises with the replace function.

 

Last edited by rabbott at 19:00 Oct 28, 2016.
rabbott
Posts: 1649
Posted 19:09 Oct 28, 2016 |

I converted replace to a lambda function by changing it from

replace = \i item items -> xs ++ item:ys where (xs, _:ys) = splitAt i items

which didn't load, to

replace = \i item items -> let (xs, _:ys) = splitAt i items in xs ++ item:ys
 

Can you see what the issue is?