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
Pattern matching over lazy values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-18 (15:08)
From: Jon Harrop <jon@f...>
Subject: Pattern matching over lazy values

Incidentally, would it not be enormously beneficial to be able to pattern 
match over lazy values?

This syntax is never used:

# fun (x y) -> true;;
Syntax error: ')' expected, the highlighted '(' might be unmatched

so you can allow "lazy foo" as a pattern:

# let force (lazy n) = n;;
val force : 'a lazy_t -> 'a

and then make the pattern match force lazy values only as it comes across 
them, so you can pattern match over lazy trees. I can't see any way to do 
this without hacking the compiler...

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists