Jupyter notebook backed by an F# kernel

Examples


In [1]:
"Last value displayed"


Out[1]:
"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
Out[3]:
<null>

In [5]:
Util.Url("http://fsharp.org/img/logo/fsharp256.png") |> Display


Out[5]:
<null>

In [7]:
Util.Math("f(x) = sin(x)") |> Display


$$f(x) = sin(x)$$
Out[7]:
<null>

In [8]:
let data = [ ("F#", 10); ("C#", 5); ("C++", 20); ("Java", 1); ]
Util.Table(data) |> Display


Item1Item2
F#10
C#5
C++20
Java1
Out[8]:
<null>

F# Charting


In [9]:
1+11


Out[9]:
12

In [11]:
//#load "FSCharting.Gtk.fsx" // Mac/Linux
#load "FSCharting.fsx" // Windows

In [12]:
FSharp.Charting.Chart.Bar(data) |> Display


Out[12]:
<null>

In [13]:
FSharp.Charting.Chart.Line(data) |> Display


Out[13]:
<null>

Random things


In [14]:
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 [15]:
let plot (data:seq<float>, cb) =
    let results = 
        seq {
            for x in data do
                yield (x, cb(x))
        }

    FSharp.Charting.Chart.Line (results)

In [16]:
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)$$
Out[16]:
<null>

In [17]:
(** 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)

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


Out[17]:
<null>

In [ ]: