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.  Meaning of the ! operator (Nathan Huesken)
   2. Re:  Meaning of the ! operator (Daniel Fischer)
   3.  Re: problem with System.Directory.Tree (Anand Mitra)
   4. Re:  Re: problem with System.Directory.Tree (Stephen Tetley)


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

Message: 1
Date: Sun, 13 Jun 2010 16:12:22 -0400
From: Nathan Huesken <hask...@lonely-star.org>
Subject: [Haskell-beginners] Meaning of the ! operator
To: Biginners Haskell Mailinglist <beginners@haskell.org>
Message-ID: <20100613161222.6aa14...@samzwo>
Content-Type: text/plain; charset=US-ASCII

Hi,

I have often seen in haskell code a "!" in front of variables.
In example:

data BrickState = Live | Dying !GLfloat deriving (Eq,Show)

I never read the meaning of the "!", what does it do?

Thanks!
Nathan


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

Message: 2
Date: Sun, 13 Jun 2010 22:37:47 +0200
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] Meaning of the ! operator
To: beginners@haskell.org
Message-ID: <201006132237.48153.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-1"

On Sunday 13 June 2010 22:12:22, Nathan Huesken wrote:
> Hi,
>
> I have often seen in haskell code a "!" in front of variables.
> In example:
>
> data BrickState = Live | Dying !GLfloat deriving (Eq,Show)
>
> I never read the meaning of the "!", what does it do?

'!' is a strictness annotation.

In this case, it means that the field is strict, that is, it can't contain 
an unevaluated thunk (because GLfloat is a type that is either fully 
evaluated or not at all).
When you call (Dying something), the something is 'seq'ed, in particular
Dying undefined === undefined, while without the '!', Dying undefined would 
be a non-bottom value.

You'll also see '!' in pattern matches, 

fun !x = whatever

there it also means that the argument x must be evaluated (to weak head 
normal form), so if

foo !x = 1

and

bar x = 1

, we have bar undefined = 1, but foo undefined = Prelude.error undefined

However, foo [undefined] = 1.

>
> Thanks!
> Nathan



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

Message: 3
Date: Mon, 14 Jun 2010 07:42:01 +0530
From: Anand Mitra <mi...@kqinfotech.com>
Subject: [Haskell-beginners] Re: problem with System.Directory.Tree
To: beginners@haskell.org
Message-ID:
        <aanlktim3ucdxuxzn02jh8ei39saemetszjoceriqb...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Again,

Thanks to the help from this group I have got past my first problem and now
stuck on another. I have succeeded in building a DirTree using library
"System.Directory.Tree" with properties of md5sum and modification time. I
have also built  the parts that can compare two such trees and find the
files that have changed.

I was trying to serializing the tree so that it can be saved for later
identification of changed files. The module "Tree" incidentally derives Show
but not Read and hence I cannot read the file serialized file. Searching a
bit I decided to use the infrastructure in "Data.Binary" to do the job for
me.

As soon as I started this I realized that I would have to modify Tree.hs
module. This was required because DirTree does not derive from Typeable and
Data which is required for it to be serialized via "Data.Binary". After
patching the Binary module to derive from Typeable and Data I get the
following error.


System/Directory/Tree.hs:95:47:
    No instance for (Data Exception)
      arising from the 'deriving' clause of a data type declaration
                   at System/Directory/Tree.hs:95:47-50
    Possible fix:
      add an instance declaration for (Data Exception)
      or use a standalone 'deriving instance' declaration instead,
         so you can specify the instance context yourself
    When deriving the instance for (Data (DirTree a))
Failed, modules loaded: BinaryDerive.

Secondly I suspect that I could have derived it without having to modify the
original module source. The compilation error does give a hint about
"standalone deriving instance" but trying stuff at
http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/deriving.html did
not help me much.

In short what is the simplest way I can serialize "System.Directory.Tree"
using Binary. Is there a better alternative to Binary for serialization ?
Are there solutions to the problem I have outlined above ? or is my approach
incorrect. Is it possible to add the deriving of datatype DirTree without
modifying the module ?

regards
-- 
Anand Mitra


On Mon, Jun 7, 2010 at 5:36 PM, Anand Mitra <anand.mi...@gmail.com> wrote:

> Hello All,
>
> I want to build a program which will recursively scan a directory and
> build md5sum for all the files. The intent is to do something similar
> to unison but more specific to my requirements. I am having trouble in
> the initial part of building the md5sums.
>
> I did some digging around and found that "System.Directory.Tree" is a
> very close match for what I want to do. In fact after a little poking
> around I could do exactly what I wanted.
>
> ,----
> | import Monad
> | import System.Directory.Tree
> | import System.Directory
> | import Data.Digest.Pure.MD5
> | import qualified Data.ByteString.Lazy.Char8 as L
> |
> | calcMD5 =
> |     readDirectoryWith (\x-> liftM md5 (L.readFile x))
> `----
>
> This work perfectly for small directories. readDirectoryWith is
> already defined in the library and exactly what we want
>
> ,----
> | *Main> calcMD5 "/home/mitra/Desktop/"
> |
> | "/home/mitra" :/ Dir {name = "Desktop", contents = [File {name =
> | "060_LocalMirror_Workflow.t.10.2.62.9.log", file =
> | f687ad04bc64674134e55c9d2a06902a},File {name = "cmd_run", file =
> | 6f334f302b5c0d2028adeff81bf2a0d9},File {name = "cmd_run~",
> `----
>
> However when ever I give it something more challenging it gets into
> trouble.
>
> ,----
> | *Main> calcMD5 "/home/mitra/laptop/"
> | *** Exception: /home/mitra/laptop/ell/calc-2.02f/calc.info-27:
> |    openFile: resource exhausted (Too many open files)
> | *Main> 29~
> `----
>
> If I understand what is happening it seems to be doing all the opens
> before consuming them via md5. This works fine for small directories
> but for any practical setup this could potentially be very large. I
> tried forcing the md5 evaluation in the hope that the file descriptor
> will be freed once the entire file is read. That did not help, either
> because I could not get it right or there is some more subtle I am
> missing.
>
> I also had a look at the code in module "System.Directory.Tree" and
> although it gave me some understanding of how it works I am no closer
> to a solution.
>
> regards
> --
> Anand Mitra
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100613/240fc6e7/attachment-0001.html

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

Message: 4
Date: Mon, 14 Jun 2010 08:56:35 +0100
From: Stephen Tetley <stephen.tet...@gmail.com>
Subject: Re: [Haskell-beginners] Re: problem with
        System.Directory.Tree
To: Anand Mitra <mi...@kqinfotech.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktincl_k4uf7ht4qcs_dbdjditncfseb-venw2...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hello Anand

System.Directory.Tree is not a good candidate for serializing directly
- as you have found out, one of the constructors - Failed - carries an
IOException which cannot be serialized (IOExceptions may contain file
handles which are inherently runtime values).

Data.Binary is usually the best option for serialization. In your
case, you wont be able to make a 1-1 mapping between a runtime DirTree
and its on disk representation as you'll have to work out what to do
about 'Failed' - maybe you would want to only serialize the good
constructors - Dir and File - instead.

As you will have to coerce the data type a bit, I'd recommend using
Data.Binary to write the serialization, but rather than make instances
of Put and Get for DirTree instead give the serialize and deserialize
functions characteristic names e.g.
 serializeGoodTree / deserializeGoodTree.

Best wishes

Stephen


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

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


End of Beginners Digest, Vol 24, Issue 13
*****************************************

Reply via email to