<!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=&#23435;&#20307; color=#0000ff size=2><SPAN 
class=079434607-06012009>Hi Luke</SPAN></FONT></DIV>
<DIV><FONT face=&#23435;&#20307; color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=079434607-06012009><FONT face=&#23435;&#20307; color=#0000ff 
size=2>&nbsp;&nbsp;&nbsp; Thank you ! I got it :)</FONT></SPAN></DIV>
<DIV><SPAN class=079434607-06012009></SPAN>&nbsp;</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 &lt;chunye.wang@nsn.com&gt;</FONT></SPAN> </DIV>
<DIV>&nbsp;</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>&lt;<A 
href="mailto:chunye.wang@nsn.com">chunye.wang@nsn.com</A>&gt;<SPAN 
class=Apple-style-span style="FONT-FAMILY: &#23435;&#20307;"></SPAN></SPAN></DIV>
<DIV class=gmail_quote><SPAN dir=ltr><SPAN class=Apple-style-span 
style="FONT-FAMILY: &#23435;&#20307;">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=&#23435;&#20307; size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN>&nbsp;&nbsp;&nbsp; <FONT face=&#23435;&#20307; size=2>Can I destructive rebind a 
  local variable like this</FONT></SPAN></DIV>
  <DIV><SPAN><FONT face=&#23435;&#20307; size=2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN><FONT face=&#23435;&#20307; size=2>import System.Directory<BR>test filename = do 
  <BR>&nbsp; is_dir &lt;- doesDirectoryExist filename<BR>&nbsp; let filename = 
  if not is_dir then filename else filename</FONT></SPAN></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Nope. &nbsp;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>&nbsp;&nbsp; let x = x in x&nbsp;</DIV>
<DIV><BR></DIV>
<DIV>is an infinite loop. &nbsp;However you can make a new name as you are 
trying, you just can't reference the old one. &nbsp;e.g.:</DIV>
<DIV><BR></DIV>
<DIV>&nbsp;&nbsp; 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>&nbsp;&nbsp;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>