caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Andrej Bauer <Andrej.Bauer@andrej.com>
Cc: Angela Zhu <angela22.zhu@gmail.com>,
	caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Ocaml type with constraints?
Date: Mon, 22 Sep 2008 01:10:26 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0809220103340.12588@martin.ec.wink.com> (raw)
In-Reply-To: <48D6C51E.5060901@andrej.com>

On Mon, 22 Sep 2008, Andrej Bauer wrote:

> Angela Zhu wrote:
>> Hi,
>>
>> I want to define an OCaml type with constraints.
>> For example:
>>
>> type item = Item of int * float;;
>>
>> If here this float type is for price of some item, and I want to make sure
>> it is positive. In other words, if x = (xi, xf) of type item,
>> I want to enforce, xf must >= 0.
>>
>> Is there a way to define OCaml type like this?
>
> No, because Ocaml type checker always check all the types at compile
> time. It is an undecidable problem whether a given expression of type
> float evaluates to a non-negative number.

By the way, even float does not guarantee to have a number: 0./.0. 
compiles and runs happily.


Martin

--
http://mjambon.com/


  reply	other threads:[~2008-09-21 23:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-21 22:01 Angela Zhu
2008-09-21 22:05 ` [Caml-list] " Andrej Bauer
2008-09-21 23:10   ` Martin Jambon [this message]
2008-09-21 22:50 ` Gordon Henriksen
2008-09-21 23:55 ` Jacques Garrigue

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=Pine.LNX.4.64.0809220103340.12588@martin.ec.wink.com \
    --to=martin.jambon@ens-lyon.org \
    --cc=Andrej.Bauer@andrej.com \
    --cc=angela22.zhu@gmail.com \
    --cc=caml-list@yquem.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).