List Info

Thread: "ocaml_beginners"::[] type constructors again




"ocaml_beginners"::[] type constructors again
country flaguser name
Germany
2007-05-26 12:21:41

Hi folks,
if I define my own data types in OCaml... Can I impose additional
restrictions within a type constructor? For example, to represent a
"time value"; with fields hour, min, sec, then the field values should
lie within 0-23 (for hour), 0-59 (for min/sec).

Best regards,
Thomas

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] type constructors again
country flaguser name
Germany
2007-05-26 13:02:47

Am Sat, 26 May 2007 19:21:41 +0200
schrieb Thomas Heye < 1910-131%40onlinehome.de">1910-131onlinehome.de>:

> Hi folks,
&gt; if I define my own data types in OCaml... Can I impose additional
> restrictions within a type constructor? For example, to represent a
> "time value"; with fields hour, min, sec, then the field values should
&gt; lie within 0-23 (for hour), 0-59 (for min/sec).
>
> Best regards,
> Thomas

you can make the datatype private, so values of it can only be created
with your functions, but pattern matching works.

Michael

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] type constructors again
country flaguser name
United Kingdom
2007-05-26 13:08:12

On Sat, May 26, 2007 at 07:21:41PM +0200, Thomas Heye wrote:
&gt; Hi folks,
&gt; if I define my own data types in OCaml... Can I impose additional
> restrictions within a type constructor? For example, to represent a
> "time value"; with fields hour, min, sec, then the field values should
&gt; lie within 0-23 (for hour), 0-59 (for min/sec).

Micha's suggestion is good.

Specifically to represent dates and times, you might also want to use
the Calendar module: http://www.lri.fr/~signoles/prog.en.html#calendar

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )