Browse thread
Ocaml type with constraints?
-
Angela Zhu
-
Andrej Bauer
- Martin Jambon
- Gordon Henriksen
- Jacques Garrigue
-
Andrej Bauer
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin.jambon@e...> |
| Subject: | Re: [Caml-list] Ocaml type with constraints? |
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/