Skip to content

Instantly share code, notes, and snippets.

@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 =
// 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,
// 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
@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:
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)