Rash thoughts about .NET, C#, F# and Dynamics NAV.


"Every solution will only lead to new problems."

Monday, 6. December 2010


Sudoku solver in F#

Filed under: F#,Kata — Steffen Forkmann at 15:07 Uhr

On my flight to the US I had a small competition with my dad. He was solving a Sudoku and I tried to write a generic solver in the same time. I admit he was a little bit faster but anyway I put my code on github.

Tags: ,

Wednesday, 24. November 2010


Aufzeichnung meines Vortrages zu Higher-Order-Functions in C# verfügbar

Filed under: Informatik,Veranstaltungen,WebCasts — Steffen Forkmann at 15:12 Uhr

Letzte Woche habe ich im Rahmen der F# Gruppe der .NET Online User Group einen Vortrag zu “Higher-Order-Functions in C#†gehalten. Unter http://vimeo.com/17048170 ist die Aufzeichnung nun zu finden.

Funktionale Programmiersprachen nehmen seit geraumer Zeit einen hohen Stellenwert in der Wissenschaft ein. Mittlerweile ziehen viele der funktionalen Konzepte bereits in den Mainstream ein. Bei diesem Treffen wollen wir einen Einblick in funktionale Konzepte und deren Umsetzung in C# gewinnen. Insbesondere soll auf "Funktionen höherer Ordnung", "Pattern Matching", "Unveränderlichkeit" und parallele Programmierung eingegangen werden.

Vortragsabstract

Tags: ,

Tuesday, 9. November 2010


Erstes Treffen der .NET Online User Group war schon ein Erfolg

Filed under: Online User group — Steffen Forkmann at 8:57 Uhr

