On Mon, Dec 7, 2015 at 8:12 PM, Mark S. Miller <
eri...@google.com> wrote:
>
http://pleiad.dcc.uchile.cl/papers/2014/figueroaAl-sblp2014.pdf
FWIW i've never managed to convince myself to learn haskell so, I
don't get the emphasis on effects, when caps seem useful to me
effect-free as well, i can't be certain that there isn't a effect-free
capability and this is extending capabilities to effects as well, I do
seem to recall a long thread about capabilities to immutable values in
the past on list, but don't recall any concensus :)
In the introduction it references sml's exceptions [6],
I was made aware of this through Andreas Rossberg, when discussing
Marc Stiegler's implementation of sealer/unsealers for Emily which
used effects on boolean references,
Attached is Andreas's makeSealer implementation for standard ML,
including my attempts at explaining/breaking it, Ocaml implementation
at the bottom of the email inline...
The condensed compiler output from SML/nj of various runsj:
val makeSealer = fn : unit -> ('a -> exn) * (exn -> 'a)
datatype Mode = BadUnseal | GoodUnseal | RaiseSealed
val foo = fn : 'a * Mode -> 'a * 'a
val a = ("secret1","secret1") : string * string
val b = ("?","?") : string * string
val c = ("??","??") : string * string
val bar = fn : string -> exn * (exn -> string)
val d = "secret6..." : string
uncaught exception Seal
raised at: mkseal.sml:18.43-18.50
/bin/sml: Fatal error -- Uncaught exception Seal with "secret4" raised at ...
uncaught exception Seal
raised at: mkseal.sml:18.43-18.50
/bin/sml: Fatal error -- Uncaught exception Seal with <unknown> raised at ...
uncaught exception Seal
raised at: mkseal.sml:91.14-91.16
/bin/sml: Fatal error -- Uncaught exception Seal with "secret7" raised at ...
Anyhow I had found this use of exceptions both surprising and
non-obvious, and i hadn't seen or found any examples of it anywhere,
the reference from the paper talks about it but doesn't provide examples.
I've found searching for this particular usage of ML difficult due to
the ubiquity of the
terms involved, e.g. 'let polymorphism', 'polymorphic exceptions' ;)
The issue with the top-level exception was with the SML/NJ compiler,
the other compiler I tested with, mlton produces just "unhandled
exception: Seal" which seems acceptable
the reference states that this is a property of SML exceptions but not
ocaml ones,
the ocaml variation mentioned earlier, it appears to get the same
behaviour through the combination of modules and exceptions, I haven't
tested this one to the same extent (e.g. mixing calls to instances of
sealers/unsealer modules which share the same type) though...
apologies for the wall of text.
module type SEALED =
sig
type t
val seal : t -> exn
val unseal : exn -> t
end
module MakeSealer (X : sig type t end) : SEALED with type t = X.t =
struct
type t = X.t
exception Seal of t
let seal x = Seal x
let unseal = function Seal x -> x | _ -> failwith "unseal"
end
module S = MakeSealer (struct type t = int end)
let n = S.unseal (S.seal 7)