Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1.  installing ghc in home directory (Alexander Katovsky)
   2. Re:  GHC-generated executables size (Gaius Hammond)
   3.  Defining custom parser using Parsec (Jimmy Wylie)
   4. Re:  Defining custom parser using Parsec (Magnus Therning)
   5.  Instance but no instance (Jeroen van Maanen)
   6. Re:  Defining custom parser using Parsec (Stephen Tetley)
   7.  Gtk2Hs in Windows (next question :) ) (C Gosch)
   8. Re:  Instance but no instance (Brent Yorgey)


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

Message: 1
Date: Sun, 17 Oct 2010 18:34:42 +0100
From: Alexander Katovsky <a.p.katov...@googlemail.com>
Subject: [Haskell-beginners] installing ghc in home directory
To: beginners@haskell.org
Message-ID:
        <aanlkti=3-+f5stfbegufg43yufqirxclnmk-xr8wd...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello,

I want to install GHC in my home directory on Ubuntu.  But when I get to
configuring the haskell platform, I need to tell GHC about the non-standard
location of the GMP library.  GHC does not appear to pass LDPATH or
LD_LIBRARY_PATH or LDFLAGS to ld.  Making an alias 'ghc=ghc -L$HOME/lib'
will not work here.  Any suggestions?

Thanks,
Alex.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20101017/20532890/attachment-0001.html

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

Message: 2
Date: Sun, 17 Oct 2010 20:14:40 +0100
From: Gaius Hammond <ga...@gaius.org.uk>
Subject: Re: [Haskell-beginners] GHC-generated executables size
To: Christian Gosch <christ...@goschs.de>
Cc: beginners@haskell.org
Message-ID: <46a9cbdb-9c3c-4058-9702-af84ed4cb...@gaius.org.uk>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes


On 15 Oct 2010, at 21:37, Christian Gosch wrote:

> Hi,
> I was playing around with ghc again, and I was wondering what makes
> the executables so large and how I could make them smaller (strip  
> works,
> but is there anything more I can do?)
> More specifically, I am compiling a program that uses the GTK+  
> bindings,
> HDBC, and some things from Prelude.
> The program simply displays a window, and reads and writes values
> from/into a data base file. Not much, really.
> Anyway, the program size is 20MB without stripping, and 10MB after
> stripping ...



A Haskell program needs to schlep around a runtime with it. So when  
you compare it to say a Java program, you need to compare it to the  
size of  a  JAR + the size of the VM, and in that case the size isn't  
so extraordinary. So that is the "why", as to the "what can you do"  
probably not much that you've not already tried, other than supplying  
your program as a script for #!/usr/bin/runghc



http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/runghc.html



That would mean your program wasn't so self-contained, as the target  
machine would also need to have all the "stuff" that you have compiled  
in, e.g. the HDBC development package.



Cheers,




G





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

Message: 3
Date: Sun, 17 Oct 2010 16:59:22 -0500
From: Jimmy Wylie <jwy...@uno.edu>
Subject: [Haskell-beginners] Defining custom parser using Parsec
To: "beginners@haskell.org" <beginners@haskell.org>
Message-ID: <4cbb71ba.3030...@uno.edu>
Content-Type: text/plain; charset="ISO-8859-1"; format=flowed

  Hi everyone,

I'm working on a digital forensics application that will take a file 
with lines of the following format:

"MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime"

This string represents the metadata associated with a particular file in 
the filesystem.

I created a data type to represent the information that I will need to 
perform my analysis:

data Event = Event {
      fn          :: B.ByteString,
      mftNum :: B.ByteString,
      ft           :: B.ByteString,
      fs           :: Integer,
      time       :: Integer,
      at           :: AccessType
      mt          :: AccessType
      ct           ::  AccessType
      crt          :: AccessType
      } deriving (Show)

data AccessType = ATime | MTime | CTime | CrTime
                   deriving (Show)

I would like to create a function that takes the Bytestring representing 
the file and returns a list of Events:
createEvents :: ByteString -> [Event]
(For now I'm creating a list, but depending on the type of analysis I 
decide to do, I may change this data structure)

I understand that I can use the Parsec Library to do this.  I read RWH, 
and noticed they have the endBy and sepBy combinators, but my issue with 
these is that using these funcitons performs too many transformations on 
the data.
endBy will return a list of strings, which then will be used by sepBy 
which will then return a [[ByteString]] which I will then have to 
iterate through to create the final [Event].

What I would like to do is define a custom parser, that will go from the 
ByteString to the [Event] without the overhead of those intermediate 
steps. This function needs to be as fast as possible, as these files can 
be rather large, and I will be performing many different tests and 
analysis on the data.  I don't want the parsing to be a bottleneck.

