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
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
// helpers to iterate IDiaEnum* objects | |
let inline toSeq (o: ^T) = | |
let e = { new IEnumerable with member this.GetEnumerator () = (^T: (member GetEnumerator: unit -> _) (o)) } | |
if true then | |
Seq.cast e | |
else | |
// Dummy expression to constrain return type to that of o.Item | |
seq [| (^T: (member Item: _ -> _) (o, Unchecked.defaultof<_>)) |] |
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 Event = | |
open System.Threading | |
let concat (source: IEvent<IEvent<_,_>>) = | |
let event = new Event<_>() | |
source.Add (Event.listen event.Trigger) | |
event.Publish | |
let collect f = | |
Event.map f >> concat |
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
open System | |
type ZipBuilder() = | |
member t.Zip(xs,ys) = List.zip xs ys | |
member t.For(xs,f) = List.collect f xs | |
member t.Yield x = [x] | |
member t.Select(xs,f) = | |
List.map f xs | |
member t.Zero() = [] |
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
open System | |
type FSharp.Control.AsyncBuilder with | |
[<CustomOperation("and!", IsLikeZip=true)>] | |
member __.Merge(x, y, f) = | |
async { | |
let! token = Async.CancellationToken | |
let! x' = Async.StartChildAsTask x | |
let! y' = Async.StartChildAsTask y | |
do System.Threading.Tasks.Task.WaitAll([|x';y'|], cancellationToken = token) |
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
#r @"bin\Debug\FsControl.Core.dll" // from https://github.com/gmpl/FsControl | |
module Monad = | |
open FsControl.Core.Abstractions | |
let do' = new Monad.DoNotationBuilder() | |
module MonadPlus = | |
open Monad | |
open FsControl.Core.Abstractions.MonadPlus |
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" | |
}""" |
OlderNewer