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
Help me find this pdf
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-10-19 (05:09)
From: Bįršur_Įrantsson <spam@s...>
Subject: Re: Help me find this pdf
Jon Harrop wrote:
> On Thursday 18 October 2007 15:22:32 Brian Hurt wrote:
>> You have to explicitly force the lazy value first-
> If you force all lazy values before the pattern match then you are doing eager 
> evaluation, not lazy. Moreover, you must also generate an auxiliary data 
> structure to store the forced values in order to pattern match over them.
>> but other than it being explicit,
> And not lazy.
>> this is no different from other languages that implicitly force the value
>> for you. 
[--snip-- lots of examples --snip--]

What you're saying is basically that lazy pattern matching should only 
force as much of the value under examination as is actually necessary to 
decide if there's a match. Do I have that right?

If so, then Haskell does exactly this. Here's a small example:

   import Debug.Trace

   x = trace "Evaluated x" "Hello"
   y = trace "Evaluated y" "World"

   main :: IO ()
   main = do
     let l = [x, y]
     case l of
       (a:_) -> do
              putStrLn "Non-empty list"
              putStrLn a
       _     -> putStrLn "Empty list"

This outputs

   Non-empty list
   Evaluated x

Note that if you don't add that "putStrLn a" there, Haskell won't even 
force x!

You're definitely right that doing anything of this sort is currently 
quite painful in OCaml.


Bardur Arantsson

It hovered above the ground, much in the way that bricks don't.
                  Douglas Adams, 'Hitchiker's Guide to the Galaxy'