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