6 people like it.

tutorial, test, tennis, clarity, simplicity in f#

f# short and sweet may help beginners. Score on winning a point, Winning number first and other players is labeled: b example "0",b ->"15", b. A special case of draw-deuce is "40", "A" -> "40","40" If player 2 wins a point score calling is flipped as 2->score(b,a). fold (fun to call for each element in the test list) (initials "0","0") [test list of winning player] Notice f# is perhaps easier and clearer than pseudo code and verbose description. An improvement suggestion for Don is if syntax is not confused can word function be made optional so = |... or -> |.. so syntax is ever more clearer?

let score=function |"0",b->"15",b|"15",b->"30",b|"30",b->"40",b|"40","A"->"40","40"|"40",b->"A",b|_,b->"Win",b

List.fold (fun (a,b)->function |2->score(b,a) |_->score(a,b))  ("0","0")  [1;2;1;1;1;2;1;1;1;1]

val score : string * string -> string * string

Full name: Script.score
val b : string
Multiple items
module List

from Microsoft.FSharp.Collections

type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member GetSlice : startIndex:int option * endIndex:int option -> 'T list
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val fold : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State

Full name: Microsoft.FSharp.Collections.List.fold
val a : string
Raw view New version

More information

Posted:20 days ago
Author:Musa Jahanghir
Tags: tennis; sample; functional data; kata , test , tutorial