2 people like it.

F# Koan Setup

Setup Code for Online F# Koans

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
//Click the Run button to begin!

let __ = "FILL ME IN"

type FILL_ME_IN =
    class end

open System.Windows
open System.Collections
open System.Windows.Controls
open System.Windows.Media
open Microsoft.TryFSharp

type Result =
    | Success
    | Failure of string

let displayResult (result:Result) =
    App.Console.ClearCanvas()
    App.Console.ClearOutput()
    App.Console.CanvasPosition <- CanvasPosition.Right

    let canvas = App.Console.Canvas
    canvas.Background <- new SolidColorBrush(Color.FromArgb(byte 225, byte 170, byte 170, byte 170))

    let grid = new Grid()
    grid.Height <- canvas.ActualHeight
    grid.Width <- canvas.ActualWidth
    canvas.Children.Add grid
    
    let border = new Border()
    border.Margin <- Thickness 7.0
    border.CornerRadius <- CornerRadius 2.0
    border.BorderThickness <- Thickness 5.0
    border.HorizontalAlignment <- HorizontalAlignment.Center
    border.VerticalAlignment <- VerticalAlignment.Center
    grid.Children.Add border


    let stackPanel = new StackPanel()
    stackPanel.Margin <- Thickness 29.0
    stackPanel.Orientation <- Orientation.Vertical
    stackPanel.HorizontalAlignment <- HorizontalAlignment.Center
    stackPanel.VerticalAlignment <- VerticalAlignment.Center

    border.Child <- stackPanel
    
    let outcome = new TextBlock(FontSize = 32.0)
    outcome.HorizontalAlignment <- HorizontalAlignment.Center
    stackPanel.Children.Add outcome

    match result with
    | Success -> 
        outcome.Text <- "Success!"
        border.BorderBrush <- new SolidColorBrush(Colors.Green)
        border.Background <- new SolidColorBrush(Color.FromArgb(byte 225, byte 0, byte 170, byte 0))
    | Failure text ->
        outcome.Text <- "Failure:"
        border.BorderBrush <- new SolidColorBrush(Color.FromArgb(byte 225, byte 170, byte 0, byte 0))
        border.Background <- new SolidColorBrush(Color.FromArgb(byte 225, byte 226, byte 0, byte 0))
        let error = new TextBlock(FontSize = 19.0, TextWrapping = TextWrapping.Wrap)
        error.Text <- text
        stackPanel.Children.Add error

let AssertEquality (x:'a) (y:'b) = 
    let result = 
        match box x with
        | :? IEnumerable as x -> match box y with | :? IEnumerable as y->
            let x = Seq.cast<obj> x
            let y = Seq.cast<obj> y

            let result = Seq.compareWith (fun x y -> if x.Equals(y) then 0 else 1) x y
            0 = result
        | _ -> x.Equals(y)

    if result then
        App.Dispatch (fun () -> displayResult Success)
    else
        let message = sprintf "Expected %A, but received %A instead" x y
        App.Dispatch (fun () -> displayResult (Failure message))
        failwith message

App.Dispatch (fun () -> App.Console.ClearOutput())
App.Dispatch (fun () -> App.Console.LoadFromUrl("http://fssnip.net/raw/bG"))
type FILL_ME_IN

Full name: Script.FILL_ME_IN
namespace System
namespace System.Windows
namespace System.Collections
namespace Microsoft
type Result =
  | Success
  | Failure of string

Full name: Script.Result
union case Result.Success: Result
Multiple items
union case Result.Failure: string -> Result

--------------------
active recognizer Failure: exn -> string option

Full name: Microsoft.FSharp.Core.Operators.( |Failure|_| )
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val displayResult : result:Result -> 'a

Full name: Script.displayResult
val result : Result
val canvas : obj
Multiple items
val byte : value:'T -> byte (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.byte

--------------------
type byte = System.Byte

Full name: Microsoft.FSharp.Core.byte
val grid : obj
val border : obj
val stackPanel : obj
val outcome : obj
union case Result.Failure: string -> Result
val text : string
val error : obj
val AssertEquality : x:'a -> y:'b -> 'a0 (requires equality)

Full name: Script.AssertEquality
val x : 'a (requires equality)
val y : 'b
val result : bool
val box : value:'T -> obj

Full name: Microsoft.FSharp.Core.Operators.box
type IEnumerable =
  member GetEnumerator : unit -> IEnumerator

Full name: System.Collections.IEnumerable
val x : IEnumerable
val y : IEnumerable
val x : seq<obj>
module Seq

from Microsoft.FSharp.Collections
val cast : source:IEnumerable -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.cast
type obj = System.Object

Full name: Microsoft.FSharp.Core.obj
val y : seq<obj>
val result : int
val compareWith : comparer:('T -> 'T -> int) -> source1:seq<'T> -> source2:seq<'T> -> int

Full name: Microsoft.FSharp.Collections.Seq.compareWith
val x : obj
val y : obj
System.Object.Equals(obj: obj) : bool
val message : string
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith

More information

Link:http://fssnip.net/bF
Posted:12 years ago
Author:Chris Marinos
Tags: f# koans