This file contains hidden or 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
| open System.Drawing | |
| let (|RGB|) (col : System.Drawing.Color) = | |
| ( col.R, col.G, col.B ) | |
| let (|HSB|) (col : System.Drawing.Color) = | |
| ( col.GetHue(), col.GetSaturation(), col.GetBrightness() ) | |
| let printRGB (col: System.Drawing.Color) = | |
| match col with |
This file contains hidden or 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
| namespace global | |
| open System | |
| open System.Linq | |
| namespace ExploreCsharpEight | |
| type IndicesAndRanges() = | |
| member val private words = [|"The"; "quick"; "brown"; "fox"; "jumped"; "over"; "the"; "lazy"; "dog"|] with get, set | |
| member this.Syntax_LastIndex() = | |
| Console.WriteLine (sprintf "The last word is %O" this.words.[(int (* ERROR UnknownPrefixOperator "^" *))]) | |
| 0 | |
| member this.Syntax_Range() = |
This file contains hidden or 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
| namespace global | |
| namespace ConsumerVehicleRegistration | |
| type Car() = | |
| member val Passengers = Unchecked.defaultof<int> with get, set | |
| namespace CommercialRegistration | |
| type DeliveryTruck() = | |
| member val GrossWeightClass = Unchecked.defaultof<int> with get, set | |
| namespace LiveryRegistration | |
| type Taxi() = |
This file contains hidden or 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
| namespace global | |
| open System | |
| open System.Collections.Generic | |
| open System.Threading.Tasks | |
| namespace ExploreCsharpEight | |
| type AsyncStreams() = | |
| member this.GenerateSequence() = | |
| do | |
| let mutable (i : int) = 0 | |
| while (i < 20) do |
This file contains hidden or 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
| namespace global | |
| open System | |
| open System.Collections.Generic | |
| open System.Linq | |
| open System.Text | |
| open System.Threading.Tasks | |
| open System.IO | |
| open System.Diagnostics | |
| namespace File_Encoder | |
| type Encoder() = |
This file contains hidden or 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
| namespace global | |
| open System | |
| open System.Collections.Generic | |
| open System.Linq | |
| open System.Text | |
| open System.Threading.Tasks | |
| open System.IO | |
| open System.Diagnostics | |
| namespace File_Encoder | |
| type Program() = |
This file contains hidden or 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 ConstructionAttribute(singleInstance : bool) = | |
| inherit System.Attribute() | |
| member this.IsSingleton = singleInstance | |
| let singletons = new System.Collections.Generic.Dictionary<System.Type,obj>() | |
| let make() : 'a = | |
| let newInstance() = System.Activator.CreateInstance<'a>() | |
| let attributes = typeof<'a>.GetCustomAttributes(typeof<ConstructionAttribute>, true) | |
| let singleInstance = | |
| if attributes.Length > 0 then |
This file contains hidden or 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 DealResult = { | |
| Card : Card option | |
| Deck : Deck | |
| } | |
| let dealACard deck = | |
| match deck with | |
| | [] -> { Card = None; Deck = deck } | |
| | card::restOfDeck -> { Card = Some card; Deck = restOfDeck } |
This file contains hidden or 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
| #r "System.Data.Linq" | |
| open System | |
| open System.Reflection | |
| open System.ComponentModel | |
| open System.Linq.Expressions | |
| open Microsoft.FSharp.Reflection | |
| open Microsoft.FSharp.Quotations | |
| module FSharpType = |
This file contains hidden or 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 Cache (reader: 'key -> 'value) max = | |
| let cache = new Dictionary<'key,LinkedListNode<'key * 'value>>() | |
| let keys = new LinkedList<'key * 'value>() | |
| fun (key : 'key) -> ( | |
| let found, value = cache.TryGetValue key | |
| match found with | |
| |true -> | |
| keys.Remove value | |
| keys.AddFirst value |> ignore |