Skip to content

Instantly share code, notes, and snippets.

@Octachron
Created February 18, 2018 19:58
Show Gist options
  • Save Octachron/a3e80f435c2ffb74c592979ee6c20166 to your computer and use it in GitHub Desktop.
Save Octachron/a3e80f435c2ffb74c592979ee6c20166 to your computer and use it in GitHub Desktop.
type scalar = float
type z = private Z type 'a s = private S
type _ t =
| Scalar: scalar -> 'any t
| Vec2: {x:float;y:float} -> z s t
| Vec3: {x:float;y:float;z:float} -> z s s t
let (+) (type dim) (x: dim t) (y:dim t) : dim t =
match x, y with
| Scalar a, Scalar b -> Scalar (a +. b)
| Scalar s, Vec2 {x;y} -> Vec2{x=x+.s;y=y+.s}
| Vec2 {x;y}, Scalar s -> Vec2{x=x+.s;y=y+.s}
| Scalar s, Vec3 {x;y;z} -> Vec3{x=x+.s;y=y+.s;z=z+.s}
| Vec3 {x;y;z}, Scalar s -> Vec3{x=x+.s;y=y+.s;z=z+.s}
| Vec2 a, Vec2 b -> Vec2{ x= a.x +. a.x; y = a.y +. b.y }
| Vec3 a, Vec3 b -> Vec3{ x= a.x +. a.x; y = a.y +. b.y; z = a.z +. b.z }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment