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: mayBe stuck (prad)
2. Re: Parsec (C Gosch)
3. Re: Parsec (C Gosch)
4. Re: Parsec (Daniel Fischer)
5. Trying to statically link Gtk2Hs application (Windows XP,
network drive) (Peter Schmitz)
----------------------------------------------------------------------
Message: 1
Date: Fri, 6 Aug 2010 11:04:25 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: mayBe stuck
To: [email protected]
Message-ID: <20100806110425.32ae3...@gom>
Content-Type: text/plain; charset=US-ASCII
On Fri, 6 Aug 2010 03:43:30 -0400
Dean Herington <[email protected]> wrote:
> I would write something like:
>
> br [] = []
> br ss = let (h, t) = break eqD ss
> in h : case t of
> [] -> []
> _ : t -> br t
>
thx dean. that certainly looks cleaner than mine, but i'm not sure i
have seen this construct before.
i thought let/in was used like this:
aaa = let y = 1+2
z = 4+6
in y+z
which is like
aaa = y + z
where y = 1+2
z = 4+6
in other words, you just define the parts first and use the "in" to
define the main expression.
but here it seems you are defining what appears to be the main item
let (h,t) = break eqD ss
to get the tuple parts and then forming your array (which really is
the main item) using these parts as
h : t
with t being given 2 options.
this is very interesting to me as i had not seen such a construct
before.
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
------------------------------
Message: 2
Date: Fri, 6 Aug 2010 20:47:48 +0200
From: C Gosch <[email protected]>
Subject: Re: [Haskell-beginners] Parsec
To: David Virebayre <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
David,
thank you for your helpful explanations. So I need to define a new datatype
encapsulating the two I want
to parse and then create a new Stream, is that correct?
Reading your comments and more of the haddock documentation of Parsec,
this came to my mind: say I want to skip over some binary parts of the input
(which is a PDF, containing ascii and
deflated parts as well as images). I found the functions
setPosition/getPosition, which seem to
build on the notion of line and column number. Is there a way to say that I
want to skip
N bytes along the stream? I didn't find an obvious one myself when browsing
through the docs.
Thanks again,
Christian
2010/8/6 David Virebayre
<[email protected]<dav.vire%[email protected]>
>
> On Fri, Aug 6, 2010 at 11:03 AM, C Gosch <[email protected]> wrote:
>
> > You're right, I probably used the wrong words .. I meant that apparently
> the
> > tokens Parsec uses are of type Char, and I would actually at some point
> > like to continue parsing, but using different tokens. Sorry if I still
> got
> > it wrong, I'm new :) I can post some code later, as I don't have it here
> > right now.
>
> Parsec (at least version 3) uses any type of token you want.
>
> Quick example off the top of my head, I didn't check if it compiles:
>
> -- you have to make lists of your token type an instance of Stream :
>
> instance Stream [ MyTokenType ] Identity MyTokenType where
> uncons [] = return Nothing
> uncons (x:xs) = return $ Just (x,xs)
>
> -- your parser type is going to look like this :
>
> type MyParser a = ParsecT [MyTokenType] () Identity a
>
> -- assuming your toke type looks like this
>
> Data MyTokenType = A Char
> | B Word8
> deriving (Show)
>
>
> -- you need a basic parser from which you can make more complicated ones
>
> satisChar :: ( Char -> Bool ) -> MyParser Char
> satisChar f = tokenPrim prt pos match
> where
> prt = show
> pos p _l _cs = incSourceLine p 1
> match (A c) = if f c then Just c else Nothing
> match _ = Nothing
>
> satisBin :: ( Word8 -> Bool ) -> MyParser Word8
> satisBin f = tokenPrim prt pos match
> where
> prt = show
> pos p _l _cs = incSourceLine p 1
> match (B w) = if f w then Just w else Nothing
> match _ = Nothing
>
> -- You can define basic parsers like this
>
> -- parse any letter
> letter = satisChar (const True)
>
> -- parse a specific char, it will return
> char c = satisChar (==c)
>
> -- parse any binary word
> binary = satisBin (const True)
>
> -- parse a specific binary
> word w = satisBin (==w)
>
> -- now you can combine this to make more complicated parsers.
>
> ...
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100806/297319a2/attachment-0001.html
------------------------------
Message: 3
Date: Fri, 6 Aug 2010 21:02:48 +0200
From: C Gosch <[email protected]>
Subject: Re: [Haskell-beginners] Parsec
To: Patrick LeBoutillier <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Ah wait ... I saw that I can get the input stream with
getParserState,
as it is part of the state. If that is the currently remaining stream, I
could use any functions from ByteString
to skip over some parts or do whatever with them, and update the state to
the last position after the part I want
to skip.
Am I correct there, or am I then getting something in Parsec out of sync?
Guess I'll just try :)
Thanks!
Christian
2010/8/6 Patrick LeBoutillier <[email protected]>
> Hi,
>
> I started using Data.Binary yesterday for a project and it's nice. I'm
> not sure it's possible, but perhaps you could switch tools along the
> way:
>
> - Parse the ASCII bit with Parsec ;
> - Give the remaining ByteString to Data.Binary for the binary part ;
> - Switch back and forth as required.
>
> Patrick
>
>
> On Fri, Aug 6, 2010 at 5:03 AM, C Gosch <[email protected]> wrote:
> >
> >
> > 2010/8/6 Dean Herington <[email protected]>
> >>
> >> At 11:42 PM +0200 8/5/10, C Gosch wrote:
> >>>
> >>> Hi,
> >>> does anyone here know their way around in Parsec?
> >>> I'm trying to parse a file which contains some binary parts too.
> >>> I have been using Parsec 3.0.1 to parse the first ASCII part, but all
> the
> >>> parsers are
> >>> returning Char type tokens, so it would not work with the binary parts
> ..
> >>> is there any way to do this?
> >>> I am using Text.Parsec.ByteString.Lazy.
> >>>
> >>> Note that I'm new to Haskell and Parsec, and doing this within a small
> >>> project that
> >>> I basically do to get a grip on Haskell (and Parsec, because it appears
> >>> to be really nifty and I want to learn more about it).
> >>>
> >>> Thanks for any hints,
> >>> Christian
> >>
> >> Parsing binary parts of a file is not inherently a problem. A parser
> can
> >> return any type; different parsers in your application will likely
> return
> >> different types.
> >>
> >> If you include some code we'll be able to help you more specifically.
> >>
> >> Dean
> >
> > You're right, I probably used the wrong words .. I meant that apparently
> the
> > tokens Parsec uses are of type Char, and I would actually at some point
> > like to continue parsing, but using different tokens. Sorry if I still
> got
> > it wrong, I'm new :) I can post some code later, as I don't have it here
> > right now.
> >
> > Cheers,
> > Christian
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
>
>
>
> --
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100806/87d71200/attachment-0001.html
------------------------------
Message: 4
Date: Fri, 6 Aug 2010 21:25:16 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Parsec
To: [email protected]
Cc: C Gosch <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Friday 06 August 2010 21:02:48, C Gosch wrote:
> Ah wait ... I saw that I can get the input stream with
> Â Â getParserState,
> as it is part of the state. If that is the currently remaining stream, I
> could use any functions from ByteString
> to skip over some parts or do whatever with them, and update the state
> to the last position after the part I want
> to skip.
> Am I correct there, or am I then getting something in Parsec out of
> sync? Guess I'll just try :)
>
> Thanks!
> Christian
I think using getInput and setInput would be more convenient.
- parse text
- bs <- getInput
- let (binaryResult, remainingInput) = treatBinaryPart bs
- setInput remainingInput
- continue parsing
------------------------------
Message: 5
Date: Fri, 6 Aug 2010 14:36:29 -0700
From: Peter Schmitz <[email protected]>
Subject: [Haskell-beginners] Trying to statically link Gtk2Hs
application (Windows XP, network drive)
To: Haskell Beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I am trying to statically link Gtk2Hs applications.
E.g., the Gtk2Hs demo ...\demo\hello\World.hs from the SourceForge tarball:
http://sourceforge.net/projects/gtk2hs/files/gtk2hs/0.10.1/gtk2hs-0.10.1.tar.gz/download
My failed link attempts are listed at the end of this mail, but first
some notes about my configuration.
I need to develop in a Windows XP environment, where the toolset
(Haskell Platform, Cabal, gtk, Gtk2hs, etc.) is located on a network
drive (H:) instead of C:. (I know this may be unusual, but I need to
be able to use any one of several PCs for development, with one common
tools tree.)
It is okay for temp files to reside on C:, but otherwise I have:
H:\proc\tools\Haskell Platform\2010.1.0.0\
H:\proc\tools\gtk\
H:\proc\tools\cabal\
etc.
(Fyi, I set up Cabal for this environment with some kind help:
http://www.haskell.org/pipermail/haskell-cafe/2010-July/thread.html#80930 ).
The _dynamically_ linked World.exe runs okay:
PATH is:
PATH=
H:\proc\tools\Haskell Platform\2010.1.0.0\bin;
H:\proc\tools\cabal\bin;
H:\proc\tools\gtk\bin;
H:\proc\tools\Haskell Platform\2010.1.0.0\lib\extralibs\bin;
H:\proc\tools\Haskell Platform\2010.1.0.0\mingw\bin
H:\proc\dev\Gtk2Hs\demo\hello>ghc --make World.hs
[1 of 1] Compiling Main ( World.hs, World.o )
Linking World.exe ...
Process completed, Exit Code 0.
I had to add the mingw\bin dir to PATH to get cpp (needed during
"cabal install gtk"), and the extralibs dir to get alex (for "cabal
install gtk2hs-buildtools").
I would like users to be able to run my statically linked apps without
having to worry about .dll issues at runtime, and just by double
clicking on the app in a Windows explorer (file system display)
window.
When I try that for this dynamically linked World.exe, I get the error dialog:
World.exe - Unable To Locate Component
The application has failed to start because libcairo-2.dll was not found.
Reinstalling the application may fix this problem.
I consulted the ghc user guide, and did some Googling.
I am not sure if the static linking difficulty is due to needing to
link with the gtk (non Haskell) code
(i.e., http://www.gtk.org/download-windows.html and
http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.20/gtk+_2.20.0-1_win32.zip
),
as perhaps alluded to in section "3. Static linking vs dynamic linking" in
http://www.cs.virginia.edu/~wh5a/blog/Some%20GHC%20notes%20for%20myself.html
(... The C libraries are not statically linked by default. To produce
a completely static binary ...)
or
if it is just due in some way to my non-standard network drive configuration
(ghc not finding some ".a" files library dirs to complete the static
link, and so it defaults to dynamic linking?).
Fyi, here are some of my dirs that have various *.a files:
H:\proc\tools\cabal\cairo-0.11.0\ghc-6.12.1
H:\proc\tools\cabal\gio-0.11.0\ghc-6.12.1
H:\proc\tools\gtk\lib
H:\proc\tools\Haskell Platform\2010.1.0.0\lib
H:\proc\tools\Haskell Platform\2010.1.0.0\mingw\lib
Other than PATH, I don't have any environment shell variable defined
for searching a library path.
Finally, here are my attempts to statically link:
PATH is:
PATH=H:\proc\tools\Haskell
Platform\2010.1.0.0\bin;H:\proc\tools\cabal\bin;H:\proc\tools\gtk\bin;H:\proc\tools\Haskell
Platform\2010.1.0.0\lib\extralibs\bin;H:\proc\tools\Haskell
Platform\2010.1.0.0\mingw\bin
H:\proc\dev\Gtk2Hs\demo\hello>ghc --make -static -optl-static World.hs
[1 of 1] Compiling Main ( World.hs, World.o )
Linking World.exe ...
H:\proc\tools\Haskell Platform\2010.1.0.0\mingw\bin\ld.exe: cannot find -lz
collect2: ld returned 1 exit status
Process completed, Exit Code 1.
PATH is:
PATH=H:\proc\tools\Haskell
Platform\2010.1.0.0\bin;H:\proc\tools\cabal\bin;H:\proc\tools\gtk\bin;H:\proc\tools\Haskell
Platform\2010.1.0.0\lib\extralibs\bin;H:\proc\tools\Haskell
Platform\2010.1.0.0\mingw\bin
H:\proc\dev\Gtk2Hs\demo\hello>ghc --make -optl-static -optl-pthread World.hs
[1 of 1] Compiling Main ( World.hs, World.o )
Linking World.exe ...
H:\proc\tools\Haskell Platform\2010.1.0.0\mingw\bin\ld.exe: cannot find -lz
collect2: ld returned 1 exit status
realgcc.exe: unrecognized option `-pthread'
Process completed, Exit Code 1.
Any advice, pointers, etc. would be appreciated.
Thanks very much,
-- Peter
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 15
*****************************************