caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] SDL2 bindings, testers and feedback welcome
Date: Wed, 12 Feb 2014 11:43:17 +0100	[thread overview]
Message-ID: <F69ABBC982DF4D8B85D8EF82E3079BE0@erratique.ch> (raw)
In-Reply-To: <4DDEBB7487B641C0834F09D522EA9918@erratique.ch>

Le mardi, 17 décembre 2013 à 07:11, Daniel Bünzli a écrit :
> * I used an 'a result = [ `Error | `Ok of 'a ] rather than an exception
> for functions that return error codes/null is error. I tend to lean
> on exceptionless designs but I'm still unsure whether it is a good
> idea that case. One of the problems is that SDL doesn't make a clear
> distinction (at the signature level *and* in the documentation)
> between programming errors (invalid_arg), exceptional errors
> (e.g. out of memory) and non-exceptional errors (e.g. could not
> access/setup a resource).

I found that in practice directly returning the string you get by SDL_GetError () in the `Error case is much more convenient. E.g. with the above type your bind looks like this:

let ( >>= ) x f = match x with  
| `Error -> `Error_msg (Sdl.get_error ())  
| `Error_msg _ as e -> e
| `Ok v -> f v



which is needlessly unconvenient. So I'm changing that type to  

'a result = [ `Error of string | `Ok of 'a ]

and you always directly get the result of Sdl.get_error () in the `Error case.  

Best,

Daniel



      parent reply	other threads:[~2014-02-12 10:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17  6:11 Daniel Bünzli
2013-12-17  7:02 ` Anthony Tavener
2013-12-17 14:17 ` Florent Monnier
2013-12-17 15:14   ` Daniel Bünzli
2013-12-18  6:54   ` Erkki Seppala
2013-12-18  8:05     ` Anthony Tavener
2013-12-18  9:24       ` Daniel Bünzli
2013-12-18  8:18     ` Florent Monnier
2013-12-22 10:01       ` Kakadu
2013-12-30 13:28         ` Vu Ngoc San
2013-12-17 17:05 ` Ashish Agarwal
2013-12-17 17:47   ` Daniel Bünzli
2013-12-17 18:57     ` Ashish Agarwal
2013-12-17 19:45       ` Anthony Tavener
2013-12-18 15:40         ` Ashish Agarwal
2013-12-18 18:02           ` Yotam Barnoy
2013-12-18 19:53             ` Daniel Bünzli
2013-12-18 22:29               ` Ashish Agarwal
2013-12-18 22:45                 ` Daniel Bünzli
2013-12-17 20:26       ` Daniel Bünzli
2013-12-18  1:13         ` Francois Berenger
2013-12-18  6:44           ` Erkki Seppala
2013-12-18  9:21           ` Daniel Bünzli
2013-12-19  1:11             ` Florent Monnier
2013-12-19  6:39       ` Florent Monnier
2013-12-17 19:29     ` Erkki Seppala
2013-12-19  5:20 ` Florent Monnier
2013-12-19  5:27   ` Florent Monnier
2013-12-19  7:13   ` Daniel Bünzli
2013-12-19 12:38     ` Florent Monnier
2014-02-12 10:43 ` Daniel Bünzli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F69ABBC982DF4D8B85D8EF82E3079BE0@erratique.ch \
    --to=daniel.buenzli@erratique.ch \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).