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: 
//Click the run button to begin!

let __ = "FILL ME IN"

type FILL_ME_IN =
    class end

open System.Windows
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 225, 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) = 
  if x.Equals(y) then
      App.Dispatch (fun () -> displayResult Success)
  else
      App.Dispatch (fun () -> displayResult (Failure <| sprintf "Expected %A, but received %A instead" x y))

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 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
System.Object.Equals(obj: obj) : bool
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf

More information

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