Skip to content

Instantly share code, notes, and snippets.

View jackfoxy's full-sized avatar

Jack Fox jackfoxy

View GitHub Profile
@jackfoxy
jackfoxy / DecisionTables.fsx
Created September 18, 2020 21:20
A demo of decision tables using F# types and pattern matching
(*
Decision Table Demo
MIT License, do with this what you will
A demo of decision tables using F# types and pattern matching, inspired by https://www.hillelwayne.com/post/decision-table-patterns/
The compiler service flags problematic (incomplete) decision tables.
Requirements:
// Fibonacci
// not originally mine, can't remember where I got it
// State Monad combined with Continuation Monad (StateT Mondad transformer)
type StateContMonad<'s, 'a, 'r> =
StateContMonad of ('s -> ('s -> 'a -> 'r) -> 'r)
type StateContBuilder() =
member __.Return value =
StateContMonad (fun state k -> k state value)
//not tested as fsx, but insert into existing fs in a project and you should see error messages other than bad tab
//did not let me save gist with tabs
//so insert them yourself in some other editor in line 21
type Production =
{
Ident : int
Year: int
Month: int
OilProduced: float
WaterProduced: float
one name publlic verification
@jackfoxy
jackfoxy / FsharpConsoleApp.js
Created July 23, 2016 19:05
Visual Studio Macro learnings and questions
/// <reference path="C:\Users\Jack\AppData\Local\Microsoft\VisualStudio\14.0\Macros\dte.js" />
// Blog announcing new VS macro facility:
// https://blogs.msdn.microsoft.com/visualstudio/2016/05/11/macros-extension-open-sourced-in-visual-studio-2015
//
// Macros get saved to:
// <user>\AppData\Local\Microsoft\VisualStudio\14.0\Macros\Macros
// does not seem to be any way to change default folder. Roaming may also work, but I have not experimented with that.
//
// Tne open source project:
// https://github.com/Microsoft/VS-Macros
@jackfoxy
jackfoxy / gist:50ffcefb88f082c51bb1
Created February 29, 2016 18:49
SQLite cannot execute from F# FSI
//Demo SQLite cannot run from FSI
//#load "load-references-debug.fsx"
#I __SOURCE_DIRECTORY__
#r "../../packages/Microsoft.Data.Sqlite.1.0.0-rc1-final/lib/net451/Microsoft.Data.Sqlite.dll"
open Microsoft.Data.Sqlite
let conn = new SqliteConnection(@"Data Source = :memory:")
@jackfoxy
jackfoxy / gist:6679238
Last active December 23, 2015 18:59
A sandbox for F# Type explorations
namespace TypeSystemSandbox
#if INTERACTIVE
#load @"C:\FsEye\FsEye.fsx"
#I "C:\Packages"
#endif
open System
//constraints from "Constraints (F#)" MS F# Language Reference
@jackfoxy
jackfoxy / simpleForceReveal.fs
Created November 14, 2012 23:30
simplified forced door reveal for let's make a deal
let forcedReveal doorWithPrize fstChoice =
match (doorWithPrize + fstChoice) with
|3 -> 3
|4 -> 2
|_ -> 1
@jackfoxy
jackfoxy / ForcedReveal.fs
Created November 13, 2012 00:33
forced door reveal for Monty Hall problem
let forcedReveal doorWithPrize fstChoice =
match doorWithPrize with
|1 -> if fstChoice = 2 then 3
else 2
|2 -> if fstChoice = 1 then 3
else 1
|_ -> if fstChoice = 1 then 2
else 1