background preloader

F#

Facebook Twitter

An F# Ant Colony Simulation in Silverlight 4.0 with Dynamic ... I’ve been enviously watching Phillip Trelford publish excellent F# games all week and tonight I just couldn’t stand it anymore.

An F# Ant Colony Simulation in Silverlight 4.0 with Dynamic ...

I stayed in, rolled up my sleeves and ported the very same ant colony simulation I used in my CUFP workshop to Silverlight 4.0. Wow, just look at those little guys go at it. Silverlight sure is pretty! As you might have noticed by the big white “Click To Load Custom AI” message, you can also compile your own AI and battle it out with what I’ve included here. To make things easy I’ve provided a ready to go solution. Performance-related features in F# and C# Lorenz attractor. The Lorenz attractor is a fractal derived from the trajectory of a 3-dimensional dynamical system that exhibits chaotic flow.

Lorenz attractor

This blog post describes a 35-line program that computes trajectories of this attractor and visualizes them as a beautiful whisp using Windows Presentation Foundation: The program is as follows: > #r "PresentationCore.dll";; > #r "PresentationFramework.dll";; > #r "WindowsBase.dll";; > #r "System.Xaml.dll";; > let trajectory f (x, y, z) dt n = let s, b, p = 10.0, 8.0 / 3.0, 28.0 let mutable x = x let mutable y = y let mutable z = z let a = Array.zeroCreate n for i=0 to n-1 do a. SEO Analysis in F#, a friendly application. Last time, we provided the components to actually make the SEO helpers into a real application.

SEO Analysis in F#, a friendly application

This time, we make the application more friendly. In particular : default files and directories are created if they don’t exist yet. Then, instead of being forced to use a command window, this time, double clicking will suffice. This will also allow us to see how to use events and Winforms (yup, no WPF !) , and how to use functions to make form building a tad quicker. Generically Constraining F# Generic constraints inside .NET has always been a fun enterprise, especially given how C# handles them There has been some discussion on Jon Skeet’s blog about the fact that C# does not allow for generic constraints referring to a number of types.

Generically Constraining F#

These include: System.Array System.Delegate System.Enum System.Object System.ValueType This is indeed a bit unfortunate, as it limits some of the more interesting applications. The example Jon shows is indeed illegal in C#: F#: Pipelined Monads. #light type Definition = unit type internal ModelResultCatch<'T> =

F#: Pipelined Monads

Units of Measure in F#: Part One. Do you remember NASA's Mars Climate Orbiter?

Units of Measure in F#: Part One

It was lost in September 1999 because of a confusion between metric and so-called "English" units of measurement. The report into the disaster made many recommendations. Catamorphisms, part one. (Read this blog entry at a pace which is appropriate for you.

Catamorphisms, part one

Some readers will find this mostly old-hat, whereas others will find it rough going at parts. I encourage you to take a break and try out the code examples, if that helps you out.) I would like to discuss catamorphisms. A catamorphism is a generalization of a fold on lists to an arbitrary data type. Correct by Construction in F# Correct by Construction in F# Jomo Fisher—a theme in the design of the F# language is that problems in the code are revealed as compilation errors.

Correct by Construction in F#

Consider this C# code which is used to compose a courteous letter to a customer: enum Courtesy { Mr, Ms, Dr } Using computation expressions to control monitor locks.