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 [<Measure>] seconds | |
type Interval = { Name: string; Duration: int<seconds>; Elapsed : int<seconds> } | |
type Interval with | |
member x.Remaining = x.Duration - x.Elapsed | |
type Workout = { Name: string; Intervals : Interval list } | |
type Workout with | |
member x.WorkoutTime = x.Intervals |> Seq.sumBy (fun x -> x.Duration) |
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
namespace TibcoMessagePoster.Model | |
type FixField<'a>(fieldName, fieldId, validator : ('a -> bool)) = | |
member self.FieldName = fieldName | |
member self.FieldId = fieldId | |
member self.Validator = validator | |
new(fieldName, fieldId) = FixField(fieldName, fieldId, fun _ -> true ) | |
type FixHeaderFields = | |
static member ApplVerId = FixField("ApplVerId", "1128", fun str -> str = "9") |
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
namespace MvvmCrossTests.Core.FSharp | |
open System | |
open Cirrious.MvvmCross.ViewModels | |
open Microsoft.FSharp.Quotations | |
open Microsoft.FSharp.Quotations.Patterns | |
// One way of accessing the name of an expression that can be passed to the RaisePropertyChanged is |
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
(* Maybe Monad *) | |
(* | |
Taken from FSharpX: | |
https://github.com/fsprojects/fsharpx/blob/master/src/FSharpx.Core/ComputationExpressions/Monad.fs | |
*) | |
type MaybeBuilder() = | |
member this.Return(x) = Some x | |
member this.ReturnFrom(m: 'T option) = m | |
member this.Zero() = None | |
member this.Bind(m, f) = Option.bind f m |
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
(* Duck Typing *) | |
let inline flyAndWalk arg = | |
let flying = ( ^a : (member Fly : unit -> string) arg) | |
let walking = ( ^a : (member Walk : unit -> string) arg) | |
(flying, walking) | |
type Duck() = | |
member this.Swim() = "paddling" | |
member this.Fly() = "flapping" |
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
(* Events *) | |
type ClassWithEvent() = | |
let event1 = new Event<_>() | |
[<CLIEvent>] | |
member this.Event1 = event1.Publish | |
let clsWithEvent = ClassWithEvent().Event1.Add ( fun arg -> printfn "Argg" ) | |
let viaReactive = ClassWithEvent().Event1 |> Observable.subscribe( fun arg -> printfn "Arrgg" ) |
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
(* Agents *) | |
type CounterMessage = | |
| Update of float | |
| Reset | |
let inbox = MailboxProcessor.Start(fun agent -> | |
// Function that implements the body of the agent | |
let rec loop sum count = async { | |
// Asynchronously wait for the next message |
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
// Demo of how to convert an non-standard event into an Observable Sequence | |
// by using the Observable.FromEvent overload that uses a conversion Function. | |
public class SomeObservableClass | |
{ | |
public delegate void SettingChangedEventHandler(object sender, string setting); | |
public event SettingChangedEventHandler SettingChanged; | |
} | |
void Main() |
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 IInterface = | |
abstract theFunc : unit -> string | |
let init = | |
{ new IInterface with | |
member x.theFunc() = "Impl" | |
} | |
printfn "%s" <| init.theFunc() |
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 ComplexTypes = | |
let backgroundTypes = | |
dict [ ("Buy", "Blue") | |
("Sell", "Red") | |
("My", "Green") | |
("Their", "Yellow") ] | |
let stringFormatTypes = | |
dict [ ("Price", "#.##") | |
("Qty", "#.0") ] |
OlderNewer