Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
null values and sentinels
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-01-18 (11:10)
From: Anton Moscal <msk@p...>
Subject: Re: null values and sentinels

On Tue, 12 Jan 1999, Jerry Jackson wrote:

> Hello,
> I'd like to know what the recommended solution to the following 
> situation is...
> I'd like to create a type like:
> # type foo = {xxx: int; mutable yyy: foo};;
> so that I can add nodes by mutating the "yyy" slots.  Unfortunately,
> it seems that I must create a sentinel value of type "foo" to stand
> for a null pointer.  This works but I'd like to be able to use pattern
> matching on the value of yyy so as to get compile-time warnings if I
> forget to check for null.

The only known to me solution is the following:


    let rec foo_nil = {xxx=1; yyy = foo_nil};

and then use foo_nil as Nil constant. The main problem is the
following: foo_nil can't be used in the matching.
Anton E.Moscal