Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / lo.fs
Last active Aug 29, 2015
LinqOtimizer question.
View lo.fs
// 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 Dec 12, 2014
A monadic interpreter
View MyInterpreter.fs
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
View 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 Aug 29, 2015
Flowlet gist
View Flowlet
// 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 Aug 29, 2015
F# top 100 biggest binaries in a GIT repo and print the Commit they were introduced
View top100.fs
// ----------------------------------------------------------------------------------------------
// 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.
View test.fs
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 Aug 29, 2015
C++14 tuple
View my_tuple.cpp
#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
{
};
View mpc.fs
// ----------------------------------------------------------------------------------------------
// 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.
View json_mpc.fs
// ----------------------------------------------------------------------------------------------
// 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.
View full_mpc.fs
// ----------------------------------------------------------------------------------------------
// 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.