[Haskell-beginners] Alfred Programs in Haskell

Richard Guay raguay at customct.com
Wed Mar 4 14:01:36 UTC 2015


It's not a file permission problem because it works great when the file 
exists. But, when the file doesn't exist, it still tries to read the 
file. It acts like the file is there when it isn't. In ghci, it returns 
the true boolean when the file is there and a false when it isn't. But, 
in the program, it is always executing the readFile.

Kim-Ee Yeoh wrote:
>
>
> On Wed, Mar 4, 2015 at 12:38 PM, Richard Guay <raguay at customct.com
> <mailto:raguay at customct.com>> wrote:
>
> fExist <- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++
> "/" ++ fileName
> if fExist
> then do
> contents <- readFile $ h ++ cacheDirBasic ++ getBundleID
> ++ "/" ++ fileName
>
>
> First of all, let's refactor that into a let binding, e.g.
>
> let pathName = h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName
> fExist <- doesFileExist pathName
> if fExist then readFile pathName else return ""
>
> The advantage of keeping DRY here should be obvious. Defining the same
> thing in 2 places can lead to both getting out of lockstep.
>
> Now as for debugging the actual problem, have you tried the REPL? That
> is, launch ghci, load the appropriate libraries, and see what happens
> when you enter
>
> doesFileExist "/home/me/myfile"
>
> and similarly for readFile. That way you'd rule things out like a file
> permissions problem, etc.
>
>
> -- Kim-Ee
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150304/66c9b2cf/attachment.html>


More information about the Beginners mailing list