Skip to content

Instantly share code, notes, and snippets.

@gusty
gusty / SixDependencyApproachesInPractice.fsx
Last active February 28, 2023 09:42 — forked from swlaschin/SixDependencyApproachesInPractice.fsx
Code examples from fsharpforfunandprofit.com/posts/dependencies-5/
(* ===================================
Code from my series of posts "Six approaches to dependency injection"
=================================== *)
open System
(*
## The requirements
@gusty
gusty / io-monad.fsx
Last active May 28, 2019 07:20 — forked from isaacabraham/io-monad.fsx
F# port of the first half of John De Goes "FP to the max" (https://www.youtube.com/watch?v=sxudIMiOo68)
#load @".paket\load\net452\FSharpPlus.fsx"
open FSharpPlus
open System
[<AutoOpen>]
module SideEffects =
let private r = Random()
let printLn text = async { printfn "%s" text }
let readLn() = async { return Console.ReadLine() }
+--------------------+--------------------+-------------------------+--------------------+
|Operation           | F#+ / F#           |F#+ Haskell Compatibility|Haskell             |
+====================+====================+=========================+====================+
|List.append         | @                  |                         | ++                 |
+--------------------+--------------------+-------------------------+--------------------+
|Function composition| f << g             | f . (g)                 | f . g              |
+--------------------+--------------------+-------------------------+--------------------+
|                    | <|                 | $                       | $                  |
+--------------------+--------------------+-------------------------+--------------------+
@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 / 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