From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 8B8AABB84 for ; Mon, 22 Sep 2008 00:05:23 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoQDACdi1khbucREiGdsb2JhbACTHQEBARUioGeBZg X-IronPort-AV: E=Sophos;i="4.32,442,1217800800"; d="scan'208";a="17196317" Received: from post.literal.si ([91.185.196.68]) by mail3-smtp-sop.national.inria.fr with ESMTP; 22 Sep 2008 00:05:23 +0200 Received: from localhost (post.literal.si [91.185.196.68]) by post.literal.si (Postfix) with ESMTP id 07DCF10E481F; Mon, 22 Sep 2008 00:05:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at literal.si Received: from post.literal.si ([91.185.196.68]) by localhost (post.literal.si [91.185.196.68]) (amavisd-new, port 10024) with ESMTP id wzI+d1ezALvq; Mon, 22 Sep 2008 00:05:19 +0200 (CEST) Received: from [192.168.1.100] (BSN-77-148-136.static.dsl.siol.net [193.77.148.136]) by post.literal.si (Postfix) with ESMTP id D427410E4801; Mon, 22 Sep 2008 00:05:18 +0200 (CEST) Message-ID: <48D6C51E.5060901@andrej.com> Date: Mon, 22 Sep 2008 00:05:18 +0200 From: Andrej Bauer Reply-To: Andrej.Bauer@andrej.com User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Angela Zhu , caml-list Subject: Re: [Caml-list] Ocaml type with constraints? References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; andrej:01 andrej:01 ocaml:01 ocaml:01 checker:01 undecidable:01 angela:98 wrote:01 compile:01 caml-list:01 int:01 define:02 define:02 expression:02 evaluates:02 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. Best regards, Andrej