A Twitter search client in 10 lines of code with F# and the JSON type provider
Live tweets from Alea.cuBase F#-for-financial-GPU event in London.
Yesterday, there was Alea.cuBase live coding session. Don Syme led live tweets from inside. This post is dedicated to those who missed it.
I’ll be live tweeting from the .NET in the City event where Daniel Egloff presents F# for GPGPU quantalea.net/news/29/
— Don Syme (@dsyme) May 16, 2013
Continue reading ➞ Live tweets from Alea.cuBase F#-for-financial-GPU event in London.
F# Weekly #19, 2013
Welcome to F# Weekly,
Tiny weekly this time, a short roundup of F# content from this past week:
News
- Node.js + C# + F# + Python + PowerShell interop ===
#edgejs - Enjoying interactive data visualization with Tsunami by Taha Hachana
- F#-based quantum algorithms simulator was presented at Niels Bohr Institute last week.
- Call F# async workflows from node.js.
- New FSharpx version was released with fixes in the Excel type provider.
- R Type Provider is on Nuget now.
- GestIT is a C# library for gestures (ready for F#). (Here is a video of using LeapMotion sensor for playing Jetpack)
Videos/Presentations
- The first wave of Evolve sessions videos were posted.
- “Slackless gears with licorice video” by Semasiographologist.
- “Debugging CUDA Written in F#! (First Try)” by Xiang Zhang.
- “F# for Trading” by Phil Trelford.
Blogs
- Vatro published “Ping your boss“.
- Faisal Waris posted “Sample Mobile Web App Presented at #mobidevday“.
- Phil Trelford wrote about “Fixed Width Data Files“.
- Alex Young shared “VimSpeak: Control Vim with Speech Recognition“.
- Experiences using F# for developing analysis scripts and tools over search engine query log data.
- Don Syme blogged “F# for Machine Learning – a Gentle Introduction and Coding Dojo“.
- Marko Apfel posted “Productive work environments for F# development (under windows)“.
P.S. The top 20 data visualisation tools
That’s all for now. Have a great week.
Previous F# Weekly edition – #18
@sergey_tihon Lastest results for json.net using the most recent versions off NuGet twitter.com/JamesNK/status…
— James Newton-King ♔ (@JamesNK) May 12, 2013
Json.Net vs ServiceStack.Text
I can not understand why JSON.NET so popular (http://www.servicestack.net/mythz_blog/?p=344)
Or maybe I am wrong and picture have changed ?
@sergey_tihon Lastest results for json.net using the most recent versions off NuGet twitter.com/JamesNK/status…
— James Newton-King ♔ (@JamesNK) May 12, 2013
Need to test it!
F# Weekly #18, 2013
A roundup of F# content from this past week:
News
- F# projects on Google Summer of Code.
- Ross McKinlay proposed an idea for new Type Provider.
- Learn how F# is central to Microsoft’s ground-breaking Quantum Algorithms research.
-
F#-based quantum algorithms simulator presented at Niels Bohr Institute last week
- A very early public beta release of Tsunami IDE is available now.
Videos/Presentations
- “Domain-driven design with F# and EventStore” by Lev Gorodinski.
- “F# for Trading” by Phillip Trelford.
- FP Days Cambridge 2012 Content on InfoQ.
Blogs
- Phil Trelford posted “Examples!“.
- Jack Pappas shared “How to use the fsharp REPL when debugging C# code in Visual Studio“.
- Colin Bull wrote about “Option Operators“.
- Mathias Brandewinder blogged “Recommendation Engine using Math.NET, SVD and F#“(!!!super hot!!!)
- Lev Gorodinski wrote “Domain-Driven Design (DDD) With F# – Validation“.
- TechRepublic posted “CodePaLOUsa: Humanitarian Toolbox, F#, open source licensing, happiness“.
- Marko Apfel introduced “SharpDevelop, F#, missing “Send to F# Interactive” context menu“.
- Anton Kropp wrote “Capturing union values with fparsec“.
- Don Syme blogged “IEEE Computer Society Webinar: Try F# for Big and Broad Data – Tuesday May 7“.
- Richard Dalton wrote “Learning To Think Functionally: Back To Basics“.
- Anton Kropp posted “The largest mass problem“.
- Gene Belitski shared “If Google would be looking to hire F# programmers – part3“.
-
Gene Belitski shared “If Google would be looking to hire F# programmers – part4“.
- Mike Harris blogged “Philosophy of Programming“.
- Dave Thomas posted “I Node Something (Bout You)“.
That’s all for now. Have a great week.
Previous F# Weekly edition – #17
F# Weekly #17, 2013
A roundup of F# content from this past week:
News
- F# community on Google+.
- Fantomas is moving fast: web project is ready and VS add-in is in progress.
- Taha Hachana presented F# syntax highlighting tool.
- Google+ discussion on an F# Resharper plugin.
- Benchmarking F# async http proxy on Mono on Azure.
- “Integrating stock data into the F# language” is new to F# Deep Dives.
Videos
- “Mono, Open Source, Visual Studio, and Xamarin” by Miguel de Icaza.
- “F# embedded in Excel“(part 1 and part 2) by Matt Moloney and Adam Mlocek. (slides)
- “F# MVC for WPF” by Dmitry Morozov. (slides)
- “MathSharp turn MathML into code” by ActiveMesa.
- “Reasonable codewithfsharp” slides by Michael Falanga
Blogs
- John Liao posted “Exploring Riak with F#“.
- Visual Studio Magazine posted “iOS Development with Xamarin.iOS and Visual Studio“.
- Gene Belitski presented “A Tale of Two Functions“.
- Bryan Edds wrote “Aml – A Modular Language written in F# and available for .NET“.
- Mike Harris shared “Finding Perfect Numbers“.
- Sergey Tihon announced “New selectors with Canopy 0.7.3“.
- Anton Kropp wrote “A response to “Ten reasons to not use a functional programming language”“.
- Don Syme blogged “F# and QuantLib: An Introduction“.
- Hao Lian posted “Dive into parser combinators: parsing search queries with F# and FParsec in Kiln“.
- Gene
Belitski shared “If Google would be looking to hire F# programmers – part1“.
- Gene
Belitski shared “If Google would be looking to hire F# programmers – part2“.
- Taha Hachana wrote “Fantomas support in the Tsunami IDE“.
- Don Syme blogged “Miguel de Icaza discusses Xamarin support for F# on Channel 9“.
- Sergey Tihon posted “Neo4jClient new Cypher Start notation & F# Extra Top Level Operators“.
- John Liao shared “Exploring Riak with F# and CorrugatedIron“.
- Phil Trelford wrote “Foq It Easy“.
- InfoQ published “Develop Financial Applications with F# and QuantLib“.
- Sergey Tihon blogged “WPF MVVM with Xaml Type Provider“.
- Ashley Nathan Feniello posted “Memoization“.
- Richard Dalton wrote “Learning To Think Functionally – Stuck“.
- Phil Trelford shared “Fractal Zoom in Colour“.
- Mike Harris posted “Primality by Trial Division OR TDD Example in F# using FsUnit“.
That’s all for now. Have a great week.
Previous F# Weekly edition – #16
Mike Falanga speaks about Discriminated Unions at Cleveland F# SIG
do the needful, write about it, simple
I was able to record the Cleveland F# SIG, where Mike Falanga spoke about F# language’s Discriminated Unions feature (http://msdn.microsoft.com/en-us/library/dd233226.aspx).
Here are the videos I took of the event for all attendees that weren’t able to make it:
View original post 283 more words
WPF MVVM with Xaml Type Provider
About a year ago XAML type provider (that now a part of fsharpx project) was born. First of all, happy birthday XAML type provider and thank you everyone who was involved.
Up to XAML type provider release the best option for F# WPF development was to split app into two parts: C# project with all XAML stuff for best tooling support and F# project with all source code. Daniel Mohl have created a project template “F# and C# Win App (WPF, MVVM)” that illustrates this approach end to end (read more about this in his blog).
XAML type provider is an amazing thing that makes available full-featured WPF development completely in F#. Steffen Forkmann has an excellent blog post about its usage “WPF Designer for F#“. It is probably one of my favorite posts about F# at all, it shows a real beauty and excellence of the technology. This approach was already templated by Daniel Mohl – “F# Empty Windows App (WPF)“.
I think that a natural desire is to have an F# MVVM app using XAML type provider. It can be done by combining these two templates. At the first step, create a new project from “F# Empty Windows App (WPF)” template, and leave App.fs file without any changes.
module MainApp open System open System.Windows open System.Windows.Controls open FSharpx type MainWindow = XAML<"MainWindow.xaml"> let loadWindow() = let window = MainWindow() window.Root [<STAThread>] (new Application()).Run(loadWindow()) |> ignore
Now we need to define a ViewModel for MainWindow. I have reused BaseViewModel and RelayCommand from polyglot approach template.
namespace ViewModels open System open System.Windows open System.Windows.Input open System.ComponentModel type ViewModelBase() = let propertyChangedEvent = new DelegateEvent<PropertyChangedEventHandler>() interface INotifyPropertyChanged with [<CLIEvent>] member x.PropertyChanged = propertyChangedEvent.Publish member x.OnPropertyChanged propertyName = propertyChangedEvent.Trigger([| x; new PropertyChangedEventArgs(propertyName) |]) type RelayCommand (canExecute:(obj -> bool), action:(obj -> unit)) = let event = new DelegateEvent<EventHandler>() interface ICommand with [<CLIEvent>] member x.CanExecuteChanged = event.Publish member x.CanExecute arg = canExecute(arg) member x.Execute arg = action(arg) type MainViewModel () = inherit ViewModelBase() let mutable name = "Noname" member x.Name with get () = name and set value = name <- value x.OnPropertyChanged "Name" member x.OkCommand = new RelayCommand ((fun canExecute -> true), (fun action -> MessageBox.Show(sprintf "Hello, %s" x.Name) |> ignore))
The last and probably most tricky part is a XAML. Pay attention to the row number four (local namespace definition). You need to specify assembly part even if your view model located in the same assembly as XAML. It happens because type provider works in another one.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ViewModels;assembly=FsharpMVVMWindowsApp"
Title="MVVM and XAML Type provider" Height="120" Width="300">
<Window.DataContext>
<local:MainViewModel></local:MainViewModel>
</Window.DataContext>
<Grid >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label FontSize="16">What is your name?</Label>
<TextBox Grid.Row="1" FontSize="16" Text="{Binding Name, Mode=TwoWay}"/>
<Button Grid.Row="2" FontSize="16" Command="{Binding OkCommand}">Ok</Button>
</Grid>
</Window>
Voila, it works now.

Neo4jClient new Cypher Start notation & F# Extra Top Level Operators
Some weeks ago a new version of Neo4jClient was released. There were introduced some changes in the Cypher Start notation. The new Start notation for sure has become nicer for C#, but it is still a bit ugly for F#. Recommended way of using new Start notation are anonymous classes that do not supported in F#.
The one reasonable option is to use dictionary-like interface, which in C# looks in the following way:
graphClient
.Cypher
.Start(new Dictionary<string, object>
{
{ "foo", nodeRef },
{ "bar", otherNodeRef }
});
We need to create IDictionary<string,obj> object somehow. Luckily, F# has a set of Extra Top Level Operators one of which is dict that does exactly what we need. The last thing what we need to do is to box dictionary values to convert them to obj.
dict : seq<'Key * 'Value> -> IDictionary<'Key,'Value> (requires equality) box : 'T -> obj
Some examples:
let getById (queryObject:'T when 'T :> NeoEntity) =
client.Cypher
.Start(dict ["n", box(sprintf "node(%d)" (queryObject.Id))])
.Return<Node<'T>>("n")
.Results
let simpleConnection connectionType (target:Node<_>) (source:Node<_>) =
client.Cypher
.Start(dict [("n", box(source.Reference)); ("m", box(target.Reference))])
.CreateUnique(sprintf "n-[:%s]->m" connectionType)
.ExecuteWithoutResults()
Update: Start notation supports wide range of possible object references:
graphClient
.Cypher
.Start(dict [
("n1", box "custom");
("n2", box nodeRef);
("n3", box Node.ByIndexLookup("indexName", "property", "value"));
("n4", box Node.ByIndexQuery("indexName", "query"));
("r1", box relRef);
("moreRels", box [|relRef; relRef2|]);
("r2", box Relationship.ByIndexLookup("indexName", "property", "value"));
("r3", box Relationship.ByIndexQuery("indexName", "query"));
("all", box All.Nodes)
])


