Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / RegexExtensions.fs
Created November 22, 2011 16:49
F# regex active patterns proposal #2 for fsharpx
namespace Extensions
open System.Text.RegularExpressions
///Regex extensions
module Regex =
type ActiveMatch =
{
Match: Match
MatchValue: string
Groups: Group list
anonymous
anonymous / gist:1406238
Created November 29, 2011 20:09
Originally:
https://gist.github.com/7565976a89d5da1511ce
Hi Donald (and Martin),
Thanks for pinging me; it's nice to know Typesafe is keeping tabs on this, and I
appreciate the tone. This is a Yegge-long response, but given that you and
Martin are the two people best-situated to do anything about this, I'd rather
err on the side of giving you too much to think about. I realize I'm being very
critical of something in which you've invested a great deal (both financially
@leegao
leegao / bf.ml
Created December 6, 2011 22:00
Brainfuck parser
(*
We use the following grammar, which can be proven to be LL(1) by the derivation below
D -> >|<|+|-|.|,
E -> D E'
E -> [ E ] E'
E' -> E
E' -> epsilon ; null/empty terminal
from the above, we build the following First sets
@jfromaniello
jfromaniello / gist:1876319
Created February 21, 2012 12:42
Mate Amargo
Para más información acerca de mate http://es.wikipedia.org/wiki/Mate_(infusi%C3%B3n)
Colocar en el mate 2/3 de yerba sin colocar la bombilla aún.
Tapando la boca del mate "zarandear" boca abajo varias veces para que la materia fina de la yerba quede arriba.
Volver el mate boca arriba intentando que la yerba quede toda de un lado, y del otro lado quede vacío a tal punto que se pueda ver desde arriba el fondo del mate.
Verter un poco de agua tibia del lado sin yerba, y una vez humedecida la yerba, con una cuchara intentar amontonar más la yerba agrandando el espació vacío donde se puede ver el fondo del mate.
Colocar la bombilla de tal forma que la parte por donde se absorbe el agua quede del lado sin yerba.
Siempre colocar el agua por el lado sin yerba.
@biboudis
biboudis / gist:1931336
Created February 28, 2012 08:53
A quick bloom filter in Rx
public static IObservable<Tuple<TSource, bool>> Bloom<TSource>(this IObservable<TSource> source, int size)
{
BitArray bitmap = new BitArray(size);
return source.Select<TSource, Tuple<TSource, bool>>(value =>
{
var hashCode = value.GetHashCode();
var tuple = new Tuple<TSource, bool>(value, bitmap[hashCode] == true);
bitmap[hashCode] = true;
return tuple;
@ovatsus
ovatsus / Setup.fsx
Created March 17, 2012 17:07
Script to setup F# Interactive session, loading everything in the current solution
#r "System.Xml.Linq"
open System
open System.IO
open System.Xml.Linq
let script = seq {
//TODO: this currently loads fsproj's in alphabeticall order, we should instead
//build the dependencies graph of the fsproj's and load them in topological sort order
@sebfisch
sebfisch / gist:2235780
Created March 29, 2012 10:47
Laymans explanation of delimited continuations with examples of using them for exception handling and nondeterministic programming.

Delimited Continuations

Delimited continuations manipulate the control flow of programs. Similar to control structures like conditionals or loops they allow to deviate from a sequential flow of control.

We use exception handling as another example for control flow manipulation and later show how to implement it using delimited continuations. Finally, we show that nondeterminism can also be expressed using delimited continuations.

Exception Handling

@Thorium
Thorium / gist:2416591
Created April 18, 2012 21:11 — forked from mattpodwysocki/gist:165605
IObservable<T> is close to Async<T>, so why not: F# obs { ... } as async { ... }
#I @"C:\Tools\System.Reactive"
#r "System.Core.dll"
#r "System.Reactive.dll"
type observable<'a> = System.Collections.Generic.IObservable<'a>
type observer<'a> = System.Collections.Generic.IObserver<'a>
module Observable =
open System
open System.Linq
@palladin
palladin / gist:2634310
Created May 8, 2012 11:17
Scrap Your Boilerplate (with class)
// http://homepages.cwi.nl/~ralf/syb3/
let inline gmap f g (x : ^R) : ^R = (f ? (g) <- x)
type Data = Data with
static member inline ($)(f : ^F, x : ^A) = gmap Data f x
static member inline (?<-)(Data, f, x : int) = x
static member inline (?<-)(Data, f, x : string) = x
static member inline (?<-)(Data, f, x : bool) = x
@nberardi
nberardi / BigDecimal.cs
Created May 12, 2012 15:17
BigDecimal type in .NET
using System;
using System.Linq;
namespace System.Numerics
{
public struct BigDecimal : IConvertible, IFormattable, IComparable, IComparable<BigDecimal>, IEquatable<BigDecimal>
{
public static readonly BigDecimal MinusOne = new BigDecimal(BigInteger.MinusOne, 0);
public static readonly BigDecimal Zero = new BigDecimal(BigInteger.Zero, 0);
public static readonly BigDecimal One = new BigDecimal(BigInteger.One, 0);