Monthly Archives: September 2010

Interactive Session #10: List, Array, Sequence

F# supports three different list-like data structures to store values of the same type: List, Array and Sequence. In this session we want to explore the similarities and differences among these three types. First lets instantiate values of each of … Continue reading

Posted in Getting Started, Language | 1 Comment

Interactive Session #9: Processing XML

Reading and interpreting XML data is performed through the System.Xml package. You need to create a new XmlDocument value and load the XML text into the XmlDocument. > open System.Xml;; > let txt = “<drawing><line><x>10.0</x><y>20.0</y><dx>50.0</dx> <dy>50.0</dy></line><circle><x>50.0</x><y>50.0</y><r>20.0</r> </circle></drawing>”;; val txt : … Continue reading

Posted in Getting Started, GUI, IO, Text | 1 Comment

Interactive Session #8: Pipeline Operator

The pipeline operator |> is a quite unique feature of F#, it allows to connect functions which take one argument together by passing the result of one function to the next. > let add1 x = x+1.0;; val add1 : … Continue reading

Posted in Algorithms, General, Language | Leave a comment

Interactive Session #7: Text file I/O

Binary and text file access is provided through the module System.IO. The type File provides static methods to create, open, read and write files. File.CreateText creates a new file (if it exists already content is overwritten) in text mode. > … Continue reading

Posted in Getting Started, IO, Text | Leave a comment

Interactive Session #6: Winforms SplitContainer

The SplitContainer allows to add two forms separated by a bar to another form. First we need a form again. > open System.Windows.Forms;; > let f = new Form();; val f : Form = System.Windows.Forms.Form, Text: > f.Visible <- true;; … Continue reading

Posted in Getting Started, GUI | Leave a comment

Parallel mandelbrot generator

F# offers very good support for implementing algorithms in a parallel way to exploit multi-core processors. The following example of a mandelbrot generator uses a lot of F# specific features using operator overloading to create a complex type, the async … Continue reading

Posted in Algorithms, Parallel | Leave a comment

Interactive Session #5: Creating and editing image files

Image manipulation is provided through the System.Drawing package. To create drawings you need to create a bitmap first. > open System.Drawing;; > let bitmap = new Bitmap(10, 10);; val bitmap : Bitmap You may edit the bitmap directly by setting … Continue reading

Posted in GUI, IO | Leave a comment

Interactive Session #4: Command Line Arguments

The command line arguments are provided as a list of string. As usual the first element (index 0) is the path of the program itself. > System.Environment.GetCommandLineArgs();; val it : string [] = [|”/usr/local/lib/FSharp-2.0.0.0/bin/fsi.exe”|] Read more here: Environment.GetCommandLineArgs

Posted in Getting Started | Leave a comment

Interactive Session #3: user input

Reading input from the console is performed using the Readline function. > open System;; > let s = Console.ReadLine();; howdy   val s : string = “howdy” Values can be converted with the respective conversion function: > let pi = … Continue reading

Posted in Getting Started | Leave a comment

Interactive Session #2: printing

Printing in F# is very similar to the famous printf function in C/C++. > printf “Hello World\n”;; Hello World val it : unit = () (* Alternatively printfn appends a newline automatically *) ;; > printfn “Hello again”;; Hello again … Continue reading

Posted in Getting Started | Leave a comment