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

Wang, Chunye (NSN - CN/Beijing) chunye.wang at nsn.com
Tue Jan 6 03:20:16 EST 2009

Hi Evan,

> You can also reuse the name exactly by using bind+return instead of
> 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 you forget it you probably won't get a type error, you'll
just get a bug, possibly a subtle one.  Besides, what's the next step?
>  filename''?  filename'''?

   Nice. Good solution.  ``imperative style'' is not a bad idea when I'm
not used to the ``pure functional style''


   filename  <- return $ combine filename "Makefile"

Similar to the other imperative language 

   filename = joinPath(filename,"Makefile")

 and I often write similar code in EmacsLisp also.
 It is not so buggy, because we live in "imperitive programming" for
long time

Best Regards
Chunye Wang <chunye.wang at nsn.com>

More information about the Haskell-Cafe mailing list