Skip to content

Instantly share code, notes, and snippets.

// I'm using lots of operating overloading voodoo to avoid
// having to specify static type constraints manually.
// I'm also using MemoryStream / BinaryReader which is probably
// slow but it was the easiest way to read values sequentially.
// It's currently just using the size of the receiving datatype
// rather than specifying it, though that could change.
open System
open System.IO
// This was the idea. Unfortunately, it doesn't work. The expression expects every successive item to be
// the same type the first expression, ProvidedProperty. I can upcast them all to MemberInfo, but then they
// don't work as arguments to the next items in the expression.
let createType name (parameters:obj[]) =
let providedAsmPath = Path.Combine(config.TemporaryFolder, "FixedLengthTypes.dll")
let providedAsm = ProvidedAssembly(providedAsmPath)
let length = parameters.[0] :?> int
let ty = ProvidedTypeDefinition(asm, "FixedLengthTypes", name, Some typeof<obj>, IsErased = false)
ty.AddMembers(list {
yield ProvidedProperty("Length", typeof<int>, IsStatic = true,
type Bridge = { RunwayLength: int; GapSize: int; LandingSize: int }
type BikeState = { Speed: int; Position: int }
// Get current position
let (|OnTheRunway|JustBeforeGap|InFlight|AfterGap|) bikeState =
if bikeState.Position >= bridge.RunwayLength + bridge.GapSize then AfterGap
elif bikeState.Position > (bridge.RunwayLength - bikeState.Speed) then JustBeforeGap
elif bikeState.Position < bridge.RunwayLength then OnTheRunway
else InFlight
@TheSeamau5
TheSeamau5 / hackyECS.elm
Last active October 7, 2015 15:53
Entity Component Systems in Elm using hacks à-la elm-webgl
type Entity entity = Entity
type Component = Component
get : String -> Entity -> Maybe Component
get = ECS.Native.get
update : String -> a -> Entity -> Entity
update = ECS.Native.update
@cloudRoutine
cloudRoutine / fs-coreclr-build.md
Last active October 18, 2015 20:59
Build the Visual F# Compiler and Tools for .Net CoreCLR ( On Windows )

Make things easy for yourself and start by running posh as admin

If you already have dnvm installed remember to run update-self if you haven't recently

Clone and checkout the coreclr branch of Kevin Ransom's Fork of the Visual F# Compiler and Tools

Installing DNVM

You need DNVM as a starting point. DNVM enables you to acquire a (or multiple) .NET Execution Environment (DNX).

type FileChange =
| Changed of string
| Deleted of string
| Created of string
| Renamed of string * string
let watch folder =
async {
use fsw = new System.IO.FileSystemWatcher(folder, "*.fsx", EnableRaisingEvents = true)
@TIHan
TIHan / MvxViewModelTypeProvider.fs
Last active December 31, 2015 23:39
MvxViewModelTypeProvider - work in progress - still being developed, do not use in a production environment lol
(*
Copyright (c) 2013 William F. Smith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@TheSeamau5
TheSeamau5 / QuasiFullECS.elm
Last active August 3, 2017 23:09
Quasi-Full expression of Entity Component System in Elm
import Color (Color, rgb)
import Graphics.Collage (..)
import Graphics.Element (Element)
import List ((::), map)
import Signal (Signal, foldp, (<~), sampleOn)
import Keyboard (arrows)
import Time (millisecond, every)
--------------------------
@praeclarum
praeclarum / AutoLayout.fs
Last active April 27, 2020 11:07
AutoLayout wrapper to make creating constraints in F# easier
module Praeclarum.AutoLayout
open System
#if __IOS__
open Foundation
open UIKit
type NativeView = UIView
#else
open Foundation
@praeclarum
praeclarum / Ukf.fs
Created May 26, 2016 05:04
Unscented Kalman Filter (nonlinear version of the classic Kalman filter) in F#
module Drone.Control.Ukf
open System
open Drone.Control.Matrix
type IDiscreteModel =
abstract Process : Matrix -> Matrix
abstract Observe : Matrix -> Matrix
abstract InitialState : Matrix