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:  discover data constructor without pattern    matching?
      (Philippe Sismondi)
   2.  emacs setup for haskell (Rustom Mody)
   3. Re:  discover data constructor without pattern    matching?
      (Andres L?h)
   4. Re:  emacs setup for haskell (Adrien Haxaire)
   5. Re:  Parallelism? (Simon Marlow)
   6. Re:  emacs setup for haskell (Rustom Mody)
   7. Re:  Diagnosing : Large memory usage + low CPU (Hugo Ferreira)


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

Message: 1
Date: Thu, 1 Dec 2011 20:32:56 -0500
From: Philippe Sismondi <[email protected]>
Subject: Re: [Haskell-beginners] discover data constructor without
        pattern matching?
To: Beginners Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"


On 2011-12-01, at 5:47 PM, Ozgur Akgun wrote:

> Hi,
> 
> On 1 December 2011 22:38, Philippe Sismondi <[email protected]> wrote:
> Is it possible to discover the data constructor used to make a value without 
> doing pattern matching?
> 
> Yes, it is.
> 
> constrName :: Data a => a -> String
> constrName = show . toConstr
> 
> http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Data.html#v:toConstr
> 
> (You can derive Data for your data type using the language extension 
> DeriveDataTypeable)
> 
> Hope this helps,

Wow, it sure does. Thanks a million.


> Ozgur
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111201/acb7c210/attachment-0001.htm>

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

Message: 2
Date: Fri, 2 Dec 2011 10:53:55 +0530
From: Rustom Mody <[email protected]>
Subject: [Haskell-beginners] emacs setup for haskell
To: Beginners Haskell <[email protected]>
Message-ID:
        <CAG3g5n=U15WoA0mKqKqv6LmupN_yOVH8YfcuT-jE9=dnlz-...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I am using haskell inside emacs with the usual setup ie .hs file in one
window, ghci in another.

Now the most usual workflow one would do is to load the file into ghci (C-c
C-l) and try out something in ghci.
A small niggle is that after the C-c C-l Ive to manually switch to the
other window (current window does not switch to ghci automatically)
This seems to be a strange default

More importantly the state of the workspace in ghci seems to get messed up
unless I do:
0. Prepare some code in .hs
2. Switch to ghci
3. Clear the ghci workspace with :m <nothing>
4. switch back to .hs
5. C-c C-l
6. Switch to ghci to try out new code

Is there something I am missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111202/b9f625c7/attachment-0001.htm>

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

Message: 3
Date: Fri, 2 Dec 2011 09:16:05 +0100
From: Andres L?h <[email protected]>
Subject: Re: [Haskell-beginners] discover data constructor without
        pattern matching?
To: Philippe Sismondi <[email protected]>
Cc: Beginners Haskell <[email protected]>
Message-ID:
        <caljd_v6gjevc9wg-sbuam_c3fvr2fghsmrao-_sfhgoq8y2...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi.

> Is it possible to discover the data constructor used to make a value without 
> doing pattern matching?

You've already got an answer, but ...

> In my current small project I have a data type with a zillion constructors. 
> These use record syntax so that I can access the payload without pattern 
> matching. But I just discovered that it I want to print out the constructor 
> name in my error handling function. Can I do this without, say, hacking 
> around with a string from 'show'?

... to me, it sounds as if instead of:

        data X = A { x :: Int } | B { x :: Int } | C { x :: Int }

you might want:

        data X = MkX { x :: Int, sort :: Sort }
        data Sort = A | B | C deriving Show

Then you can trivially show the constructor, because it's just a value.

Cheers,
  Andres



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

Message: 4
Date: Fri, 02 Dec 2011 09:33:20 +0100
From: Adrien Haxaire <[email protected]>
Subject: Re: [Haskell-beginners] emacs setup for haskell
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

 On Fri, 2 Dec 2011 10:53:55 +0530, Rustom Mody wrote:
> I am using haskell inside emacs with the usual setup ie .hs file in
> one window, ghci in another.
>
> Now the most usual workflow one would do is to load the file into 
> ghci
> (C-c C-l) and try out something in ghci.
> A small niggle is that after the C-c C-l Ive to manually switch to 
> the
> other window (current window does not switch to ghci automatically)
>  This seems to be a strange default

 Actually I prefer it this way because I can check often if my types are 
 OK, or that I don't have a typo.
 You can also rebind C-c C-l to execute C-x o after it.

>
> More importantly the state of the workspace in ghci seems to get
> messed up unless I do:
> 0. Prepare some code in .hs
> 2. Switch to ghci
> 3. Clear the ghci workspace with :m
>  4. switch back to .hs
> 5. C-c C-l
> 6. Switch to ghci to try out new code
>
> Is there something I am missing?

 When I do C-c C-l it recompiles and/or reloads all my modules and wipes 
 all the variables I had defined before, so I think steps 0 to 4 are not 
 needed.

 Adrien

 PS: I assumed that you were using haskell-mode



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

Message: 5
Date: Fri, 02 Dec 2011 10:05:51 +0000
From: Simon Marlow <[email protected]>
Subject: Re: [Haskell-beginners] Parallelism?
To: Michael Craig <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 02/12/2011 00:08, Michael Craig wrote:
> Thanks, I'll keep that in mind.
>
> I wrote a better example of what I'm trying to do:
> https://gist.github.com/1420742 It runs worse with multiple threads than
> it does with one (both time-wise and memory-wise), I think due to the
> bug Simon described in that commit.

To be clear, the fix was for the problem where your program ran much 
slower with -threaded than without.  It probably won't have much effect 
on scaling.

In the program you linked above, I'm not terribly surprised if it 
doesn't scale well - it is basically a communication benchmark, and 
those perform best when running both threads on a single core.  In fact, 
I would go so far as to pin them both to the same core with forkOnIO.

Perhaps you might expect that, since the channel is unbounded, the 
writer thread should be able to produce data in batches that is then 
slurped up by the reader in batches.  Sure - but when running on two 
cores the data has to be moved from the cache of one core to the other, 
and that's a killer.  Much better to keep it in the cache of one core.

> But that bug aside, is it possible to write a multithreaded application
> in Haskell that sends large amounts of data from one thread to the other
> without getting crushed by GC? I've looked into the garbage collector a
> bit, and this seems problematic.

I don't think it's so much the GC as it is the cost of moving data 
across the memory bus.  Communication should be nice and fast if you 
keep it all on one core.  If I'm wrong please send me the code and I'll 
look into it!

Cheers,
        Simon



> Mike S Craig
>
>
> On Thu, Dec 1, 2011 at 2:38 PM, Edward Z. Yang <[email protected]
> <mailto:[email protected]>> wrote:
>
>     OK. A common mistake when using channels is forgetting to make sure
>     all of the informaiton is fully evaluated in the worker thread,
>     which then
>     causes the writer thread to spend all its time evaluating thunks.
>
>     Edward
>
>     Excerpts from Michael Craig's message of Thu Dec 01 13:17:57 -0500
>     2011 <tel:57%20-0500%202011>:
>      > Excellent! Glad this has been sorted out upstream.
>      >
>      > Edward, to answer your question regarding blocking database
>     calls: I'm
>      > using mongoDB to log events that come into a WAI webapp. The
>     writes to
>      > mongo are blocking, so I'd like to run them in parallel with the
>     webapp.
>      > The webapp would push the data into a Chan and the mongo writer
>     would read
>      > from the Chan and make the writes sequentially (using the Chan as
>     a FIFO
>      > between parallel threads). This would allow for request rates to
>      > temporarily rise above mongo's write rate (of course with an expanded
>      > memory footprint during those bursts).
>      >
>      > Mike S Craig
>      >
>      >
>      > On Thu, Dec 1, 2011 at 12:10 PM, Felipe Almeida Lessa <
>      > [email protected] <mailto:[email protected]>> wrote:
>      >
>      > > On Thu, Dec 1, 2011 at 2:40 PM, Edward Z. Yang <[email protected]
>     <mailto:[email protected]>> wrote:
>      > > > Simon Marlow investigated, and we got this patch out:
>      > >
>      > > Nice work, guys!  Hope it gets included in the glourious GHC
>     7.4 =D.
>      > >
>      > > Cheers,
>      > >
>      > > --
>      > > Felipe.
>      > >
>
>
>
>




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

Message: 6
Date: Fri, 2 Dec 2011 16:16:43 +0530
From: Rustom Mody <[email protected]>
Subject: Re: [Haskell-beginners] emacs setup for haskell
To: Adrien Haxaire <[email protected]>
Cc: [email protected]
Message-ID:
        <CAG3g5n=nbKOKhC0k3rLqiL=iwo4+f6h3lxmsdzcmpzfjqg2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Fri, Dec 2, 2011 at 2:03 PM, Adrien Haxaire <[email protected]> wrote:

