Skip to content

Instantly share code, notes, and snippets.

@palladin
palladin / gist:c34a3a761f755b57244c
Created July 27, 2014 15:05
ParStream.sortBy performance test
#time
#r "bin/Release/Streams.Core.dll"
open Nessos.Streams.Core
let rnd = new System.Random()
let data = [|1..10000000|] |> Array.map (fun _ -> int64 <| rnd.Next(1000000))
#r "../../packages/FSharp.Collections.ParallelSeq.1.0/lib/net40/FSharp.Collections.ParallelSeq.dll"
open FSharp.Collections.ParallelSeq
@palladin
palladin / gist:c5fca07b74da782832cb
Last active September 25, 2021 17:52
Parallel Streams Test
#time
#r "bin/Release/Streams.Core.dll"
open Nessos.Streams.Core
let data = [|1..10000000|] |> Array.map int64
#r "../../packages/FSharp.Collections.ParallelSeq.1.0/lib/net40/FSharp.Collections.ParallelSeq.dll"
@palladin
palladin / gist:def871a13f9d26c6c388
Created July 7, 2014 20:20
Clojure meetup final
;; Anything you type in here will be executed
;; immediately with the results shown on the
;; right.
(def data '({:name "nick" :age 20} {:name "george", :age 30}
{:name "giannis", :age 40} {:name "dimitris", :age 50}))
@palladin
palladin / gist:c2964748e45a0a59a15b
Last active September 25, 2021 17:52
Simple CPS composition
let inline f k = (fun x -> k (x + 1))
let inline g k = (fun x -> k (x + 2))
(f << g) id 1 // 4
@palladin
palladin / gist:500dac7d4bd5419a3320
Created May 23, 2014 12:30
FsControl ZipIndex
#r "../packages/FsControl.1.0.8/lib/net40/FsControl.Core.dll"
open FsControl.Core.TypeMethods
open FsControl.Core.Types
let inline result (x:'a): 'Functor'a = Inline.instance Applicative.Pure x
let inline (>>=) (x:'Monad'a) (f:'a->'Monad'b) :'Monad'b = Inline.instance (Monad.Bind, x) f
let inline traverse (f:'a->'Applicative'b) (t:'Traversable'a) :'Applicative'Traversable'b = Inline.instance (Traversable.Traverse , t) f
type MonadBuilder() =
member inline b.Return(x) = result x
@palladin
palladin / gist:10106955
Created April 8, 2014 10:15
Mono Tail-call test
// mono --optimize=tailc
let fs = [1..1000000] |> List.map (fun i -> (fun k j -> k (i + j)))
let f = List.fold (fun f' f -> f f') id fs
f 1 // StackOverflow
@palladin
palladin / Bug.fsx
Created March 7, 2014 15:02
Line 7 - Error 1 'base' values may only be used to make direct calls to the base implementations of overridden members Script1.fsx 9 30 Miscellaneous Files
type MyClassBase1<'T> () =
abstract member function1 : unit -> unit
default u.function1 () = ()
and MyClassDerived1 () =
inherit MyClassBase1<int>()
override u.function1 () = base.function1()
@palladin
palladin / gist:8577661
Last active September 25, 2021 17:51
F# style LINQ programming with tuples
public static class EnumerableEx
{
public static IEnumerable<R> Select<T1, T2, R>(this IEnumerable<Tuple<T1, T2>> source, Func<T1, T2, R> f)
{
return source.Select(t => f(t.Item1, t.Item2));
}
}
Enumerable.Range(1, 10)
.Select(x => Tuple.Create(x, x))
@palladin
palladin / gist:8561783
Created January 22, 2014 16:22
My Favorite Active Pattern
let (|Named|Array|Ptr|Param|) (t : System.Type) =
if t.IsGenericType
then Named(t.GetGenericTypeDefinition(), t.GetGenericArguments())
elif t.IsGenericParameter
then Param(t.GenericParameterPosition)
elif not t.HasElementType
then Named(t, [| |])
elif t.IsArray
then Array(t.GetElementType(), t.GetArrayRank())
elif t.IsByRef
@palladin
palladin / gist:8046053
Last active September 25, 2021 17:51
Mandelbrot set with LINQ
// http://msmvps.com/blogs/jon_skeet/archive/2008/02/26/visualising-the-mandelbrot-set-with-linq-yet-again.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Diagnostics;
using LinqOptimizer.CSharp;