Skip to content

Instantly share code, notes, and snippets.

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:
// 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,
@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 =
@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
@TheSeamau5
TheSeamau5 / EntityComponentSystemExploration.md
Created December 29, 2014 23:16
An exploration of the Entity Component System in Elm

#Exploring Entity Component Systems in Elm

Entity-Component-System (or ECS) is a pattern for designing programs that is prevalent in the games industry. This pattern consists of three simple parts:

  • Entity : A uniquely identifiable object that may contain any number of components
  • Component : A property usually representing the raw data of one aspect of the object. (Position is a component, Velocity is a component, Strength is a component, etc...)
  • System : A continuous process performing actions on every entity that possesses a component of the same aspect as that system

To understand this, let us try to make a simple example: Boxes that move in space:

@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)
--------------------------
@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
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