Archive for the ‘Functional programming’ Category

World’s first F# web browser runs on Linux using Gtk and WebKit

Saturday, July 11th, 2009

After a long break I finally managed to do some programming for fun. This time I decided to see what WebKit has to offer and at the same time create the world’s first browser written in F#. I whipped it up in a couple of hours and the the whole experience was highly enjoyable, thanks to F#’s succinct syntax and WebKit’s and Gtk#’s easy APIs. In fact it got me so positively wound up that I’ve put shampoo on my toothbrush and then I didn’t remember if I washed my hair already. The only thing missing was MonoDevelop with full F# support, but that I guess, will happen sooner or later. I would also love to see MS finally release F# under Ms-PL so that I could use it for something actually useful. Anyway, here’s a screenshot:

Compiled binary is here, but good luck getting it to run. Source code it here.
If you decide to run it, I would recommend doing that on Ubuntu Karmic (9.10 alfa 2). When I run that on 9.04 it crashes and I think that an older version of WebKit is responsible for that.

More fun with Gtk# and Cairo in F#

Wednesday, December 3rd, 2008

This time it has taken me more than I planned but I finally have something to show off.

As usual the compiled exe here and the full code here.

This week I have really struggled to figure out how to mix functional and imperative concpets. After a few days of trying to recursively build an F# list I gave up and resorted to using a ResizeArray<> which is simply an equivalent of C# List<>. I really wonder if a bit more “functional” way of building a list is possible.

Another F# sunday

Sunday, November 23rd, 2008

So, another weekend, another F# excercise. This time I decided have some fun with Cairo inside Gtk# and a port of the old Knockout example from C# seemed like a prefect idea. Here’s what I got:

Compiled executable here, code here. Now, what I’ve done was pretty much a simple “translation” to get it running but I would love to make the code really functional. So, go headed and comment on what I could change to do it.


Another embarrassing udpate: fixed indentation


Update 2: indentation is broken by Wordpress editor. Code replaced with a link.

Playing with F#

Sunday, November 16th, 2008

This little pretty window:

is a result of this tiny bit of F# code:

#light

open System
open Gtk

Application.Init()

let window = new Gtk.Window(“F# Gtk”)
let vBox = new Gtk.VBox()
let closeButton = new Gtk.Button()
let label = new Gtk.Label(“Hello World!”)

window.WindowPosition < – Gtk.WindowPosition.Center
window.SetDefaultSize(160, 40)
window.Destroyed.Add(fun _ -> Application.Quit() )

closeButton.Label < – “Close”
closeButton.Clicked.Add(fun _ -> Application.Quit() )

vBox.BorderWidth < – (uint32) 6
vBox.PackStart(label, false, false, (uint32) 6)
vBox.PackStart(closeButton, false, false, (uint32) 6)

window.Add(vBox)
window.ShowAll()

//brown paperbag update: I’ve missed this line during Copy/Paste
Application.Run()

Next step is piece of code that actually does something semi-useful. I’m thinking about implementing a convex hull algorithm which F# seems pretty well suited for.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes