This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Position = | |
| Property of string // name of the property | |
| Station of string // name of the station | |
| Chance | |
| CommunityChest | |
| FreeParking | |
| GoToJail | |
| Jail | |
| Tax of int // amount of tax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let printName position = | |
match position with | |
| Property(propertyName) -> sprintf "Property '%s'" propertyName // prints "Property 'Old Kent Road'" | |
| Tax(amount) -> sprintf "Tax of £%d" amount // prints "Tax of £100" | |
| CommunityChest -> sprintf "Community Chest" | |
// etc.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let calculateMove position = | |
match position with | |
| GoToJail -> Some Jail // option type - some Position, in this case Jail | |
| Chance -> randomChancePosition // draws a random Chance card which may or may not be a movement card | |
| CommunityChest -> randomCommunityChestPosition // as above | |
| _ -> None // return nothing back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let roll currentPosition dice = | |
let position = currentPosition |> moveBy dice // return new position, do not mutate current position | |
printfn "Landed on %s" (printName position) | |
match calculateMove position with | |
| Some(movedTo) -> printfn "Moved to %s" (printName movedTo) | |
movedTo | |
| None -> position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MachineLearning | |
open System | |
open System.IO | |
let public TRAINING_DATA = "digitssample.csv"; | |
let public LIVE_DATA = "digitscheck.csv" | |
type RawScribble = { Number:int; Pixels:int[] } | |
type Scribble = { Number:int; PixelData:int[][] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let createAgent() = | |
let tokenSource = new System.Threading.CancellationTokenSource() | |
Agent.Start((fun inbox -> async { | |
printfn "spun up a new agent..." | |
while true do | |
let! data = inbox.Receive() | |
let! result = // Do some async work here... | |
match result with | |
// Everything done, we can cancel | |
| AllDone -> printfn "completed!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Raw Add method | |
public static int Add(Tuple<int, int> numbers) | |
{ | |
return numbers.Item1 + numbers.Item2; | |
} | |
static void Main(string[] args) | |
{ | |
// Memoized version of Add | |
var add = Memoize<Tuple<int, int>, int>(Add); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Raw add function | |
let add (x,y) = x + y | |
// Memoized version | |
let add = memoize add | |
add (5,10) // Adding (5,10) to cache | |
add (5,10) // Cache hit for (5,10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Service | |
{ | |
OtherService GetOtherService(); | |
} | |
public interface OtherService | |
{ | |
Int32 GetNumber(); | |
} |
OlderNewer