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. Re:  How to convert a Data.Set to a Descending    List?
      (Felipe Almeida Lessa)
   2. Re:  How to convert a Data.Set to a Descending    List?
      (Sunil S Nandihalli)
   3. Re:  How to convert a Data.Set to a Descending    List? (David Place)
   4.  bugs or lack thereof (Dennis Raddle)
   5.  main: <<loop>> ....? (Sunil S Nandihalli)
   6. Re:  main: <<loop>> ....? (Sunil S Nandihalli)
   7. Re:  main: <<loop>> ....? (Benjamin Edwards)
   8. Re:  main: <<loop>> ....? (David Virebayre)
   9. Re:  main: <<loop>> ....? (Sunil S Nandihalli)
  10. Re:  main: <<loop>> ....? (David Virebayre)
  11. Re:  main: <<loop>> ....? (Sunil S Nandihalli)


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

Message: 1
Date: Sun, 21 Aug 2011 09:30:26 -0300
From: Felipe Almeida Lessa <felipe.le...@gmail.com>
Subject: Re: [Haskell-beginners] How to convert a Data.Set to a
        Descending      List?
To: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <CANd=OGEQiUk=ejhkdk+6bgj_5fxxdcyd7_wb_6dhcmyvb3n...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Sun, Aug 21, 2011 at 5:18 AM, Sunil S Nandihalli
<sunil.nandiha...@gmail.com> wrote:
> ?Is there a more efficient way to convert a Set to a descending list?
> I was looking for a function similar to Set.toAscList something like
> Set.toDecList . I feel first converting to a ascending list and then
> reversing may be in-efficient given that I actually don't need all the
> elements only a last couple of elements..

Implementing toDecList should be easy, but it's not implemented.  So I
can see a couple of ideas:

a) Instead of using a 'Set X', where X is your datatype, use 'Set (Rev X)' where

  newtype Rev t = Rev t
  instance Eq t => Eq (Rev t) where Rev x == Rev y = x == y
  instance Ord t => Ord (Rev t) where compare (Rev x) (Rev y) = compare y x

Then you would just need to use toAscList =).

b) If you need both the few first and few last elements to toAscList,
then option a doesn't work.  But if you really need just a few
elements, you may use maxKey:

  toDecList s =
    case maxView s of
      Nothing -> []
      Just (x, s') -> x : toDecList s'

  The problem is that 'take k . toDecList' take O(k log n) instead of O(k).

c) Data.Set.fold says that the order is unspecified.  But the current
implementation does the fold in ascending order.  You may cheat and
implement:

  toDecList s = fold (\a b -> b . (a:)) id s []

Cheers, =)

-- 
Felipe.



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

Message: 2
Date: Sun, 21 Aug 2011 19:16:13 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: Re: [Haskell-beginners] How to convert a Data.Set to a
        Descending      List?
To: Felipe Almeida Lessa <felipe.le...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <CAP0FD71C0dkfA-aXTSHbwW6wu65U9VUSSWAK-dxe+VuAR4x=a...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Felipe,
 Thanks a lot for your response. I thought I should describe what I
want in a little more detail. You may have a better suggestion to
solve the problem.
 I currently have a Set I want to take a couple of elements on either
side of a given key. How can I do this? Here is a description of the
subseq function in clojure.
http://clojuredocs.org/clojure_core/clojure.core/subseq
Thanks,
Sunil.

