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 @"c:/packages/FSharpPlus.1.0.0-CI00099/lib/net45/FSharpPlus.dll" | |
open System | |
open FSharpPlus | |
// Validation definition | |
type Validation<'a,'e> = Success of 'a | Failure of 'e | |
with | |
// Validation is an instance of Applicative | |
static member inline Return x = Success x |
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 @"bin\Debug\FsControl.Core.dll" // from https://github.com/gmpl/FsControl | |
let inline return' x = Inline.instance FsControl.Core.TypeMethods.Applicative.Pure x | |
let inline (>>=) x (f:_->'R) : 'R = Inline.instance (FsControl.Core.TypeMethods.Monad.Bind, x) f | |
let inline mzero () = Inline.instance FsControl.Core.TypeMethods.MonadPlus.Mzero () | |
let inline mplus (x:'a) (y:'a) : 'a = Inline.instance (FsControl.Core.TypeMethods.MonadPlus.Mplus, x) y | |
module Monad = | |
open FsControl.Core.TypeMethods |
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
// FUNCTORS AND APPLICATIVES | |
//-------------------------- | |
// You may run this script step-by-step | |
// The order of execution has to be respected since there are redefinitions of functions and operators | |
// -------- | |
// FUNCTORS | |
// -------- |
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 @"C:\packages\FsControl.1.0.8\lib\net40\FsControl.Core.dll" | |
type Eval = Eval of int | |
let eval (Eval x) = x | |
// To define a Type Method we need to add at least 2 instances | |
type Eval' = Eval' of int | |
let eval' (Eval' x) = x | |
module ExpAlg = |
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 trampoline f c n = | |
let rec loop = function | |
| Choice1Of2 x -> x | |
| Choice2Of2 x -> loop (f x) | |
loop (Choice2Of2 (c,n)) | |
// Test | |
let factorial n = | |
let rec factorialT (current, n) = | |
if n = bigint 0 then Choice1Of2 current |
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 @"c:/packages/FsControl.1.0.9/lib/net40/FsControl.Core.dll" | |
open FsControl.Core.TypeMethods | |
open FsControl.Core.Types | |
open FsControl.Operators | |
type MonadBuilder() = | |
member inline b.Return(x) = result x | |
member inline b.Bind(p,rest) = p >>= rest | |
member b.Let (p,rest) = rest p |
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 "nuget: FSharpPlus,1.2" | |
open FSharpPlus | |
open FSharpPlus.Math.Generic | |
type Ratio = | |
struct | |
val Numerator : bigint | |
val Denominator : bigint | |
new (numerator: bigint, denominator: bigint) = {Numerator = numerator; Denominator = denominator} |
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
// Unfortunatelly it stopped working in F# 4.1 after this PR https://github.com/Microsoft/visualfsharp/pull/1650 | |
// Will ask to revert it | |
type FoldArgs<'t> = FoldArgs of ('t -> 't -> 't) | |
let inline foldArgs f (x:'t) (y:'t) :'rest = (FoldArgs f $ Unchecked.defaultof<'rest>) x y | |
type FoldArgs<'t> with | |
static member inline ($) (FoldArgs f, _:'t-> 'rest) = fun (a:'t) -> f a >> foldArgs f | |
static member ($) (FoldArgs f, _:'t ) = f |
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
// Based on http://nut-cracker.azurewebsites.net/blog/2011/11/07/functions-for-n-tuples/ | |
// Warning: This script has long compile times | |
// but as from F# 4.1 will work fine | |
// due to this fix: https://github.com/Microsoft/visualfsharp/pull/1682 in the compiler | |
open System | |
type Infinite<'a> = Infinite of 'a | |
module TupleInternalValues = |
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
(* Namespaces | |
TryParsers | |
WebLinq | |
WebLinq.Collections | |
WebLinq.Html | |
WebLinq.Sys | |
WebLinq.Text | |
WebLinq.Xml | |
WebLinq.Xsv |
OlderNewer