[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • To: David Scott <scott.dj@xxxxxxxxx>
  • From: Anil Madhavapeddy <anil@xxxxxxxxxx>
  • Date: Fri, 14 Oct 2016 15:08:16 +0100
  • Cc: mirageos-devel <mirageos-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 14 Oct 2016 14:08:22 +0000
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=recoil.org; h=content-type :mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; q=dns; s= selector1; b=k0eGZBxYZQoi1V8MOIDKSfTfD0XIlsSXx1mFRgYTyOlTcTWKxDk ayhEK+zWekt2opZ8/pNBkzYccqE+Xrf5FxBFVk+ise4ltuijjE7lHGbBx7jyrHvQ VOP1JWHpuhd0fi5orhHXhkGgK++rlThNYfy2mQz6wKNXk/RS7eEEy5OU=
  • List-id: Developer list for MirageOS <mirageos-devel.lists.xenproject.org>

> On 14 Oct 2016, at 15:05, David Scott <scott.dj@xxxxxxxxx> wrote:
> On Fri, Oct 14, 2016 at 2:51 PM, Anil Madhavapeddy <anil@xxxxxxxxxx> 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 like Ipaddr to 
>> using the Result type instead, so it would be
>> val foo : ... -> ('a, [`Msg of string]) result
>> instead, using the Result type?  That would let libraries use combinators 
>> such as Rresult, and not gobble errors from parsing silently.  It would be 
>> an incompatible API bump so we would need to bump all consumers of, e.g. 
>> Ipaddr  http://docs.mirage.io/ipaddr/Ipaddr_unix.V4.html simultaneously.

> Personally I like the sound of this-- it's nice to use combinators to parse a 
> more complicated structure and be able to emit something more useful than 
> "None" as an error. Should we write a "recommended conventions" doc or wiki 
> page to include things like `foo_exn` and `foo` examples above?

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: 
- Lwt_result has a slightly different set of combinators 

So I guess we need to decide if we publish an Rresult_lwt.t which lifts up 
"('a,'b) result" into an Lwt.t with the same API as Rresult otherwise.


MirageOS-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.