From: Sylvain Le Gall <sylvain@le-gall.net>
To: caml-list@inria.fr
Subject: [Caml-list] Types for solved and unsolved conditional values
Date: Fri, 20 May 2011 12:03:17 +0000 (UTC) [thread overview]
Message-ID: <slrnitcm45.ks.sylvain@gallu.homelinux.org> (raw)
Hello all,
I would like to express a conditional value that can be either solved or
unsolved and be able to quickly match the result, in the case of a
solved value. The value returned should be 'a.
Some code:
type ('a, 'b) conditional
type 'a unsolved = ('a, (expr, 'a) list) conditional
type 'a solved = ('a, [`Always 'a | `NotSolved]) conditional
(* Unsolved conditional *)
let myval =
[EFlag "foo", "foo";
EBool true, "nofoo"]
(* Solved conditional *)
let myval' =
`Always "foo"
A basic solution would be to make types independent, this way:
type ('a, 'b) conditional = 'a, (expr * 'b) list
type 'a unsolved = ('a, unit) conditional
type 'a solved = ('a, [`Always of int | `NotSolved]) conditional
let myval =
(),
[EFlag "foo", "foo";
EBool true, "nofoo"]
let myval' =
`Always 0,
[EFlag "foo", "foo";
EBool true, "nofoo"]
But I don't feel it is the right solution. Is there any way to do it
better ?
Cheers,
Sylvain Le Gall
--
My company: http://www.ocamlcore.com
Linkedin: http://fr.linkedin.com/in/sylvainlegall
Start an OCaml project here: http://forge.ocamlcore.org
OCaml blogs: http://planet.ocamlcore.org
next reply other threads:[~2011-05-20 12:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-20 12:03 Sylvain Le Gall [this message]
2011-05-20 12:32 ` [Caml-list] " Sylvain Le Gall
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=slrnitcm45.ks.sylvain@gallu.homelinux.org \
--to=sylvain@le-gall.net \
--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