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: Zheng Li <li@p...>
Subject: Re: Help me find this pdf
Bįršur Įrantsson <spam@scientician.net> writes:
> 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

Isn't it just a matter of explicit and implicit?

let x = [<'(print_endline "evaluate x"; "hello")>]
let y = [<'(print_endline "evaluate y"; "hello")>]

let main () =
  let l = [x;y] in
  match l with
  | h::_ -> print_endline "Non-empty list"; print_endline (Stream.next h)
  | _ -> print_endline "Empty list"

Also look at the SDFlow [1] I released a few days ago. It's lazy, combinatorial
and non-strict (but deterministic). If you really want a lazy list in the exact
haskell style, I have no problem to provide a SDList later (given more time),
the only missing pieces from SDFlow to also be considered as lazy lists are:

  - destructive -> nondestructive (dozens of lines)
  - relax recursive value restriction (a camlp4 script) 

[1] http://www.pps.jussieu.fr/~li/software/index.html#sdflow


> 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'

-- 
Zheng Li
http://www.pps.jussieu.fr/~li