Skip to content

Instantly share code, notes, and snippets.

@gusty
gusty / Validation.fsx
Last active January 6, 2018 10:18 — forked from mausch/Validation.fsx
Applicative Validation easy with F#+
#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
@gusty
gusty / QueenSongs.linq
Created November 4, 2016 12:36
Sample WebLinq query. All Queen songs from Wikipedia.
(* Namespaces
TryParsers
WebLinq
WebLinq.Collections
WebLinq.Html
WebLinq.Sys
WebLinq.Text
WebLinq.Xml
WebLinq.Xsv
@gusty
gusty / Functors and Applicatives.fsx
Last active December 29, 2015 06:39
Functors and Applicatives.
// 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
// --------
@gusty
gusty / Program.fsx
Last active December 28, 2015 12:39 — forked from zecl/Program.fsx
#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
@gusty
gusty / zipIndex.fsx
Last active August 29, 2015 14:01
Solve stack overflow in zipIndex function.
#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
#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 =