Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  doesFileExist cannot get ~/blah_blah right (Brent Yorgey)
   2. Re:  Problems with parsing in attoparsec (mukesh tiwari)
   3.  </>? Was: doesFileExist cannot get ~/blah_blah   right
      (Tommy M. McGuire)
   4. Re:  </>? Was: doesFileExist cannot get ~/blah_blah right
      (David McBride)


----------------------------------------------------------------------

Message: 1
Date: Tue, 9 Apr 2013 08:07:39 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] doesFileExist cannot get ~/blah_blah
        right
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On Mon, Apr 08, 2013 at 04:04:22PM -0700, Erlend Hamberg wrote:
> On 8 April 2013 15:45, Hong Yang <[email protected]> wrote:
> 
> > I got "not exists ..." from
> >
> >     fileExists <- doesFileExist "~/blah_blah"
> >     if fileExists then print "exists ..."
> >                      else print "not exists ..."
> >
> > using the directory-1.1.0.2 package, when ~/blah_blah does exist.
> >
> 
> When you type ?~/blah_blah? in your shell, the *shell* will expand ?~? to
> your home directory, so when you pass ?~/foo? to a program, that program
> never sees ?~/foo?, but ?/home/user/foo?. In other words, ?~/blah_blah?
> probably does *not* exist.
> 
> What you probably should do is to find the user's home directory and
> prepend that to ?blah_blah?. You can find a user's homedir by calling
> `getHomeDirectory` from `System.Directory`:
> 
>     Prelude System.Directory> homedir <- getHomeDirectory
>     Prelude System.Directory> putStrLn $ homedir ++ "/blah_blah"
>     /Users/ehamberg/blah_blah

Also, since we are discussing portability, it's a much better idea to do

  homedir </> "blah_blah"

instead of homedir ++ "/blah_blah", since the former will use the
correct path separator character for whatever system it is compiled
on.

-Brent



------------------------------

Message: 2
Date: Tue, 9 Apr 2013 19:32:11 +0530
From: mukesh tiwari <[email protected]>
Subject: Re: [Haskell-beginners] Problems with parsing in attoparsec
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAFHZvE9QTOv2eWC92kJXxLFzvJRUJVpyyawAYT1K=4ckeyu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Michel
I think you are reading empty string inside index function. I figured out
little bit and some where you are reading empty string but could not
concentrate enough ( or expert enough :) ) to see more because you are
parsing you code based on counting the number of characters ( take 6 inside
index function ).

*Main> read ""::Int
*** Exception: Prelude.read: no parse

Except the first test case, I changed the space between 0 and 2 ( for last
test case, I reduced the space between 0 and 4 )  to seven and now it's not
parsing completely but there is no error.

I have posted the code on ideone[1]. Here is the output on my system. I
have also attached the code.

*Main> :load "/Users/mukeshtiwari/Programming/Haskell/ParsingAtto.hs"
[1 of 1] Compiling Main             (
/Users/mukeshtiwari/Programming/Haskell/ParsingAtto.hs, interpreted )
Ok, modules loaded: Main.
*Main> test1
Done "\n" [(1,IndexedFaceTriangle 10 1 9),(2,IndexedFaceTriangle 1 2 9)]
*Main> test2
Done "  12     8     1     0\n" [[(1,IndexedFaceTriangle 10 1
9),(2,IndexedFaceTriangle 1 2 9),(11,IndexedFaceQuad 9 2 0 4)]]
*Main> test3
Done "  12     8     1     0\n" [[(1,IndexedFaceTriangle 10 1
9),(2,IndexedFaceTriangle 1 2 9),(11,IndexedFaceQuad 9 2 0 4)]]
*Main> test4
Done "  12     8     1     0\n" [[(1,IndexedFaceTriangle 10 1
9),(2,IndexedFaceTriangle 1 2 9),(11,IndexedFaceQuad 9 2 0 4)]]
*Main> test5
Done "   12     8     1     0\n" [[(1,IndexedFaceTriangle 10 1
9),(2,IndexedFaceTriangle 1 2 9),(11,IndexedFaceQuad 9 2 0 4)]]

[1] http://ideone.com/x75C3j

Mukesh Tiwari


On Tue, Apr 9, 2013 at 11:30 AM, Michel Kuhlmann <[email protected]>wrote:

> Hi,
> I couldn't figure out, why I'm failing with attoparsec.
> I have the follwing code (https://github.com/michelk/devsurf/tree/readNet)
>
>     import           Data.Attoparsec.Text
>     import qualified Data.Text as T
>     import           Language.DevSurf.Readers.SpringNet
>     import Prelude hiding (takeWhile, take)
>
>     data IndexedFace
>         = IndexedFaceTriangle Int Int Int
>         | IndexedFaceQuad     Int Int Int Int
>         deriving (Show)
>
>     -- | block of faces-lines
>     faces :: Parser [[(Int, IndexedFace)]]
>     faces = faceLine `sepBy` endOfLine
>
>     -- | Line containing up to two indexed faces
>     faceLine :: Parser [(Int, IndexedFace)]
>     faceLine = face `sepBy` (take 6)
>
>     -- | single indexed-face
>     face :: Parser (Int, IndexedFace)
>     face = do
>       i  <- index
>       v1 <- index
>       v2 <- index
>       v3 <- index
>       v4 <- index
>       case v4 of
>         0  -> return (i, IndexedFaceTriangle v1 v2 v3)
>         _  -> return (i, IndexedFaceQuad     v1 v2 v3 v4)
>
>     -- | node or face index 6 wide
>     index :: Parser Int
>     index = do
>       i <- take 6
>       return . read . T.unpack $ i
>
> When testing, the follwing is working:
>
>     testEleL2 = do
>       let ele = T.pack    "     1    10     1     9     0           2
> 1     2     9     0\n"
>           r    =  parse faceLine ele
>       case r of
>            Partial _ -> print $ feed r (T.pack "")
>            _         -> print r
>
>     testEles = do
>       let eles = T.pack $ concat ["     1    10     1     9     0
>   2     1     2     9     0\n"
>                                  --,"     3    11     9     2     0\n"
>                                  ,"     4    12     8     1     0\n"
>                                  ]
>           r    =  parse faces eles
>       case r of
>            Partial _ -> print $ feed r (T.pack "")
>            _         -> print r
>
>     testEles = do
>       let eles = T.pack $ concat ["     1    10     1     9     0
>   2     1     2     9     0\n"
>                                  ,"     3    11     9     2     0\n"
>                                  --,"     4    12     8     1     0\n"
>                                  ]
>           r    =  parse faces eles
>       case r of
>            Partial _ -> print $ feed r (T.pack "")
>            _         -> print r
>
> But this is not working
>
>     testEles = do
>       let eles = T.pack $ concat ["     1    10     1     9     0
>   2     1     2     9     0\n"
>                                  ,"     3    11     9     2     0\n"
>                                  ,"     4    12     8     1     0\n"
>                                  ]
>           r    =  parse faces eles
>       case r of
>            Partial _ -> print $ feed r (T.pack "")
>            _         -> print r
>
>
>     testEles = do
>       let eles = T.pack $ concat ["     1    10     1     9     0
>   2     1     2     9     0\n"
>                                  ,"     3    11     9     2     0
>   4    12     8     1     0\n"
>                                  ]
>           r    =  parse faces eles
>       case r of
>            Partial _ -> print $ feed r (T.pack "")
>            _         -> print r
>
> Please help.
> Thanks, Michel
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130409/90cdef56/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ParsingAtto.hs
Type: application/octet-stream
Size: 2773 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130409/90cdef56/attachment-0001.obj>

------------------------------

Message: 3
Date: Tue, 09 Apr 2013 11:15:01 -0500
From: "Tommy M. McGuire" <[email protected]>
Subject: [Haskell-beginners] </>? Was: doesFileExist cannot get
        ~/blah_blah     right
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On 04/09/2013 07:07 AM, Brent Yorgey wrote:
> Also, since we are discussing portability, it's a much better idea to do
> 
>   homedir </> "blah_blah"
> 
> instead of homedir ++ "/blah_blah", since the former will use the
> correct path separator character for whatever system it is compiled
> on.

Wait, what? Where'd "</>" come from?


-- 
Tommy M. McGuire
[email protected]



------------------------------

Message: 4
Date: Tue, 9 Apr 2013 12:25:10 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] </>? Was: doesFileExist cannot get
        ~/blah_blah right
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAN+Tr40gyBidS=TAxxNc8EyeSqVsV_hrKt1g=q30fotm7rf...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

There is a package system-filepath
http://hackage.haskell.org/package/system-filepath which fixes a lot of
quibbles people have with the way filepaths are implemented in haskell.
There are apparently a lot of problems with using strings as filepaths,
like the fact that they are slow, that they have encoding issues, and that
people cannot make a path that is system agnostic.

So the </> operator in that library just joins two filepaths together with
the correct slash.


On Tue, Apr 9, 2013 at 12:15 PM, Tommy M. McGuire <[email protected]> wrote:

> On 04/09/2013 07:07 AM, Brent Yorgey wrote:
> > Also, since we are discussing portability, it's a much better idea to do
> >
> >   homedir </> "blah_blah"
> >
> > instead of homedir ++ "/blah_blah", since the former will use the
> > correct path separator character for whatever system it is compiled
> > on.
>
> Wait, what? Where'd "</>" come from?
>
>
> --
> Tommy M. McGuire
> [email protected]
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130409/072c350a/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 58, Issue 19
*****************************************

Reply via email to