On Sun, Aug 21, 2011 at 6:00 PM, Felipe Almeida Lessa
<felipe.le...@gmail.com> wrote:
> On Sun, Aug 21, 2011 at 5:18 AM, Sunil S Nandihalli
> <sunil.nandiha...@gmail.com> wrote:
>> ?Is there a more efficient way to convert a Set to a descending list?
>> I was looking for a function similar to Set.toAscList something like
>> Set.toDecList . I feel first converting to a ascending list and then
>> reversing may be in-efficient given that I actually don't need all the
>> elements only a last couple of elements..
>
> Implementing toDecList should be easy, but it's not implemented. ?So I
> can see a couple of ideas:
>
> a) Instead of using a 'Set X', where X is your datatype, use 'Set (Rev X)' 
> where
>
> ?newtype Rev t = Rev t
> ?instance Eq t => Eq (Rev t) where Rev x == Rev y = x == y
> ?instance Ord t => Ord (Rev t) where compare (Rev x) (Rev y) = compare y x
>
> Then you would just need to use toAscList =).
>
> b) If you need both the few first and few last elements to toAscList,
> then option a doesn't work. ?But if you really need just a few
> elements, you may use maxKey:
>
> ?toDecList s =
> ? ?case maxView s of
> ? ? ?Nothing -> []
> ? ? ?Just (x, s') -> x : toDecList s'
>
> ?The problem is that 'take k . toDecList' take O(k log n) instead of O(k).
>
> c) Data.Set.fold says that the order is unspecified. ?But the current
> implementation does the fold in ascending order. ?You may cheat and
> implement:
>
> ?toDecList s = fold (\a b -> b . (a:)) id s []
>
> Cheers, =)
>
> --
> Felipe.
>



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

Message: 3
Date: Sun, 21 Aug 2011 10:10:17 -0400
From: David Place <d...@vidplace.com>
Subject: Re: [Haskell-beginners] How to convert a Data.Set to a
        Descending      List?
To: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <e082a31e-d6f6-4440-80ce-c8524bb04...@vidplace.com>
Content-Type: text/plain; charset=us-ascii


On Aug 21, 2011, at 9:46 AM, Sunil S Nandihalli wrote:

> I currently have a Set I want to take a couple of elements on either
> side of a given key. How can I do this?

I'll bet this is very easy using Finger Trees.  

> http://www.soi.city.ac.uk/~ross/papers/FingerTree.html

> http://hackage.haskell.org/packages/archive/fingertree/0.0/doc/html/Data-FingerTree.html


____________________
David Place   
Owner, Panpipes Ho! LLC
http://panpipesho.com
d...@vidplace.com






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

Message: 4
Date: Sun, 21 Aug 2011 16:53:43 -0700
From: Dennis Raddle <dennis.rad...@gmail.com>
Subject: [Haskell-beginners] bugs or lack thereof
To: Haskell Beginners <beginners@haskell.org>
Message-ID:
        <cakxlvooamfbfqepwz6vk-0wxl0indah+zlwa+beekhnwec3...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I love Haskell for the fact that my programs have relatively few bugs
other than typos or obvious mistakes in types that the compiler
catches. I just wrote about 100 lines of code to do a fairly complex
task, which is to make a map of changing loudness in a musical
document (including slopes, not just flat level changes) and after I
got the typos out and it compiled, it just worked.

I have been a professional programmer in imperative languages for 20
years, so I can think pretty accurately about what I am doing, but I'm
new to Haskell, and it's a marked difference in the ease of getting
something to work right.

Dennis



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

Message: 5
Date: Mon, 22 Aug 2011 13:02:45 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: [Haskell-beginners] main: <<loop>> ....?
To: beginners@haskell.org
Message-ID:
        <CAP0FD708UC9=xnetmgpssxfkn_stdzro4uehctpwwgyucqr...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hello everybody,
main: <<loop>>  -> where did this come from. I know I am not printing
it anywhere .. and it is not printing some of things I am tracing
using Debug.Trace module. Can somebody help?
Thanks,
Sunil.



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

Message: 6
Date: Mon, 22 Aug 2011 13:06:46 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: Re: [Haskell-beginners] main: <<loop>> ....?
To: beginners@haskell.org
Message-ID:
        <CAP0FD73J=aUC+kjXi73jsurjK8owDCOWQK0VOzy=kuhnzy7...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

I failed to tell that it prints "main : <<loop>>" and terminates... I
was not clear about it in my previous email.. but that is what I
meant. my appologies ..

On Mon, Aug 22, 2011 at 1:02 PM, Sunil S Nandihalli
<sunil.nandiha...@gmail.com> wrote:
> Hello everybody,
> main: <<loop>> ?-> where did this come from. I know I am not printing
> it anywhere .. and it is not printing some of things I am tracing
> using Debug.Trace module. Can somebody help?
> Thanks,
> Sunil.
>



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

