<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3462" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=宋体 color=#0000ff size=2><SPAN
class=079434607-06012009>Hi Luke</SPAN></FONT></DIV>
<DIV><FONT face=宋体 color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=079434607-06012009><FONT face=宋体 color=#0000ff
size=2> Thank you ! I got it :)</FONT></SPAN></DIV>
<DIV><SPAN class=079434607-06012009></SPAN> </DIV>
<DIV><SPAN class=079434607-06012009></SPAN><SPAN lang=en-us><FONT face=Arial
size=2>Best Regards</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial
size=2>Chunye Wang <chunye.wang@nsn.com></FONT></SPAN> </DIV>
<DIV> </DIV><BR>
<DIV class=OutlookMessageHeader lang=zh-cn dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> ext Luke Palmer
[mailto:lrpalmer@gmail.com] <BR><B>Sent:</B> Tuesday, January 06, 2009 3:44
PM<BR><B>To:</B> Wang, Chunye (NSN - CN/Beijing)<BR><B>Cc:</B>
Haskell-Cafe@haskell.org<BR><B>Subject:</B> Re: [Haskell-cafe] Can I destructive
rebind a local variable in haskell?<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=gmail_quote>2009/1/6 Wang, Chunye (NSN - CN/Beijing) <SPAN
dir=ltr><<A
href="mailto:chunye.wang@nsn.com">chunye.wang@nsn.com</A>><SPAN
class=Apple-style-span style="FONT-FAMILY: 宋体"></SPAN></SPAN></DIV>
<DIV class=gmail_quote><SPAN dir=ltr><SPAN class=Apple-style-span
style="FONT-FAMILY: 宋体">Dear haskeller,</SPAN></SPAN>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV>
<DIV><SPAN><FONT face=宋体 size=2></FONT></SPAN> </DIV>
<DIV><SPAN> <FONT face=宋体 size=2>Can I destructive rebind a
local variable like this</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=宋体 size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=宋体 size=2>import System.Directory<BR>test filename = do
<BR> is_dir <- doesDirectoryExist filename<BR> let filename =
if not is_dir then filename else filename</FONT></SPAN></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Nope. The "filename" on the right side of the = is the same as the
"filename" on the left, so you're making an infinite loop, the same way:</DIV>
<DIV><BR></DIV>
<DIV> let x = x in x </DIV>
<DIV><BR></DIV>
<DIV>is an infinite loop. However you can make a new name as you are
trying, you just can't reference the old one. e.g.:</DIV>
<DIV><BR></DIV>
<DIV> let filename = 42</DIV>
<DIV><BR></DIV>
<DIV>Here would be just fine.</DIV>
<DIV><BR></DIV>
<DIV>However, for cases like this, it is useful that single quote is a valid
identifier, so you can say:</DIV>
<DIV><BR></DIV>
<DIV> let filename' = if not is_dir then filename else filename</DIV>
<DIV><BR></DIV>
<DIV>(read "filename prime")</DIV>
<DIV><BR></DIV>
<DIV>Luke</DIV></DIV></BODY></HTML>