Skip to content

Instantly share code, notes, and snippets.

View t0yv0's full-sized avatar

Anton Tayanovskyy t0yv0

View GitHub Profile
type Proc<'T> =
| P of ('T -> option<Proc<'T>>)
exception Bleep
let def f =
P (fun x -> try Some (f x) with Bleep | MatchFailureException _ -> None)
let rec ( <||> ) (P a) (P b) =
let f x =
@t0yv0
t0yv0 / Kombinators.v
Created October 5, 2013 00:02
Kombinators for scaling simple trait and/or combinators to n-way product/sum combinators.
Inductive choice a b :=
| C1 : a -> choice a b
| C2 : b -> choice a b.
Notation " a ++ b " := (choice a b).
Module Type TRAIT.
Parameter t : Type -> Type.
Parameter and : forall {a b}, t a -> t b -> t (a * b).
Parameter or : forall {a b}, t a -> t b -> t (a ++ b).
type Person =
{
Address : string
Age : int
Name : string
}
let makePerson name age address =
{
Address = address
module GenericsExperiment
/// Generic property interface. Since F# lacks higher kinds,
/// we cannot write code parametric in `P`, so instead write code with casts
/// in terms of an open type `P<'T>`.
type P<'T> =
interface
end
/// Implements derivation rules for a certain generic property.
This file has been truncated, but you can view the full file.
Mono log profiler data
Profiler version: 0.4
Data version: 4
Mean timer overhead: 5844 nanoseconds
Program startup: Tue Apr 2 17:00:45 2013
Program ID: 3508
Server listening on: 55256
JIT summary
// Example 1: `any` allows unsafe casts
var x : any = 1;
x();
// Example 2: subtyping on functions allows unsafe casts
interface I1 { x: number; }
interface I2 { x: number; y: number; }
function f(g: (x: I1) => void) { g({x: 1}); }
@t0yv0
t0yv0 / PKGBUILD
Created March 23, 2013 13:44
Corrections to the fsharp-git Arch Linux PKGBUILD to make it work (downgrading to a previous tag of F# open source repo)
# Maintainer: Joris Putcuyps <Joris.Putcuyps at gmail dot com>
pkgname=fsharp-git
pkgver=20130323
pkgrel=1
pkgdesc="An ML based functional language integrated with the .NET platform."
arch=('any')
url="http://msdn.microsoft.com/en-us/fsharp"
license=('APACHE')
groups=()
depends=('mono>=2.10.2')
// Capture: http://docs.phonegap.com/en/2.5.0/cordova_media_capture_capture.md.html
module Capture {
interface ConfigurationData {
type: string;
height: number;
width: number;
}
/// Provides basic types and syntax for defining XML and HTML fragments
/// as a deep EDSL in F#. Design goals:
///
/// A. Allow different concrente interpretations, including:
/// 1. XML documents and fragments
/// 2. HTML(5) documents and fragmetns
/// 3. XML or HTML templates with placeholders and/or instructions
///
/// B. Provide minimal type safetiy ensuring some sanity but not encoding every
/// invariant, which seems not practical with the weak F# type system.
open System.IO
type Format<'T> =
{
Read : BinaryReader -> 'T
Write : BinaryWriter -> 'T -> unit
}
(* Unions *)