I'm under the impression that the Parsec library will allow me to define 
a custom parser to do this, but I'm having problems understanding the 
library, and the documentation for it.

A gentle shove in the right direction would be greatly appreciated.

Thanks for your help,
Jimmy






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

Message: 4
Date: Mon, 18 Oct 2010 07:56:33 +0100
From: Magnus Therning <mag...@therning.org>
Subject: Re: [Haskell-beginners] Defining custom parser using Parsec
To: Jimmy Wylie <jwy...@uno.edu>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID:
        <aanlktik0fxr2ho6hlrthxhwn=2zver4l31ghp3zta...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Sun, Oct 17, 2010 at 22:59, Jimmy Wylie <jwy...@uno.edu> wrote:
>  Hi everyone,
>
> I'm working on a digital forensics application that will take a file with
> lines of the following format:
>
> "MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime"
>
> This string represents the metadata associated with a particular file in the
> filesystem.
>
> I created a data type to represent the information that I will need to
> perform my analysis:
>
> data Event = Event {
>     fn          :: B.ByteString,
>     mftNum :: B.ByteString,
>     ft           :: B.ByteString,
>     fs           :: Integer,
>     time       :: Integer,
>     at           :: AccessType
>     mt          :: AccessType
>     ct           ::  AccessType
>     crt          :: AccessType
>     } deriving (Show)
>
> data AccessType = ATime | MTime | CTime | CrTime
>                  deriving (Show)
>
> I would like to create a function that takes the Bytestring representing the
> file and returns a list of Events:
> createEvents :: ByteString -> [Event]
> (For now I'm creating a list, but depending on the type of analysis I decide
> to do, I may change this data structure)
>
> I understand that I can use the Parsec Library to do this.  I read RWH, and
> noticed they have the endBy and sepBy combinators, but my issue with these
> is that using these funcitons performs too many transformations on the data.
> endBy will return a list of strings, which then will be used by sepBy which
> will then return a [[ByteString]] which I will then have to iterate through
> to create the final [Event].
>
> What I would like to do is define a custom parser, that will go from the
> ByteString to the [Event] without the overhead of those intermediate steps.
> This function needs to be as fast as possible, as these files can be rather
> large, and I will be performing many different tests and analysis on the
> data.  I don't want the parsing to be a bottleneck.

This sounds awfully lot like a premature optimisation, which as we all
know, is the root of evil :-)

