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
-- http://comonad.com/reader/wp-content/uploads/2009/08/A-Parsing-Trifecta.pdf | |
-- | |
import Prelude hiding (null) | |
import Data.ByteString | |
data Input = Chunk ByteString | EOF | |
data Iteratee a | |
= Return a Input | |
| Cont (Input -> Iteratee a) |
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
operator infix • { associativity right } | |
@infix func •<A,B,C> (f : B->C, g : A->B) -> (A->C) { | |
return { (x : A) in f(g(x)) } | |
} | |
func inc(a : Int) -> Int { return a+1 } | |
func show(a : Int) -> String { return String(a) } | |
let f = show • inc • inc |
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
// Based on http://www.nut-cracker.com.ar/index.php/overloading-in-f | |
type IVec<'T> = | |
abstract member Add : 'T -> 'T | |
abstract member Inv : unit -> 'T | |
type Vector2D = Vector2D of float * float with | |
interface IVec<Vector2D> with | |
member x.Add (Vector2D(b1, b2)) = match x with Vector2D(a1,a2) -> Vector2D(a1+b1, a2+b2) | |
member x.Inv () = match x with Vector2D(a1, a2) -> Vector2D(-a1, -a2) |
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 DaveSquared.Sample | |
open Xunit | |
let incr x = x+1 | |
// Test using Unquote | |
open Swensen.Unquote | |
[<Fact>] |
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
import Foundation | |
import UIKit | |
import XCTest | |
// INTRODUCTION | |
// Console<T> is a type representing programs that can interact with the console (i.e. read from stdin, write to stdout), | |
// to produce a value of some type T. | |
// | |
// A Console<()> program is one that returns void ( a.k.a. Unit, written "()" ). |
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
-- Some function that takes a number and a string | |
ghci> let f a b = show (a+1) ++ " " ++ b | |
ghci> :t f | |
f :: (Show a, Num a) => a -> [Char] -> [Char] | |
-- Some type with a number of fields we want to read | |
ghci> data Option = Option { number :: Int, label :: String } deriving (Show, Eq) | |
ghci> let o = Option 1 "hi" | |
-- Read value of each field from Option and pass to `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
public interface IFoo { void MyMethod(Action<int[]> callback); } | |
[Test] | |
public void TestCallback() | |
{ | |
var sub = Substitute.For<IFoo>(); | |
var callback = Substitute.For<Action<int[]>>(); | |
var data = new[] { 1, 2, 3 }; | |
sub.When(x => x.MyMethod(callback)) |
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
require 'spec' | |
class DocsToCode | |
def docs_in(path) | |
[] | |
end | |
def code_in(doc) | |
"" | |
end | |
def extract(path) |
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
public interface IRoot { string Data { get; set; } } | |
[Serializable] | |
public abstract class Root : IRoot { public abstract string Data { get; set; } } | |
[Test] | |
public void FailingTest() | |
{ | |
var root = CreateMock(); // <-- create a mock with your favourite mocking framework for Root or IRoot | |
var formatter = new BinaryFormatter(); |
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
var mouseDown = Observable.FromEventPattern(firstButton, "MouseDown"); | |
var mouseUp = Observable.FromEventPattern(firstButton, "MouseUp"); | |
var mouseMove = Observable.FromEventPattern(firstButton, "MouseMove"); | |
mouseDown.Subscribe(x => Debug.WriteLine(">>> mouse down")); | |
mouseUp.Subscribe(x => Debug.WriteLine(">>> mouse up")); | |
(from down in mouseDown | |
from up in mouseUp.TakeUntil(mouseMove) | |
select up) |