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: Average of numeric list (David Virebayre)
2. Re: Average of numeric list (Daniel Fischer)
3. llvm on Mac (Alba Marchisio)
4. Re: Average of numeric list (Daniel Fischer)
5. Re: Average of numeric list (Nadav Chernin)
----------------------------------------------------------------------
Message: 1
Date: Tue, 5 Apr 2011 10:58:36 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
2011/4/4 Daniel Fischer <[email protected]>
>
> Note however, that that's not a particularly efficient way to calculate the
> mean, since the compiler isn't smart enough to transform it into a loop
> traversing the list once (so allowing it to be garbage collected as it is
> consumed and the computation to run in constant space) and keeping the
> accumulators evaluated.
>
I've always wondered, is it imaginable that a compiler would be able to do
such transforms (assuming very intelligent people (i.e. not me) have plenty
of time to work on it), or is it way too complicated ?
David.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110405/0ecb3aa9/attachment-0001.htm>
------------------------------
Message: 2
Date: Tue, 5 Apr 2011 11:14:31 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Tuesday 05 April 2011 10:38:37, Nadav Chernin wrote:
> Why only "length as" we must to cast? Why "sum as", that have type
> Integer can be used in (/).
>
> :t (/)
>
> (/) :: (Fractional a) => a -> a -> a
No, sum as has the type of as's elements,
sum :: Num a => [a] -> a
So the use of (/) refines the constraint from (Num a) to (Fractional a).
if you want it to work on Integers too,
you'd get
mean :: (Real a, Fractional b) => [a] -> b
mean xs = realToFrac (sum xs) / (fromIntegral $ length xs)
------------------------------
Message: 3
Date: Tue, 5 Apr 2011 11:15:36 +0200
From: Alba Marchisio <[email protected]>
Subject: [Haskell-beginners] llvm on Mac
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi All.
I want to build my code using -fllvm option in GHC. (ghc --make main.hs
-fllvm -o lexer)
Doing so I've got the warning:
Warning: -fllvm is incompatible with -fPIC and -dynamic on this platform;
ignoring -fllvm
My system is MacOS X 10.6.7 with Xcode 4 and I've installed GHC 7.0.3 (64
bit)
Any idea ?
Alba.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110405/b04f6708/attachment-0001.htm>
------------------------------
Message: 4
Date: Tue, 5 Apr 2011 11:28:28 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: David Virebayre <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Tuesday 05 April 2011 10:58:36, David Virebayre wrote:
> 2011/4/4 Daniel Fischer <[email protected]>
>
> > Note however, that that's not a particularly efficient way to
> > calculate the mean, since the compiler isn't smart enough to
> > transform it into a loop traversing the list once (so allowing it to
> > be garbage collected as it is consumed and the computation to run in
> > constant space) and keeping the accumulators evaluated.
>
> I've always wondered, is it imaginable that a compiler would be able to
> do such transforms (assuming very intelligent people (i.e. not me)
> have plenty of time to work on it), or is it way too complicated ?
It is imaginable, within some limits.
I'm pretty sure one can't write an algorithm that spots *all* occurrences
of code where such a rewrite would be good, but one can write algorithms to
spot specific patterns.
Spotting more patterns would require more code in the compiler, and it
would increase compile times.
So one has to decide whether the cost is worth the benefit.
Apparently, so far it has not been considered worthwhile.
------------------------------
Message: 5
Date: Tue, 5 Apr 2011 12:57:32 +0300
From: Nadav Chernin <[email protected]>
Subject: Re: [Haskell-beginners] Average of numeric list
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
How can i know when casting of types maked by compiler and when programmer
must to do it?
On Tue, Apr 5, 2011 at 12:14 PM, Daniel Fischer <
[email protected]> wrote:
> On Tuesday 05 April 2011 10:38:37, Nadav Chernin wrote:
> > Why only "length as" we must to cast? Why "sum as", that have type
> > Integer can be used in (/).
> >
> > :t (/)
> >
> > (/) :: (Fractional a) => a -> a -> a
>
> No, sum as has the type of as's elements,
>
> sum :: Num a => [a] -> a
>
> So the use of (/) refines the constraint from (Num a) to (Fractional a).
> if you want it to work on Integers too,
> you'd get
>
> mean :: (Real a, Fractional b) => [a] -> b
> mean xs = realToFrac (sum xs) / (fromIntegral $ length xs)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110405/fae08d4d/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 34, Issue 7
****************************************