Skip to content

Instantly share code, notes, and snippets.

type Point = { mutable x: int; mutable y: int }
with member p.move q = p.x <- p.x + q.x;
p.y <- p.y + q.y
let makePoint x y = { x = x; y = y }
type IPoint
= interface
abstract x: int;
abstract y: int;
abstract move: IPoint -> unit
end
type Point
= class
val mutable vx: int;
val mutable vy: int;
new(x,y) = { vx = x; vy = y }
interface IPoint
with member p.move q = p.vx <- p.vx + q.x;
p.vy <- p.vy + q.y
member p.x = p.vx
member p.y = p.vy
type Point(x,y)
= class
let mutable vx = x
let mutable vy = y
interface IPoint
with member p.move q = vx <- vx + q.x;
vy <- vy + q.y
member p.x = vx
member p.y = vy
end
[<AbstractClass>]
type AbstractPoint
= class
val mutable vx: int;
val mutable vy: int;
new(x,y) = { vx = x; vy = y }
member p.x with get() = p.vx and set z = p.vx <- z
member p.y with get() = p.vy and set z = p.vy <- z
abstract move: AbstractPoint -> unit
end
// Raise an ArgumentException:
invalid_arg "list must not be empty"
// Raise a FailureException:
failwith "internal error"
raise (InvalidOperationException("help!"))
exception Special of int
raise (Special 99)
exception EmptyList of string
let rec folds g x
= match x
with [] -> raise (EmptyList "folds")
| [x] -> x
| h::t -> g h (folds g t)
try folds (fun x y -> x + y) []
with EmptyList m -> stdout.WriteLine(m);
0
let resource = getResource()
in try folds (useResource resource) []
with EmptyList m -> stdout.WriteLine(m);
rethrow()
finally releaseResource resource