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
package eventsourcing | |
import java.time.Instant | |
import cats._ | |
import cats.data.Coproduct | |
import cats.free.{Free, Inject} | |
import cats.implicits._ | |
import doobie.imports._ | |
import fs2.Stream |
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 First = | |
{ Name: string | |
Items: string list } | |
type Second = | |
{ Name: string | |
Numbers: int list } | |
open FSharpPlus |
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
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs" | |
type Continuation<'output, 'next> = 'output -> 'next | |
module TerminalDsl = | |
open Chessie.ErrorHandling | |
type Terminal<'next> = | |
| WriteLine of string * Continuation<unit, 'next> | |
| ReadLine of unit * Continuation<string, 'next> |
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 Control.Monad.Eff.Alt where | |
import Control.Bind (bind) | |
import Control.Monad.Eff.Exception (Error) | |
import Partial.Unsafe (unsafeCrashWith) | |
import Prelude (liftA1, class Functor, class Applicative, class Monad, ap, class Apply, class Bind, class Show, Unit) | |
-- This illustrates an alternative way to use the type system to model | |
-- effects, where the effects type is a "regular" type, and the effects |
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
// So called van Laarhoven lenses, named after their discoverer, have a number | |
// of nice properties as explained by Russell O'Connor: | |
// | |
// http://r6.ca/blog/20120623T104901Z.html | |
// | |
// Unfortunately their typing (in Haskell) | |
// | |
// type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t) | |
// | |
// seems to be well outside of what can be achieved in F#. |
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
// This F# language suggestion wants a way to name collections of constraints: | |
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/8509687-add-constraints-as-a-language-construct | |
// | |
// This is a type alias X<T> = T, so X<int> = int etc. | |
type X<'T> = 'T | |
// This is a type alias X<T> = T which adds a constraint | |
type WithStruct<'T when 'T : struct> = 'T |
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
Option Explicit | |
' MSubstitute is like the SUBSTITUTE function of Excel except it allows | |
' multiple substitutions at once. It replaces all occurrences of texts in the | |
' first column of SubstitutionsRange in Text with the corresponding text in | |
' second column. | |
Public Function MSubstitute(ByVal Text As String, _ | |
ByVal SubstitutionsRange As Range, _ | |
Optional ByVal IgnoreCase As Boolean = True) As String |
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
#I @"g:\prg\Fleece\Fleece\bin\Release\" | |
#r @"FsControl.Core.dll" | |
#r @"FSharpPlus.dll" | |
#r @"System.Json.dll" | |
#r @"ReadOnlyCollectionsInterfaces.dll" | |
#r @"ReadOnlyCollectionsExtensions.dll" | |
#r @"Fleece.dll" | |
open System | |
open System.Collections.Generic |
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
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 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
// Install http://www.nuget.org/packages/Fleece | |
open Fleece | |
open FSharpPlus | |
let json = """{ | |
"1": "one", | |
"2": "two", | |
"3": "three" | |
}""" |