Skip to content

Instantly share code, notes, and snippets.

View 7sharp9's full-sized avatar

Dave Thomas 7sharp9

  • Moirae Software Engineering Ltd
  • UK
  • X @7sharp9_
View GitHub Profile
@7sharp9
7sharp9 / ActivePatterns.fs
Created November 20, 2018 21:35
Language Essentials Active Patterns
namespace ClassLibrary1
open System
module SingleCase =
//definition
let (|UpperCase|) (x:string) = x.ToUpper()
//PM usage
match "foo" with
@7sharp9
7sharp9 / tech001.fs
Created November 2, 2018 20:41
Introduction to quotations
open System
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.ExprShape
open Microsoft.FSharp.Quotations.DerivedPatterns
let qliteral =
<@
let addAndMultiply a b =
@7sharp9
7sharp9 / parser.fs
Last active November 19, 2015 18:18
toml fparsec
open System
open System.Globalization
open FParsec
type Token =
| KeyGroup of string list
| KeyValue of string * obj
let (<||>) p1 p2 = attempt (p1 |>> box) <|> attempt (p2 |>> box)
let spc = many (anyOf [' '; '\t'])
namespace FSHelloSceneKit
open System
open MonoTouch.UIKit
open MonoTouch.Foundation
open MonoTouch.SceneKit
type FSHelloSceneKitViewController () =
inherit UIViewController()
module EasyLayout
open System
open System.Drawing
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.DerivedPatterns
open MonoTouch.Foundation
open MonoTouch.UIKit
@7sharp9
7sharp9 / gist:8421623
Created January 14, 2014 16:55
average of 10 runs of an fsharp script
for i in {1..10}; do time fsharp hello world.fsx; done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum += $1} END {print sum / NR}'
@7sharp9
7sharp9 / tokenizer.fs
Last active January 2, 2016 23:49
tokenizer snippets
let idents tokens =
//reverse the tokens
let tokens = tokens |> Array.rev |> List.ofArray
let rec loop tokens result =
match tokens with
| [] -> result
| (name, token: TokenInformation) :: tail ->
match token.TokenName with
| "IDENT" -> loop tail (name :: result)
| "DOT" -> loop tail result
@7sharp9
7sharp9 / arrays.fs
Created October 13, 2013 23:08
Array declarations:
let things = [|"One";"Two";"Three"|]
let things2 = [|"One"
"Two"
"Three"|]
let things3 = [|
"One"
"Two"
"Three"
@7sharp9
7sharp9 / BasicExample.fs
Last active December 22, 2015 20:59
An Blank screen Xna App
namespace BasicExample
open Microsoft.Xna.Framework
type Basic() as x =
inherit Game()
let graphics = new GraphicsDeviceManager(x)
override x.Draw (gameTime) = x.GraphicsDevice.Clear(Color.CornflowerBlue)
@7sharp9
7sharp9 / file.cs
Last active December 17, 2015 16:59
Example of record construction syntax for multiple constructors
[ProjectFileTypeDefinition(Name)]
public class HtmlProjectFileType : KnownProjectFileType
{
public new const string Name = "HTML";
public const string HTML_EXTENSION = ".html";
public const string HTM_EXTENSION = ".htm";
public new static readonly HtmlProjectFileType Instance;
private HtmlProjectFileType() : base(Name, "Html", new[] {HTML_EXTENSION, HTM_EXTENSION}) { }