Björn Rochel live Gestern hat Björn Rochel mit seinem Vortrag zum Thema Rhino.ServiceBus den aktiven Start der .NET Online User Group vollzogen. Mit 28 Teilnehmern war dies (trotz einiger technischer Probleme bei mir als geplantem Co-Moderator) schon ein voller Erfolg. Wenn die nächsten Treffen auch so in der Art stattfinden, dann kann die NOUG (Twitter-Hashtag #NOUG) echt etwas Großes werden. Danke an alle die mitmachen und der NOUG in so kurzer Zeit schon ein Gesicht und Struktur geben.

Björn hat aus seinem Vortrag auch schon eine geniale weiterführende Idee für die NOUG entwickelt. In einer "Build your own CQRS"-Gruppe will er gemeinsam mit anderen Interessierten eine vollständige Implementierung einer CQRS – Beispielanwendung vorantreiben.

Nächsten Montag hat dann die F#-Gruppe ihr Kick-Off-Meeting. Ich würde mich über viele interessierte Teilnehmer freuen. Bei diesem Treffen wollen wir einen ersten Einblick in funktionale Konzepte gewinnen. Insbesondere soll auf "Funktionen höherer Ordnung", "Pattern Matching", "Unveränderlichkeit" und parallele Programmierung eingegangen werden. Damit wir uns nicht zu sehr in Diskussionen zur F#-Syntax verfangen wollen wir dies beim ersten Treffen in C# probieren. Damit wir auch ein möglichst interaktives Treffen hinbekommen wäre ein Mikrofon und im Idealfall auch eine Webcam nicht schlecht. 😉

Wichtige Links:

[Das Bild habe ich schamlos von DerAlbert geklaut.]

Tags: , , ,

Thursday, 4. November 2010


.NET Online User Group gegründet

Filed under: Coding Dojo,F#,Online User group — Steffen Forkmann at 19:24 Uhr

Nach einigen Diskussionen und Anregungen auf Twitter und einer konstitutionellen Skype-Session (zwischen DerAlbert, Björn Rochel und mir) wurde heute die “.NET Online User Group†gegründet.

Ziele und Einordnung der Gruppe

Unter dem Deckmantel dieser Gruppe wollen wir versuchen möglichst oft und regelmäßig Online-Treffen für .NET-Entwickler aus dem deutschsprachigen Raum zu organisieren.
Die Online User Group sieht sich damit keinesfalls als Konkurrenz zu den bereits bestehenden lokalen User Groups. Wir stellen uns dabei eher vor durch ein breites Angebot an Formaten und das große Einzugsgebiet auch in speziellere Themen tief reinschauen zu können, die bei den lokalen Gruppen aufgrund der heterogenen Interessen eher vermieden werden.

Gruppen

So ist es z.B. geplant Gruppen zu bilden, die sich zu bestimmten “Randgruppenâ€-Themen ganz intensiv austauschen können. Den Anfang machen wir mit einer F# Gruppe, deren Ziel es ist die Sprache F# im Speziellen und Funktionale Programmierung im Allgemeinen detailliert zu beleuchten. Beim ersten Treffen am 15.11. wollen wir uns mit “Funktionen höherer Ordnung†beschäftigen.

Jede der Gruppen wird min. einen Paten haben. Die Aufgabe des Paten ist es als Ansprechpartner zu fungieren und Termine zu koordinieren. Das soll aber nicht heißen, dass der Pate bei jedem Treffen selbst einen Vortrag halten soll.

Kurzfristige Treffen

In letzter Zeit ist es des Öfteren vorgekommen, dass einige Themen auf Twitter oder in Newsgroups plötzlich sehr intensiv diskutiert wurden. Wir wollen mit der User Group nun auch eine Kommunikationsplattform bieten, die in der Lage ist kurzfristig in einem direkteren Rahmen über solche Themen zu diskutieren. Wir können uns dabei gut vorstellen, dass spontan verabredet wird (z.B. über Twitter) sich am Abend zu einem bestimmten Thema über die Kanäle der User Group (insbesondere LiveMeeting) zu unterhalten.

Coding Dojo

Auch das bereits etablierte Online Coding Dojo mit Albert Weinert und Ilker Cetinkaya wird ab jetzt unter der Flagge der .NET Online User Group durchgeführt werden. Der erste Termin hierfür ist der 18. November.

Klassische Vorträge

Aber auch Vorträge wird es bei der .NET Online User Group geben. Zum jetzigen Zeitpunkt stehen bereits 4 Termine fest:

Weitere Schritte

Um die .NET Online User Group ordentlich anlaufen lassen zu können benötigen wir natürlich jede Menge Hilfe:

  • Bitte helft uns die User Group bekannt zu machen. Twitter, Email, Blogs, Briefe, Faxe, TV-Spots, persönliche Kommunikation usw.
  • Bitte registriert euch auf der Webseite der User Grouo
  • Bitte schlagt Vorträge vor
  • Bitte nennt uns Themenwünsche und Ideen
  • Bitte meldet euch freiwillig als Paten für bestimmte Untergruppen bzw. Themenbereiche
  • Bitte schlagt uns vor wie ihr sonst noch helfen könnt 😉
Tags: , ,

Wednesday, 3. November 2010


Running specific targets in "FAKE – F# Make"

Filed under: F# — Steffen Forkmann at 8:44 Uhr

This article has been moved to http://fsharp.github.io/FAKE/specifictargets.html

Tags: , ,

Wednesday, 12. May 2010


“FAKE – F# Make” 1.20.0 released

Filed under: F#,FAKE - F# Make — Steffen Forkmann at 12:26 Uhr

Today I released a new bugfix release for “FAKE – F# Makeâ€. We fixed some path and logging issues and as a new feature we introduced the @@ operator which allows to combine paths.

Tags: , ,

Tuesday, 24. November 2009


Generating an IObservable<T> from an IEvent in F#

Filed under: F# — Steffen Forkmann at 12:39 Uhr

Yesterday I showed how we can map some of the Rx operators to an API which looks more like the F# base classes. Today I wanted to use these mapped operators in a WPF-application written in F#.

F# gives us a nice way to use events as first class citizen (via IEvent) but these events implement their own version of IObservable<T> (in FSharp.Core.dll), which is unfortunately incompatible with the Rx version and therefore with the mapped API.

The solution I found is to wrap the F# IEvent with a Rx IObservable<T>:

/// Generates an observable from an IEvent

let fromEvent (event:IEvent<_,_>) =      

  Observable.Create<_>(fun x ->

    event.Subscribe x.OnNext |> ignore

    new System.Action(fun () -> ()))     

Now we are able to use the WPF events as observables:

// Register ListBox Commands

listBox1.KeyDown

  |> Observable.fromEvent

  |> Observable.filter (fun args -> args.Key = Key.Delete)

  |> Observable.subscribe deleteElement

I am interested if someone has a different and maybe better solution to this problem.

Updated: 21.12.2009 – Observable.Context is no longer supported by Rx ==> Removed

Tags: ,

Monday, 23. November 2009


Mapping the Reactive Framework (Rx) operators for F#

Filed under: F# — Steffen Forkmann at 13:35 Uhr

The “Reactive Extensions for .NET (Rx)†comes with lot’s of operators for using IObservable<T>. This code mimics the signature of the default F# sequence combinators and allows to use observables like sequences. It is a similar approach like Matthews Podwysocki’s blog post about mapping the IParallelEnumerable.

I will update this post from time to time to include more of the operators.

  • Update: 25.11.2009 – new operators mapped
  • Update: 21.11.2009 – Updated to new Rx release

module RxExtensions.Observable

 

open System.Linq

open System

open System.Threading

open System.Windows.Threading

 

type ‘a observable = IObservable<‘a>

type ‘a observer = IObserver<‘a>

 

/// converts a lambda in a System.Action

let asAction f = new System.Action(f)

 

/// System.Action whichs does nothing

let doNothing = asAction (fun () -> ())

 

/// Creates an observer

let createObserver next error completed =

  {new System.IObserver<_> with

      member this.OnCompleted() = completed()

      member this.OnError(e) = error e

      member this.OnNext(args) = next args}

 

/// Creates a new observable

let create f =

  Observable.Create<_>(fun x ->

    f x

    doNothing)  

 

/// Creates a observable from a async

let ofAsync async =

  create

    (fun obs ->

       Async.StartWithContinuations

         (async,obs.OnNext,obs.OnError,obs.OnError))

 

/// Gets a dispatcher Schdeuler for the current dispatcher

let getDispatcherScheduler _ =

  new DispatcherScheduler(Dispatcher.CurrentDispatcher)

 

/// Generates an observable from an IEvent

let fromEvent (event:IEvent<_,_>) = create (fun x -> event.Add x.OnNext)

 

/// Generates an empty observable

let empty<‘a> = Observable.Empty<‘a>()

 

/// Takes the head of the elements

let head = Observable.First

 

/// Merges the two observables

let mergeWith obs1 obs2 = Observable.Merge(obs2, obs1)

 

/// Merges all observables

let mergeAll (observables:IObservable<IObservable<‘a>>) =

  Observable.Merge observables

 

/// Merges all observables

let merge (observables:(IObservable<‘a>) seq) =

  Observable.Merge observables

 

/// Creates a range as an observable

let range start count = Observable.Range(start, count)

 

/// Converts a seq in an observable

let toObservable (seq: ‘a seq) = Observable.ToObservable seq

 

/// Converts a observable in a seq

let toEnumerable = Observable.ToEnumerable

 

/// Subscribes to the Observable with all 3 callbacks

let subscribeComplete next error completed (observable: ‘a observable) =

   observable.Subscribe(

     (fun x -> next x),

     (fun e -> error e),

     (fun () -> completed()))

 

/// Subscribes to the Observable with a

/// next and an error-function

let subscribeWithError next error observable =

  subscribeComplete next error (fun () -> ()) observable

 

/// Subscribes to the Observable with just a next-function

let subscribe next observable =

  subscribeWithError next ignore observable

 

/// throttles the observable for the given interval

let throttle interval observable =

  Observable.Throttle(observable,interval)   

 

/// throttles the observable scheduled on the current dispatcher

let throttleOnCurrentDispatcher interval observable =

  Observable.Throttle(

     observable,getDispatcherScheduler(),interval)

 

/// samples the observable at the given interval

let sample interval observable =

  Observable.Sample(observable,interval)   

 

/// samples the observable at the given interval

/// scheduled on the current dispatcher

let sampleOnCurrentDispatcher interval observable =

  Observable.Sample(

    observable,getDispatcherScheduler(),interval)

 

/// returns the observable sequence that reacts first.

let takeFirstOf2Reactions obs1 obs2 =

  Observable.Amb(obs1,obs2)

 

/// returns the observable sequence that reacts first.

let amb (obs: IObservable<‘a> seq) =

  Observable.Amb obs  

 

/// returns the observable sequence that reacts first.

let takeFirstReaction (obs: IObservable<‘a> seq) =

  Observable.Amb obs  

 

/// Matches when both observable sequences

/// have an available value.

let both obs1 obs2 = Observable.And(obs1,obs2)

 

/// Merges two observable sequences

/// into one observable sequence.

let zip obs1 obs2 =   

   Observable.Zip(obs1, obs2, Func<_,_,_>(fun a b -> a, b))

 

/// Merges two observable sequences into one observable sequence

/// whenever one of the observable sequences has a new value.

///    ==> More results than zip

let combineLatest obs1 obs2 =   

   Observable.CombineLatest(

     obs1, obs2, Func<_,_,_>(fun a b -> a, b))    

 

/// Concats the two observables to one observable

let concat observable =

  Observable.SelectMany(

    observable,

    Func<_,_>(fun (x:IObservable<‘a>) -> x))

 

/// maps the given observable with the given function

let map f observable =

  Observable.Select(observable,Func<_,_>(f))  

 

/// maps the given observable with the given function

let mapi f observable =

  Observable.Select(observable,Func<_,_,_>(fun x i ->f i x))  

 

/// Filters all elements where the given predicate is satified

let filter f observable =

  Observable.Where(observable, Func<_,_>(f))

 

/// Splits the observable into two observables

/// Containing the elements for which the predicate returns

/// true and false respectively

let partition predicate observable =

  filter predicate observable,

  filter (predicate >> not) observable

 

/// Skips n elements

let skip n observable = Observable.Skip(observable, n)

 

/// Skips elements while the predicate is satisfied

let skipWhile f observable =

  Observable.SkipWhile(observable, Func<_,_>(f))

 

/// Runs all observable sequences in parallel

/// and combines their first values.

let forkJoin (observables: (‘a observable) seq) =

  Observable.ForkJoin observables

 

/// Counts the elements

let length = Observable.Count

 

/// Takes n elements

let take n observable =

  Observable.Take(observable, n)  

 

/// Determines whether the given observable is empty 

let isEmpty observable = Observable.IsEmpty observable

 

/// Determines whether the given observable is not empty 

let isNotEmpty observable = not (Observable.IsEmpty observable)

 

/// Determines whether an observable sequence

/// contains a specified value

/// which satisfies the given predicate

let exists predicate observable =

  observable

    |> skipWhile (predicate >> not)

    |> isNotEmpty

 

/// Continues an observable sequence that is terminated

/// by an exception with the next observable sequence.

let catch (newObservable:IObservable<‘a>) failingObservable =

  Observable.Catch(failingObservable,newObservable) 

 

/// Takes elements while the predicate is satisfied

let takeWhile f observable =

  Observable.TakeWhile(observable, Func<_,_>(f))

 

/// Iterates through the observable

/// and performs the given side-effect

let perform f observable =

  Observable.Do(observable,fun x -> f x)

 

/// Invokes finallyAction after source observable

/// sequence terminates normally or by an exception.

let performFinally f observable =

  Observable.Finally(observable,fun _ -> f())

 

/// Folds the observable

let fold f seed observable =

  Observable.Aggregate(observable, seed, Func<_,_,_>(f))  

 

/// Retruns an observable from a async pattern 

let fromAsync beginF endF =

   Observable.FromAsyncPattern<_>(

     Func<_,_,_>(fun x y -> beginF(x,y)),

       (fun x -> endF x)).Invoke()

 

/// Runs all observable sequences in parallel

/// and combines their first values.

let subscribeAll next observables =

  observables |> Seq.map (subscribe next) |> Seq.toList     

 

type IObservable<‘a> with

  /// Subscribes to the Observable with just a next-function

  member this.Subscribe(next) =

    subscribe next this

 

  /// Subscribes to the Observable with a next

  /// and an error-function

  member this.Subscribe(next,error) =

    subscribeWithError next error this

 

  /// Subscribes to the Observable with all 3 callbacks

  member this.Subscribe(next,error,completed) =

    subscribeComplete next error completed this

 

open System.Net

 

type WebRequest with

  member this.GetRequestStreamAsync() =

    fromAsync

     this.BeginGetRequestStream

     this.EndGetRequestStream

 

  member this.GetResponseAsync() =

    fromAsync

      this.BeginGetResponse

      this.EndGetResponse

 

  member this.GetResponseStreamAsync() =

    fromAsync

      this.BeginGetRequestStream

      this.EndGetRequestStream

 

type Async<‘a> with

  member this.ToObservable() = ofAsync this

Tags: , , ,

Tuesday, 6. October 2009


“FAKE – F# Make” Version 0.10 released

Filed under: F#,FAKE - F# Make — Steffen Forkmann at 11:59 Uhr

I just released a new version of my Open Source Build Automation Framework “FAKE – F# Makeâ€. You can read more about FAKE on the project website or in the Getting started with "FAKE – F# Make"-article.

Although the new release contains many bugfixes, I only want to show the two major improvements here.

1. FAKE 0.10 uses FSI instead of FSC

From now on FAKE uses the “F# Interactive†(fsi.exe) instead of the F# Compiler (fsc.exe) to run the build scripts, which brings two major improvements.

No TempPath for compiled binaries needed

Due to the fact that FAKE scripts are no longer compiled at the beginning of the build process, we don’t need a temporary folder for the created binaries.

Loading modules at runtime

The #load command in F# scripts allows us to load modules at runtime. Now we are able to put reusable Targets or TargetTemplates (see below) into external build script files.

2. TargetTemplates

TargetTemplates provide an easy way to reuse common Targets. Let’s consider a (very) small sample:

Target "TraceHello" (fun () ->

  trace "Hello World from FAKE"

)

This Target “TraceHello†traces a “Hello World†string into our build log. Now we want it to be slightly more generic and to trace a custom string. We can do this by using a TargetTemplate:

/// createTraceTarget: string -> string -> Target

let createTraceTarget = TargetTemplate (fun s ->

  trace s

)

Now we have a template (or a function which generates targets) that gets a string for the target name and a string for the trace text and generates  a usable target:

createTraceTarget "TraceHello" "Hello World from FAKE"

createTraceTarget "Trace2" "Trace another text"

Of course the TargetTemplate function is generic and can be used with any tuple as parameter:

/// createTraceTarget: string -> string*int -> Target

let createTraceTarget = TargetTemplate (fun (s,d) ->

  trace s

  trace <| sprintf "my int: %d" d

)

 

createTraceTarget "TraceHello" ("Hello World from FAKE",2)

createTraceTarget "Trace2" ("Trace another text",42)

Tags: , , ,

Wednesday, 15. April 2009


Integrating a “FAKE – F# Make” build script into TeamCity

Filed under: F#,FAKE - F# Make,Tools,Visual Studio — Steffen Forkmann at 11:00 Uhr

This artile has been moved to http://fsharp.github.io/FAKE/teamcity.html

Tags: , , , , , , ,