> On Fri, 2 Dec 2011 10:53:55 +0530, Rustom Mody wrote:
>
>> I am using haskell inside emacs with the usual setup ie .hs file in
>> one window, ghci in another.
>>
>> Now the most usual workflow one would do is to load the file into ghci
>> (C-c C-l) and try out something in ghci.
>> A small niggle is that after the C-c C-l Ive to manually switch to the
>> other window (current window does not switch to ghci automatically)
>>  This seems to be a strange default
>>
>
> Actually I prefer it this way because I can check often if my types are
> OK, or that I don't have a typo.
> You can also rebind C-c C-l to execute C-x o after it.
>
>
>> More importantly the state of the workspace in ghci seems to get
>> messed up unless I do:
>> 0. Prepare some code in .hs
>> 2. Switch to ghci
>> 3. Clear the ghci workspace with :m
>>  4. switch back to .hs
>> 5. C-c C-l
>> 6. Switch to ghci to try out new code
>>
>> Is there something I am missing?
>>
>
> When I do C-c C-l it recompiles and/or reloads all my modules and wipes
> all the variables I had defined before, so I think steps 0 to 4 are not
> needed.
>

Yeah I guess I need to reproduce the case.
Yesterday I kept getting errors until I started this protocol of 'cleaning
the workspace' and then it worked.  Need to reconstruct what that case
was...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111202/f2e642dd/attachment-0001.htm>

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

Message: 7
Date: Fri, 02 Dec 2011 10:57:00 +0000
From: Hugo Ferreira <[email protected]>
Subject: Re: [Haskell-beginners] Diagnosing : Large memory usage + low
        CPU
To: "Edward Z. Yang" <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi Edward,

On 12/01/2011 07:55 AM, Edward Z. Yang wrote:
> Hello Hugo,
>
> Can you do a heap profile (+RTS -hT, or maybe use one of the other
> options if you've got a profiling copy lying around)?

I have attached a profiling session (showing types).
I am surprised to see that the "[]" consumes so much data.
Where is this coming from? Need to analyse this more closely.

> Try using
> smaller data if it's taking too long; usually the profile will still
> look the same, unless it's a particular type of input that is triggering
> bad behavior.
>

The case above is for test data that is about 1/5 of the original data.

> There is not enough detail in your code for me to use my psychic
> debugging skills, unfortunately.
>

I have very little knowledge of Haskell in order to interpret this
stuff correctly, even so I think we still need your "psychic
debugging skills" B-)

Any idea how I can track what's generating all those "[]" ?
Note that the (,,) seems to be the NGramTag. data which is basically
used as a list (Zipper).

regards,
Hugo F.

> Edward
>
> Excerpts from Hugo Ferreira's message of Wed Nov 30 09:23:53 -0500 2011:
>> Hello,
>>
>> On 11/29/2011 10:57 PM, Stephen Tetley wrote:
>>> Hi Hugo
>>>
>>> What is a POSTags and how big do you expect it to be?
>>>
>>>
>>
>> type Token = String
>> type Tag = String
>>
>> type NGramTag = (Token, Tag, Tag)
>>
>> type POSTags = Z.Zipper NGramTag
>>
>>> Generally I'd recommend you first try to calculate the size of your
>>> data rather than try to strictify things, see Johan Tibell's very
>>> useful posts:
>>>
>>>
>>> http://blog.johantibell.com/2011/06/memory-footprints-of-some-common-data.html
>>> http://blog.johantibell.com/2011/06/computing-size-of-hashmap.html
>>>
>>
>> According to size in String I am expecting a maximum of 50 Mega.
>> Profiling (after a painful 80 minutes) shows:
>>
>> total alloc = 20,350,382,592 bytes
>>
>> Way too much.
>>
>>> Once you know the size of your data - you can decide if it is too big
>>> to comfortably work with in memory. If it is too big you need to make
>>> sure you're are streaming[*] it rather than forcing it into memory.
>>>
>>> If POSTags is large, I'd be very concerned about the top line of
>>> updateState - reversing lists (or sorting them) simply doesn't play
>>> well with streaming.
>>>
>>
>> The zipper does quite a bit of reversing and appending.
>> I also need to reverse lists to retain the order of the
>> characters (text). I also do sorting but I have eliminated this
>> in the tests.
>>
>> So my question: how can one "force" the reversing and append?
>> Anyone?
>>
>> TIA,
>> Hugo F.
>>
>>>
>>> [*] Even in a lazy language like Haskell, streaming data isn't
>>> necessarily automatic.
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: postagger2.ps
Type: application/postscript
Size: 60160 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111202/0b1a9dc8/attachment.ps>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: postagger2.prof
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111202/0b1a9dc8/attachment.asc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postagger2.hp
Type: text/x-c++hdr
Size: 85660 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111202/0b1a9dc8/attachment.hpp>

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

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


End of Beginners Digest, Vol 42, Issue 3
****************************************

Reply via email to