Showing posts with label FSharpx. Show all posts
Showing posts with label FSharpx. Show all posts

Monday, March 26, 2012

A Nice Addition to the Empty WPF F# Template

A few days ago Steffen Formann announced a Xaml type provider that he and Johann Deneux have created that makes writing WPF apps in F# very easy. This type provider allows strongly typed access to the XAML, effectively providing the missing piece to allowing full F# WPF designer support. I've now updated the Empty WPF F# Template to include this type provider.

To use it, all you have to due is download/install the latest version of the F# Empty Windows App (WPF) template in VS11. This will generate an F# project with all the needed WPF assembly references. It also automatically installs the FSharpx.TypeProviders NuGet package and provides the starting point for creating WPF apps with the new Xaml type provider.

Here's a screenshot that's pretty similar to what Steffen showed in the announcement post. Note: The button and label were manually added after creating the project from the updated template.


One other piece that can be helpful when creating WPF apps in F# is the XAML related item templates (i.e. Page, User Control, Window, etc). Item templates are provided via the F# XAML Item Templates extension found at http://visualstudiogallery.msdn.microsoft.com/06c6ece1-2084-4083-a0f7-934fce9d22fb.

Monday, January 16, 2012

developerFusion Article: An Introduction to FSharpx

My article entitled "An Introduction to FSharpx" was published a few days ago. You can find it at http://www.developerfusion.com/article/136179/an-introduction-to-fsharpx.

As mentioned in the article, FSharpx is continually evolving and several new features have been added since I submitted this article. Be sure to head over to the FSharpx GitHub site to see what's new.


Sunday, October 16, 2011

Two New F# 3.0 Type Provider Related NuGet Packages

There are two new NuGet packages available that can help you get started with authoring or consuming custom type providers. Both NuGet packages depend on the FSharpx.TypeProviders library that I wrote about in my last post and that Mauricio introduced in his most recent post.

FSharpx.TypeProviders.Sample:

The FSharpx.TypeProviders.Sample package provides an example of how to consume the custom type providers included in the FSharpx.TypeProviders library. The package adds a Test.config file as well as a F# source file that contains example code for using the TypedAppSettings type provider.

FSharpx.TypeProviders.DslSample:

The FSharpx.TypeProviders.DslSample package makes it easy to quickly get started with authoring a custom type provider. The package adds a F# source file that contains the source for a very simple custom type provider, a F# script file that can be used to test the custom type provider, and a batch file that makes it easy to do manual test/debug activities.

You may be curious about the commands in the batch file and why they are needed. Section 5.6 of the document on Writing F# 3.0 Type Providers that was provided by the F# team on 09/24/2011 includes development tips that make this more clear:

5.6.1 Run Two Visual Studio Instances. You can use one Visual Studio to develop the type provider. You can test it in another, since the test IDE will take a lock on the DLL preventing it being rebuilt. Thus, the second instance of Visual Studio must be closed while the provider is built in the first instance, and then reopened. 

5.6.2 Debug type providers by using invocations of fsc.exe. Type providers are invoked by 

- fsc.exe (The F# Command Line compiler)
- fsi.exe (The F# Interactive compiler)
- devenv.exe (Visual Studio)

Debugging type providers can often be easiest using fsc.exe on a test script file (e.g. script.fsx). This is because

- You can launch debug using a command-line prompt devenv /debugexe fsc.exe script.fsx - You can use print-to-stdout logging

I have tried both approaches and agree that the second is definitely the easiest. The .fsx and .bat files provided in this NuGet package make this approach even easier. Simply modify the code of the type provider, then test/debug by launching the batch file. Note: If/when changes to the Test.fsx file are required, it is recommended that these changes be made in an editor outside of Visual Studio.

Friday, October 7, 2011

Authoring Type Providers with the TypeProviderDSL from FSharpx

Several days ago, I submitted my AppSettings Type Provider to the FSharpx project. FSharpx is an open source library that adds a number of useful "functional constructs on top of the core F# library". I strongly encourage checking it out.

One of the many things in FSharpx that I find useful is the TypeProviderDSL. This is a DSL that sits on top of the ProvidedTypes module provided in the F# 3.0 Sample Pack. With this DSL and a few other helpers in FSharpx, the code from the AppSettings Type Provider that I showed in a previous post becomes easier to read. Plus, a few lines of code are shaved off in the process.

Let's look at a few of the features of the TypeProviderDSL that are used by the AppSettings Type Provider.

1. The erasedType function provides a simple way to create a ProvidedTypeDefinition.
2. The staticParameter function encapsulates the code needed to define a static parameter.
3. The literalField function makes it slightly easier to create a ProvidedLiteralField.
4. The addXmlDoc function provides a common way to add XML documentation.
5. Lastly, the |+> operator makes it very easy to add members.

Here's the end result:



You can get FSharpx.TypeProviders from the NuGet Gallery at http://www.nuget.org/List/Packages/FSharpx.TypeProviders and find the source on GitHub at https://github.com/fsharp/fsharpx/tree/TypeProviders.