[Haskell-beginners] Alfred Programs in Haskell

Kim-Ee Yeoh ky3 at atamo.com
Wed Mar 4 12:10:49 UTC 2015


On Wed, Mar 4, 2015 at 12:38 PM, Richard Guay <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150304/5d3b6fec/attachment.html>


More information about the Beginners mailing list