Skip to content

Instantly share code, notes, and snippets.

View PatrickMcDonald's full-sized avatar

Patrick McDonald PatrickMcDonald

View GitHub Profile
@echo off
pushd visualfsharp\src
msbuild fsharp-library-build.proj /p:TargetFramework=net40
if %errorlevel% neq 0 goto :END
msbuild fsharp-library-unittests-build.proj /p:TargetFramework=net40
@PatrickMcDonald
PatrickMcDonald / CampingChecklist.md
Last active August 29, 2015 14:05
Camping Checklist

Camping Checklist

Cooking

  • Trangia
  • fuel bottle
  • Cobb
  • fuel
namespace Curry
{
using System;
internal static class Program
{
// Curry methods
public static TResult Curry<T, TResult>(this Func<T, TResult> f, T arg)
{
// Curry'2 is just invoke
let createTimer() =
let sw = System.Diagnostics.Stopwatch.StartNew()
fun () ->
sw.Elapsed
let timer = createTimer()
// Do some stuff to time
timer();;
let foldBack folder seq state =
let arr = Seq.toArray seq
Array.foldBack folder arr state
let folder a b =
let res = a + b
//printfn "fold %A and %A giving %A" a b res
res
let list = seq [1..1000000]
namespace StringTimes
{
using System;
public class Program
{
private static void Main(string[] args)
{
const int Iterations = 10000000;
#r "System.Numerics"
open System.Numerics
/// Find the roots of ax² + bx + c
let quadraticRoots a b c =
let ``√ B² - 4ac`` = sqrt (b * b - 4.0 * a * c)
let ``2a`` = 2.0 * a
(-b + ``√ B² - 4ac``) / ``2a``, (-b - ``√ B² - 4ac``) / ``2a``
@PatrickMcDonald
PatrickMcDonald / Fibonacci.fsx
Last active August 29, 2015 14:04
Generate Fibonacci numbers
let fibs() =
let rec fibs' a b =
seq {
yield b
yield! fibs' b (a+b)
}
fibs' 1L 1L
fibs() |> Seq.take 10 |> List.ofSeq;;
let combine ys xs =
let zipi x = ys |> List.map (fun y -> (x, y))
xs |> List.collect zipi
let date year month day = new System.DateTime(year, month, day)
type DayOfWeek = | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
exception DayOfWeekError
let dayOfWeek (date: System.DateTime) =
match date.DayOfWeek with
| System.DayOfWeek.Monday -> Monday
| System.DayOfWeek.Tuesday -> Tuesday