Discover the power of F# by writing a complete card-shuffling program in only 92 lines of code.
by Seth Livingston
January 12, 2009
hen attempting to learn a new computer language, it's difficult to find a problem that's both interesting enough to bother working with and also simple enough to let you concentrate on language rather than logic. Fortunately, it turns out you can learn a lot about F# with a deck of playing cards. This article shows how to create a simple F# application that shuffles a deck and displays the cards in the console window. Along the way you'll explore:
Discriminated unions
Tuples
Lists and list sequence expressions
Functions and recursion
Pattern matching and functional polymorphism
What You Need
The minimum requirement for following along with the code is this article is Microsoft F# Interactive, delivered as part of the Microsoft F# download package available on MSDN. F# Interactive runs in a console window and compiles and runs F# commands interactively. However, the recommended setup is Visual Studio 2008 (or later) with Microsoft F# installed. If you don't have the full version of Visual Studio 2008, you can install the free Visual Studio 2008 Shell (Integrated Mode). After installing the Visual Studio Shell, install Microsoft F#.
Getting Started
Visual Studio gives you the option to create F# applications and class libraries, and has an integrated window running F# Interactive. F# will eventually be available as a standalone Visual Studio Express Edition product.
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!