[Haskell-beginners] type family exercise

info at maximka.de info at maximka.de
Fri Dec 29 15:52:10 UTC 2017


There is a little exercise at the end of the post "Type Tac Toe: Advanced Type Safety" http://chrispenner.ca/posts/type-tac-toe

>  As an exercise try combining playX and playO into a more general play! Here's a hint, you'll want to make another wrapper type like we did with Coord!

Link to the code https://github.com/ChrisPenner/Type-Tac-Toe/blob/master/src/TypeTacToe.hs

Unfortunately I couldn't solve it by myself. The only generalised play I could implement is here: 

play :: (Played x y b ~ 'False)
     => (Coord x, Coord y) -> Board b PieceT -> PieceT -> Board b PieceT
play (coordVal -> x, coordVal -> y) (Board b) p
  = Board $ overTrip y (overTrip x (const p)) b

 I would be very grateful for any help to solve the exercise by using type family extension.

Regards,
Alexei


More information about the Beginners mailing list