Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 3 comments about this article.
Article source: CoDe (2008 Sep/Oct)


Article Pages:  1  2 3 - Next >


F# 101

F#, the latest member of the Visual Studio family of languages, offers some enticing advantages over C# and Visual Basic, stemming from its functional-object fusion nature. Originally a research language from Microsoft Research, F# has long been a “secret weapon” in the arsenal of .NET programmers for doing statistical- and mathematical-heavy coding. More recently, however, a growing number of developers have begun to see the inherent advantages implicit in writing functional code, particularly in the areas of concurrency. The buzz has begun to approach interesting levels, particularly on the heels of an announcement last year from the head of the Microsoft Developer Division, Somasegar, that F# would be “productized” and fully supported by Microsoft as a whole, suddenly removing the stigma and licensing restrictions that surround research projects.

One of the more recent ideas that’s sweeping the industry is the notion of “domain-specific languages,” (DSLs) whereby a developer builds a language that others (typically either skilled knowledge workers/subject matter experts, or sometimes even other programmers) will use to solve the particular business problems facing them. As Neal Ford describes, two different kinds of DSLs permeate the space: internal DSLs, built on top of an existing language’s syntax, and external DSLs, built in some of the same ways that languages like C# and Visual Basic are, with a parser, abstract syntax tree to store the parsed code, and either an interpreter to run the resulting program or a code generator to turn it into an executable program.

"
F# espouses several core key ideas: namely that static typing is a good safeguard to writing good code so long as the type information can stay out of the programmer’s way (also known as type inferencing), that functions are values and have first-class semantics right alongside integers and strings, that shared and/or mutable state should be minimized (if not avoided outright), and that functional design permits and encourages composition and substitutability.
"

As it turns out, F#, being derived from a long line of functional languages, has many of the tools necessary to make it easy to create simple external DSLs: discriminated unions, pattern matching, and combinatorial processing, all of which will probably be meaningless terms to the reader who’s never ventured outside of the object-oriented realm before. In this article, I’ll go over the basic syntax of F#, paying close attention to both those concepts that closely mirror that of the traditional O-O languages, as well as those that are brand new to the C#/VB programmer. While it’s entirely unreasonable to expect to master the F# language (or any non-trivial language) in a single column, by the end of this, F# should at least be recognizable and readable, leading the .NET programmer into diving more deeply into F# if and when appropriate.

Concepts

F# is a CLR-adapted version of the Object-CAML language, also known as OCaml. As a functional language, F# espouses several core key ideas, namely that static typing is a good safeguard to writing good code so long as the type information can stay out of the programmer’s way (also known as type inferencing), that functions are values and have first-class semantics right alongside integers and strings, that shared and/or mutable state should be minimized (if not avoided outright), and that functional design permits and encourages composition and substitutability (which is where F# and other functional languages get much of their reputation for being “mathematical” languages).

Some of these concepts are more subtle than it may seem at first; for example, type inferencing means less explicit code needed to make the compiler happy, which in turn not only means that you can express the same concepts in less code in F#, but also that much of the verbosity of generics in C# effectively “fall away” when writing similar code in F#.

Before going too deeply into a more conceptual discussion, a quick glance at some F# code may help put a framework around some of these ideas.

Setup

Before any F# coding can take place, you must install the F# binaries. As of this writing, F# still resides on the Microsoft Research Web site, the latest version is 1.9.4.17 and is most easily found via the F# Web site there-simply visit http://research.microsoft.com/fsharp/fsharp.aspx and find the latest release link from the announcements column on the right-hand side (the actual download URL changes with each release).

When installed, F# will not only put several executables, assemblies, and assorted samples into the installation directory, but will also register its Visual Studio language service support. This registration gives the F# developer much the same development experience as the C# or VB developer, with an added bonus: an extra tool window called interactive mode, which allows the F# developer to type some F# code and execute it immediately, much as the Immediate Window works in the debugger. Simply “swipe” some code from the editor window with the mouse, hit Alt-Enter, and the text will be automagically pasted and executed in the Interactive Window. (This is by far the easiest way to explore the language and its concepts.) Note that the F# package will also install into the Visual Studio Isolated Shell, so programmers who don’t have a copy of the commercial Visual Studio bits can still play along.

Assuming F# has installed successfully, fire up Visual Studio, create a new F# Project (under the “Other Project Types” node), add a new item (“F# Source file”), and call it file1.fs (the default). Notice that when you open the new file, the compiler populates it with a large number of F# example snippets, which serve as an easy way of getting started with the language. Have a look at the code in that template file later; for now, delete it all and replace it with the following code: F#’s version of the ubiquitous “Hello world” program:

#light

let language = "F#"
printfn "Hello, %A" language

Congratulations! You are now an F# programmer.

&

By: Ted Neward

Ted Neward is a Principal Consultant with ThoughtWorks, a global consulting firm focusing on .NET, Java and Ruby enterprise development. He is an internationally recognized speaker, instructor, consultant, and mentor and spends a great deal of time these days focusing on languages and execution engines like the JVM and CLR.

ted@tedneward.com

Fast Facts

F# is a functional programming language for the CLR based on another functional/object language, OCaml.



Article Pages:  1  2 3 - Next Page: '“Let” There Be F#' >>

Page 1: F# 101
Page 2: “Let” There Be F#
Page 3: Matchmaker, Matchmaker, Bind Me a Match

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.7 out of 5

31 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      Sharepoint TechCon

 

SSWUG