Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Anil Madhavapeddy
On 18 Oct 2016, at 15:01, Richard Mortier wrote: > > On 18 October 2016 at 15:00, Daniel Bünzli > wrote: >> On Tuesday 18 October 2016 at 15:41, Richard Mortier wrote: >>> Sorry-- not familiar enough with the terminology. Any chance one of >>> you could point to an example of using "inclusion r

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Richard Mortier
On 18 October 2016 at 15:00, Daniel Bünzli wrote: > On Tuesday 18 October 2016 at 15:41, Richard Mortier wrote: >> Sorry-- not familiar enough with the terminology. Any chance one of >> you could point to an example of using "inclusion rather than union" >> please? > > type err = [ `Sub of Sub.err

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Daniel Bünzli
On Tuesday 18 October 2016 at 15:41, Richard Mortier wrote: > Sorry-- not familiar enough with the terminology. Any chance one of > you could point to an example of using "inclusion rather than union" > please? type err = [ `Sub of Sub.err | `Other | ... ] vs type err = [ Sub.err | `Other | ..

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Richard Mortier
On 18 October 2016 at 14:24, Ashish Agarwal wrote: > On Tue, Oct 18, 2016 at 4:38 AM, Daniel Bünzli > wrote: > >> I think you should transform your errors according to your level of >> abstraction as much as you do with your values. > > That's a good goal. Yes; I think it fits very well with the

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Anil Madhavapeddy
On 18 Oct 2016, at 14:24, Ashish Agarwal wrote: > > On Tue, Oct 18, 2016 at 4:38 AM, Daniel Bünzli > wrote: > > I think you should transform your errors according to your level of > abstraction as much as you do with your values. > > That's a good goal. > > Also using inclusion (by tagging

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Ashish Agarwal
On Tue, Oct 18, 2016 at 4:38 AM, Daniel Bünzli wrote: I think you should transform your errors according to your level of > abstraction as much as you do with your values. That's a good goal. > Also using inclusion (by tagging an error subset) rather than union for > errors reported by subsys

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-18 Thread Daniel Bünzli
On Monday 17 October 2016 at 22:49, Ashish Agarwal wrote: > That's an interesting proposal. So you throw away the precision at some > point. It seems a shame, but maybe that's good enough to get most of the > value. I think you should transform your errors according to your level of abstract

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-17 Thread Ashish Agarwal
On Mon, Oct 17, 2016 at 4:41 PM, Daniel Bünzli wrote: As I said, monadic join. > I wasn't sure if that would cover the patterns that arise. Perhaps it does. propagated to more generic error data types to the top level or to a > logging point. That's an interesting proposal. So you throw away

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-17 Thread Daniel Bünzli
On Monday 17 October 2016 at 21:40, Ashish Agarwal wrote: > True, these are even more precise, but the types are getting even more hairy > now. Are there good combinators that help you anymore, or do we end up doing > a lot of explicit match cases. As I said, monadic join. > I agree that good

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-17 Thread Ashish Agarwal
On Mon, Oct 17, 2016 at 3:18 PM, Daniel Bünzli wrote: You want to make a clear distinction between the errors of the bracket and > those of the client function (especially if these end up having overlapping > cases) so you rather want either: > > 1) string -> f:(t -> 'a) -> ('a, [> err]) result >

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-17 Thread Daniel Bünzli
On Friday 14 October 2016 at 18:03, Ashish Agarwal wrote: > With this style, you end up wanting to define a function like: > > val with_file : > string -> > f : (t -> (‘a, ‘b) Result.t -> > (‘a, [> err | ‘b]) Result.t Not really. You want to make a clear distinction between the errors of the br

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-17 Thread Ashish Agarwal
On Mon, Oct 17, 2016 at 10:53 AM, Richard Mortier < richard.mort...@cl.cam.ac.uk> wrote: > What was your experience here? Why *would* one force a closed type? > First, a terminology correction. What I was calling a "closed" variant is actually an "exact" variant. A "closed" variant is of the for

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-17 Thread Richard Mortier
Hi Ashish; Thanks for this mail, very useful! A couple of (naive!) queries/comments inline. On 14 October 2016 at 17:03, Ashish Agarwal wrote: > Using polymorphic variants for the error type poses some challenges. Here > are some things to think about. (The following code assumes `open Async.Std`

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Mindy
On 10/14/2016 11:03 AM, Ashish Agarwal wrote: Using polymorphic variants for the error type poses some challenges. Here are some things to think about. (The following code assumes `open Async.Std` because it already has the necessary combinators). Error Unification # let x = return (Error `Ba

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Ashish Agarwal
Using polymorphic variants for the error type poses some challenges. Here are some things to think about. (The following code assumes `open Async.Std` because it already has the necessary combinators). Error Unification # let x = return (Error `Bad);; val x : ('a, [> `Bad ]) Result.t Deferred.t =

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Hannes Mehnert
On 14/10/2016 15:44, Anil Madhavapeddy wrote: > On 14 Oct 2016, at 15:36, David Scott wrote: >> >> Looks like we have a number of different conventions for the binds. Do we >> want to have the same set of operators with and without Lwt support (and >> open the Infix module locally as needed) or

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Richard Mortier
On 14 October 2016 at 15:36, David Scott wrote: >> Looks like we have a number of different conventions for the binds. Do we >> want to have the same set of operators with and without Lwt support (and >> open the Infix module locally as needed) or separate operators that be used >> alongside each

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Anil Madhavapeddy
On 14 Oct 2016, at 15:36, David Scott wrote: > > Looks like we have a number of different conventions for the binds. Do we > want to have the same set of operators with and without Lwt support (and open > the Infix module locally as needed) or separate operators that be used > alongside each

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Anil Madhavapeddy
> On 14 Oct 2016, at 15:31, Hannes Mehnert wrote: > > [again raising the issue: could some mailing list admin please set the > reply-to to the list -- there's no need to send the message to the > individual and to the list!] > > On 14/10/2016 15:23, Anil Madhavapeddy wrote: >> On 14 Oct 2016, a

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread David Scott
On Fri, Oct 14, 2016 at 3:23 PM, Anil Madhavapeddy wrote: > On 14 Oct 2016, at 15:11, Hannes Mehnert wrote: > > > > On 14/10/2016 15:08, Anil Madhavapeddy wrote: > >> Yeah, once we agree on the conventions :-) Once we have everything > using Result.t, we also need to find the right set of combi

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Daniel Bünzli
On Friday 14 October 2016 at 16:18, Anil Madhavapeddy wrote: > This is largely within libraries, so the impact wouldn't be too bad. I do > notice that PCLOCK, MCLOCK and IP types do use option to signify failure > though, which would be mirage-types churn... PCLOCK and MCLOCK do not use options

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Hannes Mehnert
[again raising the issue: could some mailing list admin please set the reply-to to the list -- there's no need to send the message to the individual and to the list!] On 14/10/2016 15:23, Anil Madhavapeddy wrote: > On 14 Oct 2016, at 15:11, Hannes Mehnert wrote: >> >> On 14/10/2016 15:08, Anil Ma

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Mindy
On 10/14/2016 09:08 AM, Richard Mortier wrote: On 14 October 2016 at 14:51, Anil Madhavapeddy wrote: Should we take the Mirage3 opportunity to port libraries like Ipaddr to using the Result type instead I think that would be a good thing-- only concern would be how much it would delay the re

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Anil Madhavapeddy
On 14 Oct 2016, at 15:11, Hannes Mehnert wrote: > > On 14/10/2016 15:08, Anil Madhavapeddy wrote: >> Yeah, once we agree on the conventions :-) Once we have everything using >> Result.t, we also need to find the right set of combinators. >> >> - There is Rresult for basic Result.t handling: >

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Hannes Mehnert
On 14/10/2016 15:18, Anil Madhavapeddy wrote: > This is largely within libraries, so the impact wouldn't be too bad. I do > notice that PCLOCK, MCLOCK and IP types do use option to signify failure > though, which would be mirage-types churn... Well, in mirage-types we use (sometimes) `unit Lwt.

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Hannes Mehnert
On 14/10/2016 15:08, Anil Madhavapeddy wrote: > >> On 14 Oct 2016, at 15:05, David Scott wrote: >> >> >> On Fri, Oct 14, 2016 at 2:51 PM, Anil Madhavapeddy wrote: >>> We have quite a few base libraries that use the pattern of >>> >>> val foo_exn : ... -> 'a >>> @raises >>> >>> val foo: ... -> 'a

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Anil Madhavapeddy
On 14 Oct 2016, at 15:08, Richard Mortier wrote: > > On 14 October 2016 at 14:51, Anil Madhavapeddy wrote: >> Should we take the Mirage3 opportunity to port libraries like Ipaddr to >> using the Result type instead > > I think that would be a good thing-- only concern would be how much it > wo

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Amir Chaudhry
> On 14 Oct 2016, at 15:08, Richard Mortier > wrote: > > On 14 October 2016 at 14:51, Anil Madhavapeddy wrote: >> Should we take the Mirage3 opportunity to port libraries like Ipaddr to >> using the Result type instead > > I think that would be a good thing-- only concern would be how much i

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Richard Mortier
On 14 October 2016 at 14:51, Anil Madhavapeddy wrote: > Should we take the Mirage3 opportunity to port libraries like Ipaddr to using > the Result type instead I think that would be a good thing-- only concern would be how much it would delay the release? (Do we have a timeline for that in fact

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Anil Madhavapeddy
> On 14 Oct 2016, at 15:05, David Scott wrote: > > > On Fri, Oct 14, 2016 at 2:51 PM, Anil Madhavapeddy wrote: >> We have quite a few base libraries that use the pattern of >> >> val foo_exn : ... -> 'a >> @raises >> >> val foo: ... -> 'a option >> Gobbles the exception and returns Some/None

Re: [MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread David Scott
On Fri, Oct 14, 2016 at 2:51 PM, Anil Madhavapeddy wrote: > We have quite a few base libraries that use the pattern of > > val foo_exn : ... -> 'a > @raises > > val foo: ... -> 'a option > Gobbles the exception and returns Some/None > > Should we take the Mirage3 opportunity to port libraries lik

[MirageOS-devel] Using Result instead of Option in libraries

2016-10-14 Thread Anil Madhavapeddy
We have quite a few base libraries that use the pattern of val foo_exn : ... -> 'a @raises val foo: ... -> 'a option Gobbles the exception and returns Some/None Should we take the Mirage3 opportunity to port libraries like Ipaddr to using the Result type instead, so it would be val foo : ... -