O'Reilly logo

Get Programming with F#: A guide for .NET developers by Isaac Abraham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Discriminated unions, pattern matching, and lists

// Define, create, and unwrap a single-case discriminated union (lesson 23) type PlayerId = PlayerId of Guid let playerId = PlayerId (Guid.NewGuid()) let (PlayerId unwrapped) = playerId // Define and create a multicase discriminated union (lesson 22) type ClassifiedPlayer = | Beginner of Player | Standard of Player * PlayerId * GamesPlayed : int | Experienced of Player * GamesPlayed : int * DateStarted : DateTime let experiencedPlayer = Experienced(player, 24, DateTime(2015, 1, 1)) // Pattern matching over a discriminated union (lessons 20, 21) let describe player = match player with | Beginner player -> sprintf "%s is a beginner" player.Name | Standard (player, (PlayerId playerId), games) -> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required