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
// https://twitter.com/__josejuan__/status/445564129521434624 | |
// dummy definitions: | |
type Variable() = class end | |
type Expression() = class end | |
type Term() = class end | |
// overloads: | |
type E = | |
static member Sum(x: Variable list) = 0 |
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
// broken fmap for option | |
let fmap f = | |
function | |
| None -> None | |
| Some a -> | |
let b = f a | |
if box b = null then None else Some b | |
// second functor law, see http://www.haskell.org/haskellwiki/Functor | |
let fmapL p q = fmap (p << q) |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
static class Extensions { | |
public static Func<A, IEnumerable<C>> Kleisli<A,B,C>(this Func<A, IEnumerable<B>> f, Func<B, IEnumerable<C>> g) { | |
return a => from b in f(a) from c in g(b) select c; | |
} | |
} |
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
calculate :: String -> IO Int | |
calculate a = return 0 -- dummy placeholder for implementation | |
update :: String -> IO () | |
update a = print ("update " ++ a) | |
foo :: IO () | |
foo = print "foo!" | |
main = do |
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
class MyOld5700LoCBusinessClass { // actually 5715 lines | |
bool flag1, flag2, ..., flag15; | |
string message1, message2, ... message15; | |
// more instance variables | |
void Method1() {...} | |
... | |
void Method30() {...} |
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 Address = { | |
Name: string | |
Address1: string option | |
Address2: string option | |
Code: string option | |
City: string option | |
Country: string option | |
} | |
type Client = { |
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
// see http://bugsquash.blogspot.com/2014/05/mapping-objects-to-json-with-fleece.html for some background | |
open System | |
type AccountIdentifier = AccountIdentifier of Guid | |
type Account = { | |
Identifier : AccountIdentifier | |
Name : 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
using System; | |
using Newtonsoft.Json; | |
class Foo { | |
public override string ToString() { | |
return "Foo"; | |
} | |
} | |
class Bar<T> where T : Foo { |
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 StringToExnClass = StringToExnClass with | |
static member StringToExn (_: ArgumentNullException) = fun (s: string) -> ArgumentNullException s | |
static member StringToExn (_: AccessViolationException) = fun (s: string) -> AccessViolationException s | |
static member StringToExn (_: ArrayTypeMismatchException) = fun (s: string) -> ArrayTypeMismatchException s | |
// etc (need to wrap all relevant types) | |
let inline iStringToExn (a: ^a, b: ^b) = | |
((^a or ^b) : (static member StringToExn: ^b -> (string -> ^b)) b) |
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 Either<'a, 'b, 't> = ('a -> 't) -> ('b -> 't) -> 't // equivalent to Choice<'a, 'b> | |
type EitherStringInt<'t> = (string -> 't) -> (int -> 't) -> 't // equivalent to Choice<string, int> |
OlderNewer