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
<Choose> | |
<When Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets')"> | |
<PropertyGroup> | |
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath> | |
</PropertyGroup> | |
</When> | |
<When Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')"> | |
<PropertyGroup> | |
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath> | |
</PropertyGroup> |
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
/* Dependency */ | |
public class AnotherClass { | |
public virtual string DoSomething(string str1) { return str1.ToUpper(); } /* virtual so we can change/mock it. | |
* Alternatively use an interface, or abstract. */ | |
} | |
/* Class we want to test */ | |
public class MyClass { | |
public string str1; |
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 MyModule | |
open Xunit | |
open FsUnit.Xunit | |
type Sample = Sample of int | |
with override x.ToString() = sprintf "%A" x | |
[<Fact>] | |
let ``sample to string`` ()= | |
let actual = Sample 1 |
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 static class ReaderExtensions | |
{ | |
public static Func<T, B> Select<T, A, B>(this Func<T, A> reader, Func<A, B> f) | |
{ | |
return t => f(reader(t)); | |
} | |
public static Func<T, B> SelectMany<T, A, B>(this Func<T, A> reader, Func<A, Func<T, B>> f) | |
{ | |
return t =>f(reader(t))(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
public class Either<TLeft, TRight> | |
{ | |
private readonly bool isLeft; | |
private readonly TLeft left; | |
private readonly TRight right; | |
private Either(bool isLeft, TLeft a, TRight b) | |
{ | |
this.isLeft = isLeft; | |
this.left = 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
Given: | |
pure ∷ a → f a | |
⊛ ∷ f (a → b) → f a → f b | |
(.) ∷ (b → c) → (a → b) → a → c | |
show: | |
pure (.) ⊛ u ⊛ v ⊛ = u ⊛ (v ⊛ w) |
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
//Experiment, based on http://withouttheloop.com/articles/2014-04-18-fsharp-csharp-statemachines/ | |
open System | |
type Particulars = { buyer: string; seller: string } | |
type Draft = private Draft of Particulars | |
type Approved = private Approved of (Particulars * DateTime) | |
type Historical = private Historical of (Particulars * DateTime) | |
let createDraft = Draft |
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 IEnumerable<string> GetSamples(string s) { | |
var re = @"\{%\s*(?<tag>\w+)\s*\%\}(?<contents>(?s:.*?))\{%\s*end\1\s*%\}"; | |
return Regex.Matches(s, re) | |
.Cast<Match>() | |
.Where(m => m.Groups["tag"].Value == "sample") | |
.Select(m => m.Groups["contents"].Value.Trim()); | |
} |
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
#!/bin/sh | |
# Attempts to build a cabal binary package and symlink it in ~/.cabal/bin/ | |
# Don't do this for binaries that rely on other assets! (such as pandoc) | |
# USE AT YOUR OWN RISK! | |
set -e | |
ws="[^a-zA-Z0-9\-\.]" | |
if [ "$#" -ne 1 ] | |
then |
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 Control.Monad (foldM) | |
import Control.Applicative | |
-- Given an initial state return a value based on that state and the new state | |
newtype State s a = State { runState :: s -> (a, s) } | |
-- Get the value of the state | |
get :: State s s | |
get = State $ \s -> (s,s) |
OlderNewer