# Phillip Trelford's Array

## POKE 36879,255

Last week’s 2-track Progressive F# Tutorials conference seems to have gone pretty well:

Possibly the best Skills Matter event I have attended

You can see pictures from the event over on the Skills Matter Flickr stream:

Skills Matter also have Videos Podcasts of all the sessions including Don Syme’s keynote:

This was followed by an excellent Tennis Kata in the Programming with the Stars session performed by Mark Needham and Mark Seeman, first in C# and then F#.

Don posted this solution on F# Snippets which is pretty close the 2 Mark's vesion:

``` 1: /// The two players
2: type Player = A | B
3:
4: /// The point score in for a player in a game
5: type PlayerPoints = Zero | Fifteen | Thirty | Forty
6:
7: /// The score of a game
8: type Score =
9:     | Points of PlayerPoints * PlayerPoints
10:     | Advantage of Player
11:     | Deuce
12:     | Game of Player
13:
14: /// Compute the next score in a game
15: let nextPointScore a =
16:     match a with
17:     | Zero -> Fifteen
18:     | Fifteen -> Thirty
19:     | Thirty -> Forty
20:     | Forty -> failwith "what??"
21:
22: /// Check if we've reached deuce
23: let normalize score =
24:     match score with
25:     | Points(Forty,Forty) -> Deuce
26:     | _ -> score
27:
28: /// Score a point in a game
29: let scorePoint score point =
30:     match score, point with
31:     | Advantage player1, player2 when  player1 = player2 -> Game player1
32:     | Advantage player1, player2 -> Deuce
33:     | Deuce, player -> Advantage player
34:     | Points(Forty, _), A -> Game A
35:     | Points(_, Forty), B -> Game B
36:     | Points(a, b), A -> normalize (Points (nextPointScore a, b))
37:     | Points(a, b), B -> normalize (Points (a, nextPointScore b))
38:     | Game _ , _ -> (* printfn "the game is over!"; *) score
39:
40: /// Score a whole game, where a game is a sequence of points
41: let scoreGame (points: seq<Player>) =
42:     Seq.scan scorePoint (Points(Zero,Zero)) points
union case Player.A: Playerunion case Player.B: Playertype PlayerPoints =  | Zero  | Fifteen  | Thirty  | FortyFull name: Snippet.PlayerPoints  type: PlayerPoints  implements: System.IEquatable<PlayerPoints>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<PlayerPoints>  implements: System.IComparable  implements: System.Collections.IStructuralComparable
The point score in for a player in a gameunion case PlayerPoints.Zero: PlayerPointsunion case PlayerPoints.Fifteen: PlayerPointsunion case PlayerPoints.Thirty: PlayerPointsunion case PlayerPoints.Forty: PlayerPointstype Score =  | Points of PlayerPoints * PlayerPoints  | Advantage of Player  | Deuce  | Game of PlayerFull name: Snippet.Score  type: Score  implements: System.IEquatable<Score>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Score>  implements: System.IComparable  implements: System.Collections.IStructuralComparable
The score of a gameunion case Score.Points: PlayerPoints * PlayerPoints -> Scoreunion case Score.Advantage: Player -> Scoretype Player =  | A  | BFull name: Snippet.Player  type: Player  implements: System.IEquatable<Player>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Player>  implements: System.IComparable  implements: System.Collections.IStructuralComparable
The two playersunion case Score.Deuce: Scoreunion case Score.Game: Player -> Scoreval nextPointScore : PlayerPoints -> PlayerPointsFull name: Snippet.nextPointScore
Compute the next score in a gameval a : PlayerPoints  type: PlayerPoints  implements: System.IEquatable<PlayerPoints>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<PlayerPoints>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval failwith : string -> 'TFull name: Microsoft.FSharp.Core.Operators.failwithval normalize : Score -> ScoreFull name: Snippet.normalize
Check if we've reached deuceval score : Score  type: Score  implements: System.IEquatable<Score>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Score>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval scorePoint : Score -> Player -> ScoreFull name: Snippet.scorePoint
Score a point in a gameval point : Player  type: Player  implements: System.IEquatable<Player>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Player>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval player1 : Player  type: Player  implements: System.IEquatable<Player>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Player>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval player2 : Player  type: Player  implements: System.IEquatable<Player>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Player>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval player : Player  type: Player  implements: System.IEquatable<Player>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<Player>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval b : PlayerPoints  type: PlayerPoints  implements: System.IEquatable<PlayerPoints>  implements: System.Collections.IStructuralEquatable  implements: System.IComparable<PlayerPoints>  implements: System.IComparable  implements: System.Collections.IStructuralComparableval scoreGame : seq<Player> -> seq<Score>Full name: Snippet.scoreGame
Score a whole game, where the game is represented as a sequence of pointsval points : seq<Player>  type: seq<Player>  inherits: System.Collections.IEnumerableMultiple items
val seq : seq<'T> -> seq<'T>Full name: Microsoft.FSharp.Core.Operators.seq
--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>Full name: Microsoft.FSharp.Collections.seq<_>  type: seq<'T>  inherits: System.Collections.IEnumerablemodule Seqfrom Microsoft.FSharp.Collectionsval scan : ('State -> 'T -> 'State) -> 'State -> seq<'T> -> seq<'State>Full name: Microsoft.FSharp.Collections.Seq.scanval game1 : seq<Player>Full name: Snippet.game1  type: seq<Player>  inherits: System.Collections.IEnumerable
A sample game - A wins every pointval game2 : seq<Player>Full name: Snippet.game2  type: seq<Player>  inherits: System.Collections.IEnumerable
A sample game - A and B swap points indefinitelyval game3 : seq<Player>Full name: Snippet.game3  type: seq<Player>  inherits: System.Collections.IEnumerable
A sample game - A and B trade points but A wins more points than Bval truncate : int -> seq<'T> -> seq<'T>Full name: Microsoft.FSharp.Collections.Seq.truncateval toList : seq<'T> -> 'T listFull name: Microsoft.FSharp.Collections.Seq.toListval randomGame : int -> seq<Player>Full name: Snippet.randomGame
Generate a random gameval i : int  type: int  implements: System.IComparable  implements: System.IFormattable  implements: System.IConvertible  implements: System.IComparable<int>  implements: System.IEquatable<int>  inherits: System.ValueTypeval rnd : System.Randomnamespace Systemtype Random =  class    new : unit -> System.Random    new : int -> System.Random    member Next : unit -> int    member Next : int -> int    member Next : int * int -> int    member NextBytes : System.Byte [] -> unit    member NextDouble : unit -> float  endFull name: System.RandomSystem.Random.NextDouble() : floatval i : int32  type: int32  implements: System.IComparable  implements: System.IFormattable  implements: System.IConvertible  implements: System.IComparable<int>  implements: System.IEquatable<int>  inherits: System.ValueTypeval nth : int -> seq<'T> -> 'TFull name: Microsoft.FSharp.Collections.Seq.nthval printfn : Printf.TextWriterFormat<'T> -> 'TFull name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn```

