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:  Translating a while (Yitzchak Gale)
   2. Re:  Translating a while (Yitzchak Gale)
   3.  Library source (Nicolas Couture-Grenier)
   4.  Re: Translating a while (Heinrich Apfelmus)
   5.  Re: Library source (Nicolas Couture-Grenier)
   6. Re:  Re: Library source (Brent Yorgey)
   7. Re:  Speed performance problem on Windows? (Kyle Murphy)
   8. Re:  Library source (Daniel Fischer)
   9. Re:  Library source (Dave Bayer)


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

Message: 1
Date: Mon, 8 Mar 2010 16:40:18 +0200
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Translating a while
To: Nicolas Couture-Grenier <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

> j xs = maybeLast . filter snd . zip [0..] $ zipWith (<) xs (drop 1 xs)
>  where
>    maybeLast [] = Nothing
>    maybeLast xs = Just (last xs)

Make that j xs = fmap fst . maybeLast . ... etc.

-Yitz


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

Message: 2
Date: Mon, 8 Mar 2010 16:50:18 +0200
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Translating a while
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Daniel Fischer wrote:
> When working with lists, one would typically not produce the next
> permutation from the previous, but generate the list of all permutations
> (take a look at the code of "permutations" in Data.List).

And even if you do need to use the classic "produce the
next permutation from the previous" algorithm, with Haskell
lists it would be more convenient to work from the beginning
of the list rather than the end, if possible. That produces
the permutations in "reverse dictionary" order instead of
dictionary order though. In a "reverse dictionary", the words
are ordered by looking at the last letter, then the previous letter,
etc.

Regards,
Yitz


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

Message: 3
Date: Mon, 8 Mar 2010 11:07:31 -0500
From: Nicolas Couture-Grenier <[email protected]>
Subject: [Haskell-beginners] Library source
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Where can I find the haskell sources of the standard library?

I searched for all files ending in .hs in my haskell folder and found none.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100308/43370f31/attachment-0001.html

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

Message: 4
Date: Mon, 08 Mar 2010 17:07:23 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Translating a while
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Daniel Fischer wrote:
> Am Montag 08 März 2010 14:49:15 schrieb Nicolas Couture-Grenier:
>> I'm learning Haskell and I'm trying to translate a pseudocode algorithm
>> to generate the next permutation from a previous permutation.
> 
> Don't try to translate it directly. In Haskell, generally a different 
> approach than for imperative (pseudo-) code is better.

For instance, like this:

        -- next permutation in lexicographic order
    next :: Ord a => [a] -> Maybe [a]
    next [x]    = Nothing
    next (x:xs) =
        case next xs of
            Nothing -> case span (> x) xs of
                ([],xs) -> Nothing
                (ys,zs) -> Just (last ys : reverse (init ys ++ x : zs))
            Just xs' -> Just (x:xs')

Since there is exactly one permutation that doesn't have a next one, the
result has to be wrapped in a  Maybe  type. Of course, this is very
handy and natural for the recursive formulation of the algorithm anyway.


Since the above definition contains some thought™, here a helper
function to test its correctness:

    permutationsFrom xs = xs : unfoldr (fmap (\x -> (x,x)) . next) xs

    correct n = let perms = permutationsFrom [1..n] in
           length perms == product [1..n]
        &&   sort perms == perms

In other words, repeatedly applying  next  to the trivial permutation
[1..n]  should eventually yield a sorted list of all permutations.

  *Main> correct 8
  True



Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



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

Message: 5
Date: Mon, 8 Mar 2010 11:11:10 -0500
From: Nicolas Couture-Grenier <[email protected]>
Subject: [Haskell-beginners] Re: Library source
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Sorry for the stupid question...

I downloaded them...



On Mon, Mar 8, 2010 at 11:07 AM, Nicolas Couture-Grenier <
[email protected]> wrote:

> Where can I find the haskell sources of the standard library?
>
> I searched for all files ending in .hs in my haskell folder and found none.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100308/6a75c364/attachment-0001.html

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

Message: 6
Date: Mon, 8 Mar 2010 11:19:11 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Re: Library source
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

You can also find them online, the easiest way is using Hoogle.  Say
you wanted to see the source code for the 'sort' function.  Go to

  haskell.org/hoogle

