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
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 } |
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
type IPoint | |
= interface | |
abstract x: int; | |
abstract y: int; | |
abstract move: IPoint -> unit | |
end |
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
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 |
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
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 |
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
[<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 |
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
// Raise an ArgumentException: | |
invalid_arg "list must not be empty" | |
// Raise a FailureException: | |
failwith "internal error" |
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
raise (InvalidOperationException("help!")) |
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
exception Special of int | |
raise (Special 99) |
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
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 |
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
let resource = getResource() | |
in try folds (useResource resource) [] | |
with EmptyList m -> stdout.WriteLine(m); | |
rethrow() | |
finally releaseResource resource |