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
Re: Seeking pratical tutorial or examples.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-10-20 (12:44)
From: Bruce Hoult <bruce@h...>
Subject: multiple destructuring?
I'm just starting to play with OCaml and I wrote the following function:

let rec is_sorted lst =
    match lst with
       [] -> true
    | [elt] -> true
    | a :: b :: tail -> a<b & is_sorted(b :: tail)

I'm wondering whether the b :: tail actually allocates memory or is 
the compiler smarter than that?  What's the best way to avoid this? 
If I rewrite to match instead with "a :: tail" (and then later pull 
that apart into b :: more_tail) am I guaranteed that tail is 
non-empty because of the prior [elt] case?

-- Bruce