Message: 7
Date: Mon, 22 Aug 2011 08:41:18 +0100
From: Benjamin Edwards <edwards.b...@gmail.com>
Subject: Re: [Haskell-beginners] main: <<loop>> ....?
To: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <can6k4njgjq6wp1y7hfza_wcmbm4eeu_wdtoo42iudp0efhz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Where is the code?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110822/318707b2/attachment-0001.htm>

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

Message: 8
Date: Mon, 22 Aug 2011 09:43:46 +0200
From: David Virebayre <dav.vire+hask...@gmail.com>
Subject: Re: [Haskell-beginners] main: <<loop>> ....?
To: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <cam_wfvtxh_a3kizqj5m4j6o5ylfjmleh6ycj9jd1jwssbzy...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2011/8/22 Sunil S Nandihalli <sunil.nandiha...@gmail.com>:
> I failed to tell that it prints "main : <<loop>>" and terminates... I
> was not clear about it in my previous email.. but that is what I
> meant. my appologies ..

That is exactly what ghc does. In some cases, it is able to detect a
function does nothing but loop, so it prints <<loop>> and terminates.

I don't know the details of how that works, I'm sure someone will be
able to explain it in detail, but consider this example :

david@pcdavid:~$ cat loop.hs
main = main
david@pcdavid:~$ ghc --make loop.hs
[1 of 1] Compiling Main             ( loop.hs, loop.o )
Linking loop ...
david@pcdavid:~$ ./loop
loop: <<loop>>



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

Message: 9
Date: Mon, 22 Aug 2011 13:15:46 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: Re: [Haskell-beginners] main: <<loop>> ....?
To: Benjamin Edwards <edwards.b...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <cap0fd71ng+u7uzwwf72tox1ggdfhwavppfqzsp0hoa5jgyu...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Benjamin,
 It was longer than I could post here .. but here it is ..

https://github.com/sunilnandihalli/is2/blob/master/main.hs

Sunil.

On Mon, Aug 22, 2011 at 1:11 PM, Benjamin Edwards
<edwards.b...@gmail.com> wrote:
> Where is the code?



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

Message: 10
Date: Mon, 22 Aug 2011 09:49:02 +0200
From: David Virebayre <dav.vire+hask...@gmail.com>
Subject: Re: [Haskell-beginners] main: <<loop>> ....?
To: Sunil S Nandihalli <sunil.nandiha...@gmail.com>,    beginners
        <beginners@haskell.org>
Message-ID:
        <cam_wfvtd1acz-m3nttjt4fto8yb0h0lxcufily-zjjd6gzl...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2011/8/22 Sunil S Nandihalli <sunil.nandiha...@gmail.com>:
> Is there a way I can find out where it is in infinite loop?

I don't know of any other way to find it than looking at the code, I
hope someone with more experience will be able to explain a better
way.

After looking at the source code you posted, does it print anything
before it prints <<loop>> ?



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

Message: 11
Date: Mon, 22 Aug 2011 13:22:18 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: Re: [Haskell-beginners] main: <<loop>> ....?
To: David Virebayre <dav.vire+hask...@gmail.com>
Cc: beginners <beginners@haskell.org>
Message-ID:
        <cap0fd72bi6wpcajcdmf2jsz8asbgtlkpcexbm95hdhnvd2f...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Yes David, it is printing some stuff.. I am trying to track down where
it is getting into infinite loop by placing a lot of trace commands ..
Thanks
Sunil.

On Mon, Aug 22, 2011 at 1:19 PM, David Virebayre
<dav.vire+hask...@gmail.com> wrote:
> 2011/8/22 Sunil S Nandihalli <sunil.nandiha...@gmail.com>:
>> Is there a way I can find out where it is in infinite loop?
>
> I don't know of any other way to find it than looking at the code, I
> hope someone with more experience will be able to explain a better
> way.
>
> After looking at the source code you posted, does it print anything
> before it prints <<loop>> ?
>



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

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


End of Beginners Digest, Vol 38, Issue 39
*****************************************

Reply via email to