Last active
August 10, 2021 17:49
-
-
Save matthewcrews/0ebc36360a44bb96e9fa58f57dc82167 to your computer and use it in GitHub Desktop.
Example of what I'm trying to be able to express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module rec TestTypes = | |
type Chicken = { | |
Size : int | |
} with | |
static member ( * ) (c: Chicken, i: int) = | |
{ Size = c.Size * i } | |
static member ( + ) (c1: Chicken, c2: Chicken) = | |
Flock [c1; c2] | |
static member ( + ) (c: Chicken, Flock f) = | |
Flock c::f | |
type Flock = Flock of Chicken list | |
type TestMap<'k, 'v when 'k : comparison> = { | |
Data : Map<'k, 'v> | |
} with | |
static member inline ( .* ) (l: TestMap<_,_>, r: TestMap<_,_>) = | |
TestExpr.HadamardProduct (l, TestExpr.TestMap r) | |
static member inline ( .* ) (l: TestMap<_,_>, r: TestExpr<_,_>) = | |
TestExpr.HadamardProduct (l, r) | |
type TestExpr<'k, 'v when 'k : comparison> = | |
| TestMap of TestMap<'k, 'v> | |
| HadamardProduct of TestMap<'k, 'v> * TestExpr<'k, 'v> | |
open TestTypes | |
let m1 = { Data = Map [(1, 1); (2, 2)]} | |
let m2 = { Data = Map [(1, { Size = 1 }); (2, { Size = 3 })]} | |
let m2 = { Data = Map [(1, 3); (2, 4)]} | |
let x = m1 .* m2 .* m2 // Compiler gives a type constraint mismatch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment