View Differ.fs
type DifferenceType<'TKey, 'T> =
| Added of 'TKey * 'T
| Removed of 'TKey * 'T
| Modified of 'TKey * 'T * 'T * seq<string * (string * string)> with
member this.Key =
match this with
| Added (key, _)
| Removed (key, _)
| Modified (key, _, _, _) -> key
View CSharpVsScalaAsync
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
View Hylo.fs
type List<'i,'r> = Nil | Cons of 'i*'r
type FixList<'i> = FixList of List<'i,FixList<'i>>
let rec fmap (f : 'a -> 'b) (l : List<'i,'a>) : List<'i,'b> =
match l with
| Nil -> Nil
| Cons (x, tail) -> Cons (x, f tail)
// you can express hylo directly without using ana and cata (by either following the
View FindAllBestChains.hs
{-# LANGUAGE DeriveFunctor #-}
-- Is there a trick to getting this done easier?
-- yep, look at TryAgainFromScratch.hs
module Bridge where
import Data.List
import Data.Ord
import qualified Data.Map as Map
View dsl.hs
{-# LANGUAGE DeriveFunctor #-}
-- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- {-# LANGUAGE XRankNTypes #-}
-- run this online https://repl.it/repls/GraciousCooperativeNijssenissdwarfchihlid
import Control.Applicative -- <$>
import Control.Monad
data Free f r = Free (f (Free f r)) | Pure r
View Primes.hs
{-# LANGUAGE DeriveFunctor #-}
-- https://bartoszmilewski.com/2017/02/28/f-algebras/
newtype Fix f = Fix (f (Fix f))
unFix :: Fix f -> f (Fix f)
unFix (Fix x) = x
cata :: Functor f => (f a -> a) -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix
ana :: Functor f => (a -> f a) -> a -> Fix f
View free.fsx
#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>
View gist:104185116b28273403cb2b6ba6cec210
type TrimNonEmptyString internal (value : string) =
member __.Value = value
override __.ToString() = value
override __.Equals(yobj) =
match yobj with
| :? TrimNonEmptyString as y -> (__.Value = y.Value)
| _ -> false
override __.GetHashCode() = hash value
static member TryParse (value : string) =
if System.String.IsNullOrWhiteSpace value then
View io.fsx
[<AutoOpen>]
module IO =
type IO<'a> =
private
| Return of (unit -> 'a)
| Suspend of (unit -> IO<'a>)
let rec run x =
match x with
| Return v -> v()
View datarow.fs
// https://dotnetfiddle.net/sjSjeS
open System
open System.Data
open System.Xml
open Microsoft.FSharp.Linq
type RowReader(reader:DataRow) =
member private x.Reader = reader
static member (?) (x:RowReader, name:string) : 'R =