English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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