IPython notebook backed by an F# kernel

Examples

In [1]:
"Last value displayed"
Out[1]:
val it : string = "Last value displayed"
In [2]:
errors are displayed
input.fsx(1,1): error FS0039: The value or constructor 'errors' is not defined

Utility Methods

In [3]:
Util.Html("<b>Inline HTML</b>") |> Display
Inline HTML
In [4]:
Util.Url("http://upload.wikimedia.org/wikipedia/en/9/93/FSharp_Logo.png") |> Display
In [5]:
Util.Math("f(x) = sin(x)") |> Display
$$f(x) = sin(x)$$
In [6]:
let data = [ ("F#", 10); ("C#", 5); ("C++", 20); ("Java", 1); ]
Util.Table(data) |> Display
Item1Item2
F#10
C#5
C++20
Java1

F# Charting

In [7]:
Chart.Bar(data) |> Display
In [8]:
Chart.Line(data) |> Display

Random things

In [9]:
let linspace (min : float, max : float, dx : float) =
    if min > max then failwith (sprintf "min [%f] cannot be greater than max [%f]" min max)
    if dx = 0.0 then failwith ("dx cannot be zero")
    
    let x = ref min
    seq {
        while !x < max do
            x := !x + dx
            yield !x
    }
In [10]:
let plot (data:seq<float>, cb) =
    let results = 
        seq {
            for x in data do
                yield (x, cb(x))
        }

    Chart.Line (results)
In [11]:
let x = linspace (-10.0, 10.0, 0.1)
plot(x, fun y -> sin(y)) |> Display
Util.Math "f(x) = sin(x)" |> Display
$$f(x) = sin(x)$$
In [12]:
(** This actually does animation when running *)
open System.Threading

for i in 1 .. 100 do

    Clear() |> ignore

    let x = linspace(-10.0 + float(i), float(i), 0.1) |> Seq.toArray
    let c1 = plot(x, sin)
    let c2 = plot(x, cos)

    Chart.Combine([c1; c2])
    |> Chart.WithSize(640, 480)
    |> Display
    |> ignore
    
    Thread.Sleep(20)