Why do you think that using Parsec will result in fewer
transformations?  (It will most likely result in fewer transformations
*that you see*, but that doesn't mean much.)

> I'm under the impression that the Parsec library will allow me to define a
> custom parser to do this, but I'm having problems understanding the library,
> and the documentation for it.
>
> A gentle shove in the right direction would be greatly appreciated.

AFAIK Parsec deals with String, not ByteString, have a look at the
attoparsec library[1] instead.

There are numerous explanations of using parser combinators out there.
 Personally I've found the Parsec documentation fairly easy to
understand.  A while ago I wrote a few posts myself on it, and I think
they should translate well to attoparsec (you will probably have to
keep the haddock doc at hand though):

http://therning.org/magnus/archives/289
http://therning.org/magnus/archives/290
http://therning.org/magnus/archives/295
http://therning.org/magnus/archives/296

/M

[1]: http://hackage.haskell.org/package/attoparsec-0.8.1.1

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


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

Message: 5
Date: Mon, 18 Oct 2010 09:31:31 +0200
From: Jeroen van Maanen <jer...@lexau.org>
Subject: [Haskell-beginners] Instance but no instance
To: beginners@haskell.org
Message-ID: <4cbbf7d3.4000...@lexau.org>
Content-Type: text/plain; charset=ISO-8859-1

I am trying to upgrade some update facility in my program to allow for IO:

  class Updater modelType updateType where
    update :: updateType -> modelType -> Maybe modelType

  class UpdaterIO modelType updateType where
    updateIO :: updateType -> modelType -> IO (Maybe modelType)

  pureUpdateToIO :: (updateType -> modelType -> (Maybe modelType)) -> 
updateType -> modelType -> IO (Maybe modelType)
  pureUpdateToIO updateFunction update model = return $ updateFunction update 
model

  instance (Updater modelType updateType) => UpdaterIO modelType updateType 
where
    updateIO = pureUpdateToIO update

My code still works for all my old Updater instances even when I use them in 
the IO monad:

  do maybeUpdatedModel <- updateIO newUpdate oldModel

So far so good. However, when I try to upgrade one of the Updater instances to 
an UpdateIO instance I get into a kind of a catch 22 situation where not only

  maybeUpdatedModel = update newUpdate oldModel

results in a "No instance for Updater [...] [...]" compiler error as expected, 
but also

  do maybeUpdatedModel <- updateIO newUpdate oldModel

unexpectedly results in an "Overlapping instances for UpdaterIO [...] [...]" 
compiler error. Where one of the overlapping instance declarations is:

  instance (Updater modelType updateType) => UpdaterIO modelType updateType

How is that possible?

Cheers,  Jeroen


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

Message: 6
Date: Mon, 18 Oct 2010 08:37:42 +0100
From: Stephen Tetley <stephen.tet...@gmail.com>
Subject: Re: [Haskell-beginners] Defining custom parser using Parsec
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID:
        <aanlkti=zomghniafbtpbiyif-4myusyqw5i=effoi...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On 18 October 2010 07:56, Magnus Therning <mag...@therning.org> wrote:

>
> AFAIK Parsec deals with String, not ByteString, have a look at the
> attoparsec library[1] instead.
>

Parsec 3.0 deals with ByteStrings, Parsec 3.1 and higher improve the
performance quite about.

>From the original post, the syntax of what is to be parsed looks
simple (essentially a single data type, no alternatives except the
AccessType tag), so it can probably easily get by without combinators
like sepBy and endBy. It would need a sample of the input data or a
grammar for it to affirm this, though. A working (simple) parser in
Parsec should be easy to convert to Attoparsec etc if it doesn't use
combinators like sepBy.


parseEvents :: Parser [Event]
parseEvents = many event

event :: Parser Event
event = do
    fn_ <- parseFn
    mft_num <- parseMftNum
    ft_     <- parseFt
    fs_     <- integer
    time_   <- integer
    at_     <- parseAccessType
    mt_     <- parseAccessType
    ct_     <- parseAccessType
    crt_    <- parseAccessType
    return $ Event
      { fn       = fn_
      , mftNum   = mft_num
      , ft       = ft_
      , fs       = fs_
      , time     = time_
      , at       = at_
      , mt       = mt_
      , ct       = ct_
      , crt      = crt_
      }

More parsers will need to be defined for parseMftNum etc. The
applicative style as used in RWH can get rid of the interim variables
which makes it much nicer for parsing than the monadic style. Parsec
3.0 and later can use the Applicative style. How the input data
separates fields will need taking care of.


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

Message: 7
Date: Mon, 18 Oct 2010 13:26:19 +0200
From: C Gosch <ch.go...@googlemail.com>
Subject: [Haskell-beginners] Gtk2Hs in Windows (next question :) )
To: beginners@haskell.org
Message-ID:
        <aanlktimjqcavnzjusy4pmknldob51khbess_flv7-...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello,
this is a question only for the gtk2hs users on this list.
It might be the wrong list, and I could probably figure it out myself given
enough time, but I am asking anyway
just in case someone has solved the problem already:

I am trying to install gtk2hs in Windows 7 with
 cabal install gtk
on the command line (cmd.exe).
I managed to make the gtk libraries available, but the build process ends
with this error message:
 setup.exe: gtk-0.11.2: library-dirs: c:/devel/dist/win32/libpng-1.4.3-1/lib
 doesn't exist or isn't a directory (use --force to override)
 cabal.exe: Error: some packages failed to install:
 gtk-0.11.2 failed during the building phase. The exception was: ExitFailure
1

The directory c:/devel/dist/win32/libpng-1.4.3-1/lib does in fact not exist,
and I am wondering why
it is considered at all .. I think a libpng came together with the gtk
package.
I have tried to use --extra-lib-dirs, but that leads to the same error
message.

Any ideas?

Thanks and my apologies if this is too gtk-/windows-specific for this list.
Christian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20101018/1c61b66b/attachment-0001.html

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

Message: 8
Date: Mon, 18 Oct 2010 07:44:30 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Instance but no instance
To: beginners@haskell.org
Message-ID: <20101018114430.ga14...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Mon, Oct 18, 2010 at 09:31:31AM +0200, Jeroen van Maanen wrote:
> 
> unexpectedly results in an "Overlapping instances for UpdaterIO [...] [...]" 
> compiler error. Where one of the overlapping instance declarations is:
> 
>   instance (Updater modelType updateType) => UpdaterIO modelType updateType

When doing instance selection, GHC only looks at the part to the right
of the =>.  So, the instance above essentially means "every pair of
types are an instance of UpdaterIO, and, oh yes, they had better be an
instance of Updater as well".  So the above instance overlaps with
*every* other instance of UpdaterIO.

There are a few solutions I can think of.  One is to decide you are OK
with the overlapping instances (in this case I think it ought to work
correctly).  Or you can bite the bullet and make a separate instance
of UpdaterIO for all the old instances of Updater.

-Brent


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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 28, Issue 28
*****************************************

Reply via email to