Skip to content

Instantly share code, notes, and snippets.

@Glorp
Created May 4, 2016 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glorp/ff706667dc14299b43a9a711a1ebc29d to your computer and use it in GitHub Desktop.
Save Glorp/ff706667dc14299b43a9a711a1ebc29d to your computer and use it in GitHub Desktop.
fun foo b =
let exception Foo
in if b
then (foo (not b)) handle Foo => "caught"
else raise Foo
end
exception Bar
fun bar b =
if b
then (bar (not b)) handle bar => "caught"
else raise Bar
@Glorp
Copy link
Author

Glorp commented May 4, 2016

Standard ML of New Jersey v110.76 [built: Sun Jul 14 09:59:19 2013]
- use "exn.sml";
[opening exn.sml]
val foo = fn : bool -> string
exception Bar
val bar = fn : bool -> string
val it = () : unit
- foo true;

uncaught exception Foo
  raised at: exn.sml:5.18-5.21
             exn.sml:4.48
- bar true;
val it = "caught" : string
-

(Something like: Each foo-call "creates" a new Foo exn-constructor, so the handle, that pattern matches value constructed with "inner" Foo against "outer" Foo-pattern, fails. And inner Foo carries on, uncaught.

Bar is created outside of bar, so each bar-call deals with same Bar and things behave more behavedly?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment