caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Malcolm Matalka <mmatalka@gmail.com>
To: David MENTRE <dmentre@linux-france.org>
Cc: Francois Berenger <berenger@riken.jp>,  caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] some beautiful OCaml code
Date: Wed, 09 Jan 2013 05:06:10 -0500	[thread overview]
Message-ID: <878v82r7ql.fsf@li195-236.members.linode.com> (raw)
In-Reply-To: <CAC3Lx=bkQMo50rs=zjUpz==y_RzUffLCCDX5wcNK0Q=Mn_j5xQ@mail.gmail.com> (David MENTRE's message of "Wed, 9 Jan 2013 09:38:51 +0100")

Hey, author here,

The problem polymorphic variants are solving here is that if you want to
sequence unrelated functions but return their errors, you have to join
their return types with the return types of the function that is calling
them.  Polymorphic variants basically do this for you without every
function defining its own error return variant.

This, so far, is the only time I have found polymorphic variants the
best solution for a problem in Ocaml.

/Malcolm

David MENTRE <dmentre@linux-france.org> writes:

> Hello OCaml experts,
>
> 2013/1/9 Francois Berenger <berenger@riken.jp>:
>> There is a full blog post about it there:
>>
>> http://functional-orbitz.blogspot.se/2013/01/introduction-to-resultt-vs-exceptions.html
>
> Regarding this blog post, the final code is using Polymorphic Variants
> (http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#toc36).
> E.g.
> """
>     | _ ->
>       Error (`Bad_line s)
> """
>
> I never fully grasped polymorphic variants compared to regular ones
> but I always had the feeling the polymorphic variants where less safe
> that variants because they would allow more possibility to mix
> unrelated things[1].
>
> Are the use of polymorphic variant mandatory to write code
> Return-Value-style code or can regular variants be used?
>
> Best regards,
> david
>
> [1] Of course this ability is the very thing that is of interest to
> people using polymorphic variants.

  reply	other threads:[~2013-01-09 10:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-09  3:48 Francois Berenger
2013-01-09  8:38 ` David MENTRE
2013-01-09 10:06   ` Malcolm Matalka [this message]
2013-01-10  8:13     ` David MENTRE
2013-01-09 13:15   ` AW: " Gerd Stolpmann
2013-01-09 14:15   ` Kristopher Micinski

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=878v82r7ql.fsf@li195-236.members.linode.com \
    --to=mmatalka@gmail.com \
    --cc=berenger@riken.jp \
    --cc=caml-list@inria.fr \
    --cc=dmentre@linux-france.org \
    /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).