Discriminated unions were used to describe the tennis domain and pattern matching to transition between game score states, e.g. deuce to advantage. Colin Bull came up with a Tennis Monad: http://fssnip.net/8Q.

After lunch the tutorials broke into 2 tracks:

1. Chris Marinos introduced the F# programming language via his F# Koans
2. Meanwhile Tomas Petricek showcased Data Access in F#, Today & Tomorrow

If you were in the Data Access session you may well have created your own Point of sale application using the Tesco API:

By the end of the session we’d created our own custom F# 3 Type Provider for .INI files:

You can download the source code here.

On the second day in the morning Robert Pickering ran a hands-on session on Building Applications in F# using a WPF Twitter client as the sample. Meanwhile Tomas Petricek and Simon Cousins presented on Asynchronous Programming in F#.

In the afternoon George Stavroulakis & Gian Ntzik ran a very well received session on F# in the cloud, the slides and code for which are available on the M-Brace site.

Unfortunately I couldn’t make their session as I was presenting on TDD & BDD with F#:

The first part of the talk introduced the REPL (F# Interactive) using the code from the Functional Cells: A Spreadsheet in F# article over on the DeveloperFusion site. The tasks for this session are available at: http://trelford.com/progfsharp.zip

Thanks again to all the speakers, attendees, sponsors and Skills Matter for putting on the event.

Please support next year’s Progressive F# Tutorials: