Welcome to MSDN Blogs Sign in | Join | Help

F# Scripts--Zero to Execute in Ten Seconds

Jomo Fisher--F# is about conciseness. Consider the interview question that asks you to reverse a singly-linked-list. I’ve been asked this question twice in interviews and even the cleanest implementation in the interviewer’s chosen language was long and it was hard to show that I’d covered the corner cases. The F# answer is concise and self-evidently correct now that I’ve learned F# well enough:

// Take two lists, source and target, and append all the items from source

// to target in reverse order.

let rec AppendReverse source target =

    match source with

    | [] -> target

    | (head::tail) -> AppendReverse tail (head::target) 

// Call AppendReverse with the empty list for target.  

let Reverse list =

    AppendReverse list []

 

We’ve tried to bring this same philosophy of power and economy when integrating F# into Visual Studio. While F# does offer traditional MSBuild-based project support, sometimes you just want to write some code and not worry about projects and solutions. This is what F# scripts are for.

Once you have F# installed, you’re free to just start coding. These steps take about ten seconds:

-          Press Ctrl+N (new file) and select Script\F# Script File

 

-          In the opened .fsx file add:

System.Windows.Forms.MessageBox.Show("Hello")

 

-          One time only, press Ctrl+Alt+F to bring up the F# interactive window.

-          Press Ctrl+A (select everything) and then Alt+Enter (execute)

image

That’s it. We’ve tried to eliminate every piece of friction between you and the code you want to write.

We call these files scripts, but they’re not watered down in any way. They are actual F# which means they are compiled, statically typed and have access to .NET. There’s just not a project or even an explicit build step. In fact, this is one of the reasons F# needed a Visual Studio language service that can actively display errors and warnings as you type.

You can pick up the CTP of F# 1.9.6.0 here:  http://msdn.com/fsharp

 

This posting is provided "AS IS" with no warranties, and confers no rights.

Published Saturday, August 30, 2008 10:40 AM by Jomo Fisher

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# F# 1.9.6.0 Link Roundup

- Don's Announcement [ reddit ][ digg ] - F# Scripts -- Zero to Execute in Ten Seconds [ reddit ][ digg

Friday, August 29, 2008 2:59 PM by Jomo Fisher -- Sharp Things

# F# Releases September 2008 CTP!

Don Syme just announced today the F# Community Technical Preview (CTP) Release September 2008 which is

Saturday, August 30, 2008 1:18 AM by Matthew Podwysocki

# F# Releases September 2008 CTP!

Don Syme just announced today the F# Community Technical Preview (CTP) Release September 2008 which is

Saturday, August 30, 2008 1:20 AM by Matthew Podwysocki's Blog

# F# Releases September 2008 CTP!

Don Syme just announced today the F# Community Technical Preview (CTP) Release September 2008 which is

Saturday, August 30, 2008 1:55 AM by Community Blogs

# The F# September 2008 CTP is now available!

I’m very pleased to announce the availability of the F# September 2008 CTP Release , launched via the

Saturday, August 30, 2008 7:17 AM by Don Syme's WebLog on F# and Other Research Projects

# re: F# Scripts--Zero to Execute in Ten Seconds

Oh dear, how about:

template< class T >

T reverse( const T& other )

{

  return T( other.rbegin(), other.rend() );

}

That's the entire point of BCL has missed. On generics and so much more. F# leading nowhere too it seems.

Oh yes, did I say you have the same mechanics for COMPILE-TIME.

All this runtime nonsense is so off the mark, it is incredible it improved only so slightly on Java.. life goes on.

Saturday, August 30, 2008 9:10 AM by Qw

# re: F# Scripts--Zero to Execute in Ten Seconds

Hi Qw,

Thank you, I'd forgotten that I wanted to mention that in the real world you should just use the built in function:

   List.rev mylist

My code in the article is O(n) but why reinvent the wheel?

My code in the article is successful if it can show the power and expressiveness of F# language primitives.

Thanks!

Saturday, August 30, 2008 11:30 AM by Jomo Fisher

# The Weekly Source Code 34 - The Rise of F#

First, let me remind you that in my new ongoing quest to read source code to be a better developer ,

Thursday, September 25, 2008 5:43 AM by Readed By Wrocław NUG members

# re: F# Scripts--Zero to Execute in Ten Seconds

How can one add references to assemblies in a script?

Wednesday, December 03, 2008 12:27 PM by qwertie

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker