So I'll confess that I've had a big crush on Haskell for a couple of years now. I've tried and failed many times to really get beyond trivial code, but I'm utterly fascinated by the code one can write with strong, static typing. It can feel contrived at times and very constraining, but I can definitely see the benefits, which is why I'm so excited that Perl 6 has (gradual) types!

I've been working through Haskell Programming From First Principles for a year or so, and I made it to the Hangman game example. After getting a working program in Haskell, I wanted to see how quickly/easily I could do the same in Perl. While working through this code, I found that Perl's type system wasn't able to catch logical errors that Haskell would -- for example, I started off using a string for the "state" of the game where underscores represent unguessed characters, but I decided to move to an array and Perl was unable to find (at compile time) a place in my Puzzle class where I failed to make the appropriate change.

Still, I find this code extremely compact and readable. It was really fun to write this!

Here's an example of a game I won:

$ ./hangman.pl6 puzzle = _ _ _ _ _ _ _ [] What is your guess? a puzzle = _ _ _ _ _ _ _ [a] What is your guess? i puzzle = _ _ _ _ _ _ _ [ai] What is your guess? e puzzle = _ e _ _ _ e _ [aei] What is your guess? o puzzle = _ e _ _ _ e _ [aeio] What is your guess? u puzzle = _ e _ _ u e _ [aeiou] What is your guess? s puzzle = _ e s _ u e _ [aeiosu] What is your guess? t puzzle = _ e s _ u e _ [aeiostu] What is your guess? r puzzle = r e s _ u e r [aeiorstu] What is your guess? c puzzle = r e s c u e r [aceiorstu] You won!

And here is the code. Comments and suggestions welcome! This was my first Perl 6 object code.