Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / lo.fs
Last active August 29, 2015 14:07
LinqOtimizer question.
// The problem with Run is that the expression is begin rebuilt and then compiled everytime, potentially too expensive
let Run : int -> int = fun y -> Query.range(0,1000)
|> Query.filter(fun x -> x > y)
|> Query.sum
|> Query.run
// The problem with BuildFunc is that it doesn't compile :)
let BuildFunc : int -> int = Query.range(0,1000)
|> Query.filter(fun x -> x > VAR) // VAR should be the input parameter to the compiled func
|> Query.sum
|> Query.compile
@mrange
mrange / MyInterpreter.fs
Created December 12, 2014 21:09
A monadic interpreter
type Value =
| NoValue
| Bool of bool
| Int of int
| String of string
| Double of double
| Void
// With interpreters it's often good to have a stack of variables
// For instance when the interpreter calls a function typically a stackframe is pushed
@mrange
mrange / F# question 1
Created January 5, 2015 18:15
F# Question 1
// I like to create class type that accepts a generic enhancer function
// I tried 3 variants and nothing gives me the result I need
// Anyone has any ideas?
// warning FS0064: This construct causes code to be less generic than indicated by
// the type annotations. The type variable 'U has been constrained to be type 'obj'.
type MyTest1<'T>(enhancer : 'U->'U) =
let whatever = 3
type MyTest2<'T>() =
@mrange
mrange / Flowlet
Last active August 29, 2015 14:12
Flowlet gist
// A flowlet sample of simple customer registration flow
// First let's declare some types to hold the registration info
type AddressInfo =
{
FirstName : string
LastName : string
CareOf : string
AddressLine1 : string
AddressLine2 : string
@mrange
mrange / top100.fs
Last active August 29, 2015 14:16
F# top 100 biggest binaries in a GIT repo and print the Commit they were introduced
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
open Microsoft.FSharp.Core
open System
open System.Reflection
let mutable errors = 0
let print (cc : ConsoleColor) (prefix : string) (msg : string) : unit =
let old = Console.ForegroundColor
try
@mrange
mrange / my_tuple.cpp
Last active August 29, 2015 14:22
C++14 tuple
#define COPY_MOVE(type) \
type (type const &) = default; \
type (type &&) = default; \
type & operator= (type const &) = default; \
type & operator= (type &&) = default;
template<std::size_t>
struct my_tuple_index
{
};
@mrange
mrange / mpc.fs
Last active August 29, 2015 14:24
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.