caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: Ocaml <caml-list@inria.fr>
Subject: [Caml-list] Feature wish: types with invariants
Date: Fri, 30 Aug 2002 12:57:05 +0200	[thread overview]
Message-ID: <3D6F4F81.4000908@baretta.com> (raw)

This is a *wish* as opposed to a *request* because it does 
not add to the power of the language but only to the comfort 
and ease of use.

I would like to have the possiblity of expressing invariant 
properties which must always hold on a given datatype I'm in 
the process of defining. Consider the following definition 
of a doubly linked list:

type 'a dlist = 'a option * 'a * 'a option

There is absolutely no way to distinguish this data 
structure from that of a binary tree, or, worse yet, of a 
directed graph.

In order to enforce the structural properties of a dlist, I 
would need to disseminate the code with assertions. 
Basically, I'd like the compiler to throw in assertions for 
me whenever a new value of type dlist is constructed. Such 
assertions would have to verify invariant properties 
specified in the definition of the type.

I'd like to write:

exception Dlist_exn
type 'a dlist = 'a option * 'a * 'a option : ( dlist_value )
   where
     (match dlist_value with
        | None, _, None -> true
        | Some(_, _, this), _, None -> this == dlist_value
        | None, _, Some(this, _, _) -> this == dlist_value
        | Some(_, _, this1), _, Some(this2, _, _) ->
            this1 == dlist_value && this2 == dlist_value
      ) otherwise Dlist_exn

What do you guys think? It should not be overly messy, or am 
I completely mistaken?

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


                 reply	other threads:[~2002-08-30 10:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=3D6F4F81.4000908@baretta.com \
    --to=alex@baretta.com \
    --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).