[Haskell-cafe] Can I destructive rebind a local variable in haskell?

2009-01-05 Thread Wang, Chunye (NSN - CN/Beijing)
Dear haskeller, Can I destructive rebind a local variable like this import System.Directory test filename = do is_dir <- doesDirectoryExist filename let filename = if not is_dir then filename else filename putStrLn $ " filename " ++ filename main = test "." in GHCi 6.10.1 on Wi

Re: [Haskell-cafe] Can I destructive rebind a local variable in haskell?

2009-01-05 Thread Luke Palmer
2009/1/6 Wang, Chunye (NSN - CN/Beijing) Dear haskeller, > > > Can I destructive rebind a local variable like this > > import System.Directory > test filename = do > is_dir <- doesDirectoryExist filename > let filename = if not is_dir then filename else filename > Nope. The "filename" on

RE: [Haskell-cafe] Can I destructive rebind a local variable in haskell?

2009-01-05 Thread Wang, Chunye (NSN - CN/Beijing)
destructive rebind a local variable in haskell? 2009/1/6 Wang, Chunye (NSN - CN/Beijing) Dear haskeller, Can I destructive rebind a local variable like this import System.Directory test filename = do is_dir <- doesDirectoryExist filen

Re: [Haskell-cafe] Can I destructive rebind a local variable in haskell?

2009-01-06 Thread Evan Laforge
2009/1/6 Luke Palmer : > 2009/1/6 Wang, Chunye (NSN - CN/Beijing) > Dear haskeller, >> >> >> Can I destructive rebind a local variable like this >> >> import System.Directory >> test filename = do >> is_dir <- doesDirectoryExist filename >> let filename = if not is_dir then filename else f

RE: [Haskell-cafe] Can I destructive rebind a local variable in haskell?

2009-01-06 Thread Wang, Chunye (NSN - CN/Beijing)
Hi Evan, > You can also reuse the name exactly by using bind+return instead of let: > test filename = do > is_dir <- doesDirectoryExist filename > filename <- return $ if not is_dir then filename else filename > I'm not a huge fan of the prime thing because it's tiny and easy to miss and if y

Re: [Haskell-cafe] Can I destructive rebind a local variable in haskell?

2009-01-06 Thread Evan Laforge
> Nice. Good solution. ``imperative style'' is not a bad idea when I'm > not used to the ``pure functional style'' > > E.g. > > filename <- return $ combine filename "Makefile" > > Similar to the other imperative language > > filename = joinPath(filename,"Makefile") I wouldn't consider it