and search for 'sort'; the second result (Data.List.sort) is what we
want.  Clicking on it takes us to the documentation for sort.  Then at
the right margin there is a 'Source' link; clicking that lets us see
the definition of sort (and the rest of Data.List).

-Brent

On Mon, Mar 08, 2010 at 11:11:10AM -0500, Nicolas Couture-Grenier wrote:
> Sorry for the stupid question...
> 
> I downloaded them...
> 
> 
> 
> On Mon, Mar 8, 2010 at 11:07 AM, Nicolas Couture-Grenier <
> [email protected]> wrote:
> 
> > Where can I find the haskell sources of the standard library?
> >
> > I searched for all files ending in .hs in my haskell folder and found none.
> >

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



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

Message: 7
Date: Mon, 8 Mar 2010 11:30:29 -0500
From: Kyle Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Speed performance problem on Windows?
To: MAN <[email protected]>
Cc: [email protected], Travis Erdman <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

I'm sort of jumping into this conversation late, and I'm definitely a
Haskell newbie, but I have to wonder if the speed differences don't have
something to do with the C arguments passing conventions. I know there's
some rule that says if your first couple args are int's to pass them in the
CPU registers which might explain some of the speed boost for putting them
first. I need to go dig through my x86 reference manuals to get the exact
rules though.

-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.


On Sun, Mar 7, 2010 at 22:40, MAN <[email protected]> wrote:

> A little something I should have done before:
>
> Just compiled Don's C code (modified to my 32 bit laptop) with all
> flavors of precision. All the timings were similar:
>
> ~$ gcc bigmean.c -o bgC
> ~$ chmod +x bgC
> ~$ ./bgC 1000000000
> ~$ time ./bgC 1000000000
> 500000000.067109
>
> real    0m8.585s
> user    0m8.553s
> sys     0m0.000s
>
>
> So the time's I've been getting are approximating C speed quite well.
> There's still the difference between recursive and fusion code that
> haven't been able to gap...
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100308/1b396566/attachment-0001.html

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

Message: 8
Date: Mon, 8 Mar 2010 17:33:42 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Library source
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

Am Montag 08 März 2010 17:07:31 schrieb Nicolas Couture-Grenier:
> Where can I find the haskell sources of the standard library?
>
> I searched for all files ending in .hs in my haskell folder and found
> none.

If you don't build GHC from source (or download the source tarball just for 
the sake of it), you don't have the sources installed, however, there 
should be source-links in the library documentation (I think that comes 
with the binaries).

Otherwise, go to
http://www.haskell.org/ghc/docs/6.12.1/html/libraries/index.html
and then e.g. to 
http://www.haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Data-
List.html

There is a Source code link at the top, and at the documentation of each 
function, there's a link to the code of that particular function, e.g.
http://www.haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/src/Data-
List.html#permutations


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

Message: 9
Date: Mon, 8 Mar 2010 09:27:56 -0800
From: Dave Bayer <[email protected]>
Subject: Re: [Haskell-beginners] Library source
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


On Mar 8, 2010, at 8:07 AM, Nicolas Couture-Grenier wrote:

> Where can I find the haskell sources of the standard library?

As others have said, it depends how you install GHC.

This is a bit of a sore point with Haskell, masked by the fact that many people 
use online sources. I like to code on airline flights and places I don't have 
wifi, so local HTML versions of source for all libraries is essential.

Even building from source, cabal install doesn't produce every possible 
conceivable source file in HTML format. There are proposed fixes but they 
haven't been adopted. I resort to a script that manually rips out all CABAL 
documentation then rebuilds it from scratch, every time I add a library. If I 
had more time I'd tweak this script to be more clever, but it works, and I'm 
busy.

There are some dated assumptions behind all this; some of us are old enough to 
remember days when hard disk capacities were a serious resource constraint. 
That is no longer true. It is inconceivable to me that today, anyone serious 
about Haskell cares about its modest disk footprint. But hey, old habits die 
hard.

Why can't we agree as a community that no matter how one obtains GHC, on any 
platform by any delivery means, the default should be to provide absolutely 
every single line of source code as linked HTML? I mean, we're a serious 
language, and isn't such a principle part of the definition of being a serious 
language?




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

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


End of Beginners Digest, Vol 21, Issue 7
****************************************

Reply via email to