Thursday, September 20, 2012

Adding NuGet Support to F# Interactive in VS2012

About a year ago, I posted an approach for adding basic NuGet support to VS2010. This post provides an updated script for adding this support in VS2012.

There may be times when you wish to use NuGet from the F# Interactive, such as when you are creating F# scripts. Since NuGet focuses on Visual Studio projects, this functionality is not supported out-of-the-box; however, it’s fairly simple to get things up and running.

The first step that we’ll need to do is create an F# script that is able to interact with the official NuGet package source. The script found here does the trick. I won’t spend too much time explaining the code in this script, but at a high level this allows you to use the F# Interactive window to talk to the NuGet package source, pull down packages, and automatically add a reference to the F# script file that has focus. 

The last step to accomplish our goal, is to tell F# Interactive to run our script each time that it launches. This is pretty easy to do thanks to the functionality provided by Visual Studio for adding F# Interactive options. To set the applicable option, go to Tools | Options | F# Tools | F# Interactive. You can then add the following information to the F# Interactive options setting.

--use:C:\temp\fsiext.fsx

 The F# Interactive options window looks like the following after making this change:


Once this is in place you can do something like this:

- Create a new F# Library project and build it. 
- Open the Script.fsx file.
- Navigate to the F# Interactive window.
- Execute InstallPackage “FSPowerPack.Core.Community”;; in the F# Interactive.

This will cause the package to be pulled down from the official NuGet repository and will automatically add the appropriate references to the Script.fsx file. 

Here's what the screen should look like after completing these steps.


Disclaimer: There are a few known issues with this approach.

Wednesday, September 12, 2012

F# Templates and F# Tools for VS2012 Express for Web

It's been a great day in the world of F# + web development. Today the F# team announced the F# Tools for Visual Studio 2012 Express for Web. This tool set now makes it easier than ever to create web applications that use F# for the server-side heavy lifting. Congrats to the F# team on this great accomplishment!

Currently, I've updated 4 of the more common F# web project templates to support this new version. These include:

- F# C# MVC 4 - Which includes ASP.NET MVC 4 (Razor and ASPX) and ASP.NET Web API
- F# C# ASP.NET MVC 3 - Which includes ASP.NET MVC 3 (Razor and ASPX)
- F# and C# Web Services (ASP.NET, WSDL)
- F# MsTest Project

Happy coding!

Monday, July 9, 2012

A Few New NoSQL Helper Libraries

I've been working on a few new libraries lately that focus on providing functional wrappers around various NoSQL options.

FSharpCouch:

FSharpCouch is something that I wrote about a little over two years ago. At the time, it was more of an educational exercise, but I have since revised it and found aspects of it to be useful. This is now available on NuGet as package ID FSharpCouch.

Here's an example:


You can find additional examples and the full source at https://github.com/dmohl/FSharpCouch.

MongoFs:

MongoFs currently has a primary focus on function composition as it relates to setting up the MongoDB client aspects of server, database, and collection. It simply wraps functions around the necessary methods of the C# Mongo Driver and auto opens the encompassing module.

Here's an example:


You can get it from NuGet as package ID MongoFs and find more examples and source at https://github.com/dmohl/MongoFs.

Thursday, July 5, 2012

CoffeeScript Presentation Now Available on InfoQ

The presentation that I did at Code PaLOUsa entitled CoffeeScript: Good, Bold, and with Sugar is now available on InfoQ at http://www.infoq.com/presentations/CoffeeScript-Good-Bold-and-with-Sugar.

You can find an HTML version of the slides here and various examples on my GitHub.

Sunday, June 24, 2012

Functional JavaScript with LiveScript, Mocha, and ExpectThat

I've been playing with LiveScript a bit lately and have really been enjoying it! If you haven't heard of LiveScript, it's a "...fork of Coco, which is in turn derived from CoffeeScript..."  (LiveScript Overview Page). It provides more features than Coco and CoffeeScript including several that assist in writing code in a more functional style.

Here's a quick example of a test written in LiveScript for Mocha and ExpectThat:

This shows off a couple of the features that help you write in a functional style with LiveScript. The first is the use of pattern matching within the isWeekend function. The second is the use of the pipe-forward operator when calling the isWeekend function.

The pattern matching syntax gives you a concise way of defining a basic switch statement in JavaScript. The pipe-forward operator allows you to compose things together. In the example above, the string 'sun' (which also could have been written in LiveScript as \sun) is being passed into the isWeekend function. This becomes even more powerful when the value to be passed into the next function is coming from another function, as shown in this example:

F# has these same concepts and many more, which makes LiveScript + F# a compelling combination!

There are a number of additional LiveScript features that assist in using a functional style. For more examples of LiveScript with Mocha and ExpectThat visit https://github.com/dmohl/expectThat/tree/master/example/mocha-LiveScript. To learn more about LiveScript, see a number of examples, and/or get setup for use, visit the LiveScript site at http://gkz.github.com/LiveScript/.

Saturday, June 16, 2012

CodeStock 2012 F# and CoffeeScript Presentations

Thanks to all who attended my talks at CodeStock this year!

You can find the CoffeeScript slides here and the examples on my GitHub.

The examples from the F# talk can be found here and the slides are provided below:

Monday, June 4, 2012

F#/C# ASP.NET MVC 4 Template for Visual Studio 2012 RC

The F#/C# ASP.NET MVC 4 template has been updated to support ASP.NET MVC 4 RC and Visual Studio 2012 RC. You will need to install the release candidate of ASP.NET MVC 4 to use this updated version of the template. The install can be found at http://www.asp.net/mvc/mvc4.

As with the previous release, the F#/C# ASP.NET MVC project template supports ASPX and Razor versions of an empty ASP.NET MVC 4 project template as well as a Razor version of the ASP.NET Web API project template. The templates work on both VS2010 and VS2012 RC.