<div dir="ltr">As a part of the multicore OCaml work, we are developing an effect system for OCaml. The effect system could be used for describing *checked* exceptions. Leo's developing a prototype [0], and which already looks very promising:<div><br></div><div>===</div><div><br></div><div><div># effect not_found = Not_found;;</div><div><br></div><div>effect not_found = Not_found</div><div><br></div><div># let half x =</div><div> if x mod 2 = 0 then x / 2</div><div> else perform Not_found;;</div><div><br></div><div>val half : int -[not_found | io]-> int = <fun></div><div><br></div><div># half 7;;</div><div><br></div><div>Characters 0-6:</div><div> half 7;;</div><div> ^^^^^^</div><div>Error: This expression performs effect [not_found | io | !~]</div><div> but an expression was expected that performed [io]</div><div> Type [not_found | !~] is not compatible with type [] </div><div><br></div><div># let not_found_to_opt f x =</div><div> match f x with</div><div> | x -> Some x</div><div> | effect Not_found -> None;;</div><div><br></div><div>val not_found_to_opt : ('a -[not_found | !~]-> 'b) => 'a ~> 'b option = <fun></div><div><br></div><div># not_found_to_opt half 7;;</div><div><br></div><div>- : int option = None</div><div><br></div><div># not_found_to_opt half 8;;</div><div><br></div><div>- : int option = Some 4</div><div><br></div><div>===</div><div><br></div><div>[0]: <a href="https://github.com/lpw25/ocaml/tree/ecaml">https://github.com/lpw25/ocaml/tree/ecaml</a></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 31, 2016 at 8:28 PM, Nik Sultana <span dir="ltr"><<a href="mailto:ns441@cam.ac.uk" target="_blank">ns441@cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm not sure if there already exists such functionality for OCaml, but thought that adapting this work to OCaml from SML might make an interesting project for somebody on this list:<br>
<br>
"Estimating uncaught exceptions in Standard ML programs from type-based equations" by Yi et al.<br>
<abstract><br>
We present a static analysis that detects potential runtime exceptions that are raised and never handled inside Standard ML (SML) programs. Contrary to our earlier method (Yi, 1994) based on abstract interpretation, where the input program's control flow is simultaneously computed while our exception analysis progresses, we separate the two phases in a manner similar to conventional data flow analysis. Before the exception analysis begins, we first estimate the input program's control flow from the type information from SML/NJ compiler. Based on this call-graph structure, exception flow is specified as a set of equations, whose solution is computed using an iterative least fixpoint method. A prototype of this analysis is applied to two realistic SML programs (ML-LEX and OR-SML core) and is 3 or 40 times faster than the earlier method and saves memory by 35 or 65 percent<br>
</abstract><br>
<br>
The full paper's at <a href="http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=544613" rel="noreferrer" target="_blank">http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=544613</a><br>
_______________________________________________<br>
Cam-compiler-hacking mailing list<br>
<a href="mailto:Cam-compiler-hacking@lists.ocaml.org" target="_blank">Cam-compiler-hacking@lists.ocaml.org</a><br>
<a href="http://lists.ocaml.org/listinfo/cam-compiler-hacking" rel="noreferrer" target="_blank">http://lists.ocaml.org/listinfo/cam-compiler-hacking</a><br>
</blockquote></div><br></div>