Skip to content

Instantly share code, notes, and snippets.

View jack-pappas's full-sized avatar

Jack Pappas jack-pappas

  • Philadelphia, PA, USA
View GitHub Profile
@jack-pappas
jack-pappas / tailcall-warnings.fsx
Created March 29, 2014 19:04
Demonstration of how non-tailcall warnings could work in F#
// This code demonstrates how the F# compiler could detect and emit a warning
// for non-tail-recursive calls to help avoid stack overflows.
// In response to: http://fslang.uservoice.com/forums/245727-f-language/suggestions/5663074-enable-a-compiler-warning-when-a-recursive-algorit
module Blah
let foo x =
printfn "Foo: %x" x
let rec bar x =
// Original code: https://gist.github.com/taumuon/11302896
// This implementation optimized by Jack Pappas (https://github.com/jack-pappas)
open MathNet.Numerics.Distributions
open MathNet.Numerics.Statistics
open MathNet.Numerics.Random
open LanguagePrimitives
let inline callPayoff strike price =
max (price - strike) GenericZero
@jack-pappas
jack-pappas / Program.fs
Last active August 29, 2015 14:05
Reproduction case for F# 3.0 (and possibly newer) type inference bug
// Created by Jack Pappas
// This code is a reproduction case for an F# 3.0 / 3.1 compiler bug related
// to type parameter/variable propagation.
// To compile this code, create a new F# application project, reference the
// 'FParsec' NuGet package, then paste this code into the Program.fs created for
// the project.
module internal TypeVariableRepro =
open FParsec
open FParsec.Primitives
open System.Security.Cryptography
open System.Diagnostics
let bench (digest: HashAlgorithm) (input: byte[]) =
use digest = digest
let sw = Stopwatch.StartNew()
for _ in 1..100 do
digest.ComputeHash input |> ignore
sw.Stop()
printfn "%s elapsed %O" (digest.GetType().Name) sw.Elapsed
@jack-pappas
jack-pappas / fsharp-bootstrap-compiler-profile-data (Internal.Utilities).txt
Created April 10, 2013 19:51
A tab-delimited file based on @ToyVo's profiler data dump of the F# bootstrap compiler. The data was loaded into Excel, then the average "self" time was computed for each method (that is, time spent in the method but *not* the methods it calls). The data was sorted in decreasing order on the average "self" time, then any methods with fewer than …
Total(ms) Self(ms) Calls Self(ms) Avg. Method name
4286133 688114 125 5504.912 "Internal.Utilities.Text.Parsing.Implementation:interpret<tok> (Internal.Utilities.Text.Parsing.Tables`1<tok>,Microsoft.FSharp.Core.FSharpFunc`2<Internal.Utilities.Text.Lexing.LexBuffer`1<char>, tok>,Internal.Utilities.Text.Lexing.LexBuffer`1<char>,int)"
15510 5287 3381 1.563738539 Internal.Utilities.Filename:checkPathForIllegalChars (string)
66587 9038 37284 0.242409613 "Internal.Utilities.ResizeArrayModule:go@307-3<T> (Microsoft.FSharp.Core.FSharpFunc`2<int, Microsoft.FSharp.Core.FSharpFunc`2<T, bool>>,System.Collections.Generic.List`1<T>,int)"
4579 1363 10550 0.129194313 Internal.Utilities.Collections.HashMultiMap`2:System-Collections-Generic-IEnumerable`1-GetEnumerator ()
82669 32128 495368 0.064856834 "Internal.Utilities.Collections.Tagged.MapTreeModule:tryFind<T, a> (System.Collections.Generic.IComparer`1<T>,T,Internal.Utilities.Collections.Tagged.MapTree`2<T, a>)"
5311 1908 34340 0.055562027 Internal.Utilities.Collections.Ta
@jack-pappas
jack-pappas / .gitignore
Created April 24, 2013 19:54
A "baseline" .gitignore file for .NET projects.
###############################################################################
# General (non-project-specific) patterns
###############################################################################
# OS junk files
*.DS_Store
[Tt]humbs.db
# Temp Files
*~ # UNIX
@jack-pappas
jack-pappas / build-output
Created November 30, 2013 15:19
Mono 3.2.5 tarball build error
System.ComponentModel.Design/ComponentDesigner.cs(189,4): warning CS0618: `System.ComponentModel.Design.ComponentDesigner.InitializeNonDefault()' is obsolete: ` This method has been deprecated. Use InitializeExistingComponent instead.'
System.ComponentModel.Design/DesignerActionList.cs(67,4): warning CS0162: Unreachable code detected
System.Data.Design/TypedDataSetGeneratorException.cs(50,12): warning CS0436: The type `Locale' conflicts with the imported type of same name'. Ignoring the impo rted type definition
../../build/common/Locale.cs(36,23): (Location of the symbol related to previous warning)
./../../class/lib/net_4_0/System.Data.dll (Location of the symbol related to previous warning)
System.Windows.Forms.Design/ComponentDocumentDesigner.cs(57,32): warning CS0618: `System.ComponentModel.Design.ViewTechnology.WindowsForms' is obsolete: `Use Vi ewTechnology.Defaul
@jack-pappas
jack-pappas / results1.txt
Last active December 31, 2015 21:49
Performance comparison of immutable set implementations for .NET.
Results from running PerfComparison (https://github.com/jack-pappas/fs-core-optimized)
Random set density parameter: 0.850000
RNG seed: 246071284
----
Warming up...done.
Create Random Set<int> (n=1000000)
FSharp.Core (Original) : 5250.775900 (ms)
FSharp.Core (Optimized) : 5239.608900 (ms)
@jack-pappas
jack-pappas / Library1.fs
Created December 19, 2016 14:17
Repro for type inference bug (or non-specific compiler error message) related to use of byref
namespace FSharpByrefTypeInferBug
open System.Runtime.InteropServices
#nowarn "9"
type LONG = int32
[<AutoOpen>]
module NativeMethods =
@jack-pappas
jack-pappas / _simple.fs
Last active May 10, 2023 07:09
Fixed-length arrays in F#
// Original code posted in fsharp-opensource discussion:
// https://groups.google.com/forum/#!topic/fsharp-opensource/pI73-GkoxbY
namespace Blah
open System.Runtime.InteropServices
[<Struct>]
type vec3_t =