Our other conversation brought up the issue of error handling with polymorphic variants. I'm starting a separate thread to discuss this too. After 2 years of using polymorphic variants a lot, I'm questioning the viability of the approach. I do really like the precision it provides, but it has also been very cumbersome to maintain. I think we should consider moving to exceptions and/or Or_error. This could accelerate development quite a bit by simplifying the API. Any thoughts on this?
--
You received this message because you are subscribed to the Google Groups "biocaml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biocaml+u...@googlegroups.com.
To post to this group, send email to bio...@googlegroups.com.
Visit this group at http://groups.google.com/group/biocaml.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/CAMu2m2%2Buz_c%3D9xH76%2B6YCqhsnSVLc3EmcDOWUQQXZyFB3QqKLg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
- using exceptions or or_error.t does not really simplify development, it just "delays" part of it (handling and especially documenting errors gets pushed for later, we see that in Core/Async's big lack of documentation)Just to be precise:
('a, [> `Exn of exn | `Failure of string | `Core_or_error of Or_error.t ]) Result.tAlso note that exception types, string, and/or Or_error.t are or can be used alltogether anyway, we just need to agree on the actual names we give to them:The only problem that I've really had with polymorphic-variant-based errors is printing them while wanting to get rid of Camlp4, hopefully with ocaml 4.02.0, there will be no need for camlp4 anymore (extension points, and maybe even runtime types) :)
While the Result.t version provides an Error.parsing value in case of an error, the exception one returns an Error.t, which contains more variants on some other stuff. I would rather have several exception definitions to match the most precise types:val in_channel_to_item_stream : ?buffer_size:int -> ?filename:string -> in_channel ->(item, [> Error.parsing]) Result.t Stream.t(** Parse an input-channel into a stream of [item] results. *)val in_channel_to_item_stream_exn:?buffer_size:int -> ?filename:string -> in_channel -> item Stream.t(** Returns a stream of [item]s.[Stream.next] will raise [Error _] in case of any error. *)
--On Sun, Jan 19, 2014 at 10:57 AM, Ashish Agarwal <agarw...@gmail.com> wrote:
Our other conversation brought up the issue of error handling with polymorphic variants. I'm starting a separate thread to discuss this too. After 2 years of using polymorphic variants a lot, I'm questioning the viability of the approach. I do really like the precision it provides, but it has also been very cumbersome to maintain. I think we should consider moving to exceptions and/or Or_error. This could accelerate development quite a bit by simplifying the API. Any thoughts on this?--
You received this message because you are subscribed to the Google Groups "biocaml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biocaml+u...@googlegroups.com.
To post to this group, send email to bio...@googlegroups.com.
Visit this group at http://groups.google.com/group/biocaml.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/CAMu2m2%2Buz_c%3D9xH76%2B6YCqhsnSVLc3EmcDOWUQQXZyFB3QqKLg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "biocaml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biocaml+u...@googlegroups.com.
To post to this group, send email to bio...@googlegroups.com.
Visit this group at http://groups.google.com/group/biocaml.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/CALScVY%3DJE-JRw8goToX2OYaVhssOaNhZ2J7rMSaBr%3DhYkG%3DirQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/CAOOOohRP4%3DHPxgYqqKj0gai5-qdpLa_fuAxpB-S_V%2B18M%3DCe_w%40mail.gmail.com.
PV requires you to consider errors while EXN allows you to ignore them. Actually, I disagree with this. The PV approach forces us to use the Result monad, and the entire point of that is to systematically ignore errors. You can avoid the monad when you do want to handle an error, but you can also use try ... catch when you want to handle an exception. I don't think PV leads to better error handling, except perhaps indirectly due to the next point.
PV leads to compiler enforced documentation about the possible errors. EXN requires manual diligence to document errors in comments. To me, this is the main difference in the two approaches. Compiler enforced documentation isn't a clear win. You get crazy error messages. The API is more painful since your attention is taken too much by errors, which you usually want to ignore (although this might be resolved by a custom documentation generator).
Maintaining PV errors is harder than with EXN. Right now, we define them all in an Error sub-module, which is annoying. Every time you define a new variant, you have to remember to add it there. Within that module, you might have to refactor the multiple type definitions. On the other hand, if you don't provide the these type definitions, then your specific variant name will get propagated to other signatures. Thus, if you change the name, you'll have to change it in many places or your code won't compile. All this for an error that is almost always ignored. With EXN, you can define precise errors, rename them freely, and it'll almost never require any other change. You just have to grep the source code to make sure you didn't use it somewhere, which you almost never will have.
> I would rather have several exception definitions to match the most precise types:>
> exception Parsing_error of Error.parsing
>
> Would that be ok?In the limit, we could have an exception for each error variant. That actually makes sense to me, but I'm concerned about maintenance.
Thanks for all the discussion. I hope we can keep discussing a bit more, and then we should make a decision.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/CAMu2m2%2BDot0VJy1w3HnHadPkPFESkMTTwdLKra%2BCOeOMqnpfig%40mail.gmail.com.
That's not completely fair: when you decide to handle errors with the Result monad, the compiler does an exhaustivity check, while nothing prevents you from forgetting a case in a try ... with ... expression.
Oh wait, now I get it: if you change the name of the error type then it has to be changed in the signature of all ('a,'b) Result.t returning functions (which mostly ignore the error anyway). Is that it?
My personal opinion would be to at least keep the exception-style functions, with one exception or two at most per function, polymorphic variant type as argument of the exception. If we keep supporting both styles, this polymorphic variant type can then be used in ('a,'b) Result.t returning functions. While I still think the Result monad is too much hassle for me, I do appreciate the rigorous error handling in your parser modules, which has been a real lesson for me (and sometimes a much appreciated help in my own programs!).
--
You received this message because you are subscribed to the Google Groups "biocaml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biocaml+u...@googlegroups.com.
To post to this group, send email to bio...@googlegroups.com.
Visit this group at http://groups.google.com/group/biocaml.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/CAMu2m2JwxBabCL8OY0BU6UCRK9ayTaeQ9%2BeZyv5SGn-tmy6tvg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/biocaml/87bnz56o56.fsf%40gmail.com.