Version franēaise
Home     About     Download     Resources     Contact us    
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: -- (:)
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
   Hello

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.

Cheers,

-- 
Bardur Arantsson
<bardurREMOVE@THISscientician.net>

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