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. Log_b(a) (Matthew J. Williams)
2. Re: Log_b(a) (Daniel Fischer)
3. Re: Using The Cabal that comes with GHC 6.10 on Windows
(Christian Maeder)
4. compiling first program --> warning (7stud)
5. Re: Log_b(a) (Ertugrul Soeylemez)
6. Re: Top beginner mistakes (7stud)
7. Re: Re: Top beginner mistakes (Brandon S. Allbery KF8NH)
8. folds -- help! (7stud)
9. Re: folds -- help! (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Sun, 08 Mar 2009 00:30:21 +0000
From: "Matthew J. Williams" <[email protected]>
Subject: [Haskell-beginners] Log_b(a)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"; format=flowed
Dear friends,
What is the Haskell equivlent of log_b(a)? To clarify, log of 36 to
the base 1.5.
Sincerely
Matthew J. Williams
------------------------------
Message: 2
Date: Sun, 8 Mar 2009 01:34:19 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Log_b(a)
To: "Matthew J. Williams" <[email protected]>,
[email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Sonntag, 8. März 2009 01:30 schrieb Matthew J. Williams:
> Dear friends,
>
> What is the Haskell equivlent of log_b(a)? To clarify, log of 36 to
> the base 1.5.
>
> Sincerely
> Matthew J. Williams
>
Prelude> :i logBase
class (Fractional a) => Floating a where
...
logBase :: a -> a -> a
...
-- Defined in GHC.Float
Prelude> logBase 1.5 36
8.838045165405818
Cheers,
Daniel
------------------------------
Message: 3
Date: Sun, 08 Mar 2009 13:11:06 +0100
From: Christian Maeder <[email protected]>
Subject: [Haskell-beginners] Re: Using The Cabal that comes with GHC
6.10 on Windows
To: Glenn <[email protected]>
Cc: beginners beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
Brandon S. Allbery KF8NH wrote:
> On 2009 Mar 7, at 5:42, Glenn wrote:
>> I've installed GHC 6.10.1, which comes with Cabal.
>> However, it doesn't seem to come in executable form ?
>
> Cabal is a compiler-specific library, so it comes with the compiler.
> cabal-install is a compiler-agnostic package on Hackage which installs
> an executable that uses compiler-specific libraries to adapt to the
> installed compiler(s). So you want to download and install cabal-install.
Right, and on Windows it is enough to download the executable
http://www.haskell.org/cabal/release/cabal-install-0.6.2/cabal.exe
from http://www.haskell.org/cabal/download.html
and put into a directory, where it will be found, i.e. where ghc-pkg and
ghc have been installed.
Cheers Christian
------------------------------
Message: 4
Date: Sun, 8 Mar 2009 13:15:33 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] compiling first program --> warning
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
When compiling my first haskell program (the program on p. 71-72 of RWH),
which I have in a file called hhask.hs, I got the following warning:
$ ghc --make hhask
[1 of 1] Compiling Main ( hhask.hs, hhask.o )
Linking hhask ...
/usr/bin/ld: warning -F:
directory name (/Users/me/Library/Frameworks) does not exist
The program works fine, but I'm wondering about that warning. Does
that mean I installed haskell in the wrong place? I installed haskell only
last week on osx 10.4.11, and here is what I did:
1) I downloaded GMP.framework and GNUreadline.framework, which my
mac automatically unzipped and placed on my desktop. I then dragged
the resulting two folders into Library/Frameworks as per the instructions
at:
http://www.haskell.org/ghc/download_ghc_682.html#macosxintel
2) I downloaded ghc-6.8.2
3) I unzipped and untared into:
/Users/me/my_tar_extractions
4) I cd'ed into the newly created ghc-6.8.2 folder. The full path to that
folder is:
/Users/me/my_tar_extractions/ghc-6.8.2
5) I read the INSTALL document in the ghc-6.8.2 folder.
6) I ran the command:
$ ./configure
7) Then I rand the command:
$ sudo make install
8) At the end of the install output, I got a message that said:
-------------
Installation of ghc-6.8.2 was successful.
To use, add /usr/local/bin to your PATH.
Warning: this binary distribution does NOT contain documentation!
--------------
9) I appended /usr/local/bin onto the PATH in ~/.bash_profile.
------------------------------
Message: 5
Date: Sun, 8 Mar 2009 18:30:37 +0100
From: Ertugrul Soeylemez <[email protected]>
Subject: [Haskell-beginners] Re: Log_b(a)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
"Matthew J. Williams" <[email protected]> wrote:
> Dear friends,
>
> What is the Haskell equivlent of log_b(a)? To clarify, log of 36 to
> the base 1.5.
I know it's probably bad style (because there is a specific function for
this) and also likely less efficient, I prefer to use this:
log a / log b
Unless performance is significant, I find that more elegant than
logBase.
Greets,
Ertugrul.
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/
------------------------------
Message: 6
Date: Mon, 9 Mar 2009 01:55:09 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] Re: Top beginner mistakes
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Benjamin L. Russell <DekuDekuplex <at> Yahoo.com> writes:
> >>
> >> Common Misunderstandings - HaskellWiki
> >> http://www.haskell.org/haskellwiki/Common_Misunderstandings
> >>
I thought I'd point out something wrong with the first beginner
mistake listed on that page:
--------
1.1 Indentation
...
...
What some miss is that then and else must be indented deeper
than the if statement:
if boolean
then expr1
else expr2
----------
My tests show that the 'then' and 'else' do not have to be indented
more than the 'if':
--bhask.hs
myfunc x = if x == 2
then "hello"
else "goodbye"
Prelude> :load bhask.hs
[1 of 1] Compiling Main ( bhask.hs, interpreted )
Ok, modules loaded: Main.
*Main> myfunc 2
"hello"
*Main> myfunc 3
"goodbye"
In fact, 'then' and 'else' work for me when they are indented less
than the 'if':
--bhask.hs
myfunc x = if x == 2
then "hello"
else "goodbye"
*Main> :load bhask.hs
[1 of 1] Compiling Main ( bhask.hs, interpreted )
Ok, modules loaded: Main.
*Main> myfunc 4
"goodbye"
*Main> myfunc 5
"goodbye"
*Main> myfunc 2
"hello"
I don't if haskell changed its indenting rules or what, but that
tip seems to be erroneous.
------------------------------
Message: 7
Date: Mon, 9 Mar 2009 02:24:23 -0400
From: "Brandon S. Allbery KF8NH" <[email protected]>
Subject: Re: [Haskell-beginners] Re: Top beginner mistakes
To: 7stud <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On 2009 Mar 8, at 21:55, 7stud wrote:
> Benjamin L. Russell <DekuDekuplex <at> Yahoo.com> writes:
>>>> Common Misunderstandings - HaskellWiki
>>>> http://www.haskell.org/haskellwiki/Common_Misunderstandings
>
> I thought I'd point out something wrong with the first beginner
> mistake listed on that page:
>
> My tests show that the 'then' and 'else' do not have to be indented
> more than the 'if':
They do, but only within layout, i.e. a "let" or "do", because
otherwise they fall outside the layout block.
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [email protected]
system administrator [openafs,heimdal,too many hats] [email protected]
electrical and computer engineering, carnegie mellon university KF8NH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url :
http://www.haskell.org/pipermail/beginners/attachments/20090309/010df599/PGP-0001.bin
------------------------------
Message: 8
Date: Mon, 9 Mar 2009 16:46:16 +0000 (UTC)
From: 7stud <[email protected]>
Subject: [Haskell-beginners] folds -- help!
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
This is an example that shows how foldl and foldr work (from RWH p.93-94):
foldl (+) 0 (1:2:3:[])
== foldl (+) (0 + 1) (2:3:[])
== foldl (+) ((0 + 1) + 2) (3:[])
== foldl (+) (((0 + 1) + 2) + 3) []
== (((0 + 1) + 2) + 3)
foldr (+) 0 (1:2:3:[])
== 1 + foldr (+) 0 (2:3:[])
== 1 + (2 + foldr (+) 0 (3:[])
== 1 + (2 + (3 + foldr (+) 0 []))
== 1 + (2 + (3 + 0))
The book says on p.94:
-----
The difference between foldl and foldr should be clear from looking at where
the parentheses and the empty list elements show up. With foldl, the empty
list element is on the left, and all the parentheses group to the left.
With foldr, the zero value is on the right, and the parentheses group to the
right.
----
Huh? With foldl, the only empty list element I see is on the right.
Initially, it looked to me ike they did the same thing, and that the only
difference was the way they called step. I think "step" is a horrible,
non-descriptive name, so I'm going to use "accFunc" instead:
foldl calls: accFunc acc x
foldr calls: accFunc x acc
So it looks like you can define a function using either one and get the
same result. Here is a test:
--I am going to use odd for pfunc and [1, 2, 3] for xs:
myFilter1 pfunc xs = foldl accFunc [] xs
where accFunc acc x
| pfunc x = acc ++ [x]
| otherwise = acc
myFilter2 pfunc xs = foldr accFunc [] xs
where accFunc x acc
| pfunc x = acc ++ [x]
| otherwise = acc
*Main> myFilter1 odd [1, 2, 3]
[1,3]
*Main> myFilter2 odd [1, 2, 3]
[3,1]
Hmmm. So there is a difference. foldr appears to grab elements from
the end of the list. Therefore, to get the same result from the function
that uses foldr, I did this:
myFilter3 pfunc xs = foldr accFunc [] xs
where accFunc x acc
| pfunc x = x : acc
| otherwise = acc
*Main> myFilter3 odd [1, 2, 3]
[1,3]
But then RWH explains that you would never use foldl in practice because it
thunks the result, which for large lists can overwhelm the maximum memory
alloted for a thunk. But it appears to me the same thunk problem would
occur with foldr. So why is foldr used in practice but not foldl?
------------------------------
Message: 9
Date: Mon, 9 Mar 2009 18:20:56 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] folds -- help!
To: 7stud <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Montag, 9. März 2009 17:46 schrieb 7stud:
> This is an example that shows how foldl and foldr work (from RWH p.93-94):
>
> foldl (+) 0 (1:2:3:[])
> == foldl (+) (0 + 1) (2:3:[])
> == foldl (+) ((0 + 1) + 2) (3:[])
> == foldl (+) (((0 + 1) + 2) + 3) []
> == (((0 + 1) + 2) + 3)
>
>
> foldr (+) 0 (1:2:3:[])
> == 1 + foldr (+) 0 (2:3:[])
> == 1 + (2 + foldr (+) 0 (3:[])
> == 1 + (2 + (3 + foldr (+) 0 []))
> == 1 + (2 + (3 + 0))
>
> The book says on p.94:
>
> -----
> The difference between foldl and foldr should be clear from looking at
> where the parentheses and the empty list elements show up. With foldl, the
> empty list element is on the left, and all the parentheses group to the
> left. With foldr, the zero value is on the right, and the parentheses group
> to the right.
> ----
>
> Huh? With foldl, the only empty list element I see is on the right.
What they meant was "the value that is the result in case the fold is applied
to an empty list", in this case the 0, in the definition
fold(l/r) f z xs = ...
the 'z'.
>
> Initially, it looked to me ike they did the same thing, and that the only
> difference was the way they called step. I think "step" is a horrible,
> non-descriptive name, so I'm going to use "accFunc" instead:
>
> foldl calls: accFunc acc x
>
> foldr calls: accFunc x acc
>
> So it looks like you can define a function using either one and get the
> same result.
Note that in general the list elements and acc have different types, so only
one of
accFun acc x
and
accFun x acc
typechecks.
If the types are the same, in general accFun x acc /= accFun acc x, so foldr
and foldl give different results, too.
> Here is a test:
>
> --I am going to use odd for pfunc and [1, 2, 3] for xs:
>
> myFilter1 pfunc xs = foldl accFunc [] xs
> where accFunc acc x
>
> | pfunc x = acc ++ [x]
> | otherwise = acc
>
> myFilter2 pfunc xs = foldr accFunc [] xs
> where accFunc x acc
>
> | pfunc x = acc ++ [x]
> | otherwise = acc
>
> *Main> myFilter1 odd [1, 2, 3]
> [1,3]
> *Main> myFilter2 odd [1, 2, 3]
> [3,1]
>
> Hmmm. So there is a difference. foldr appears to grab elements from
> the end of the list. Therefore, to get the same result from the function
> that uses foldr, I did this:
>
>
> myFilter3 pfunc xs = foldr accFunc [] xs
> where accFunc x acc
>
> | pfunc x = x : acc
> | otherwise = acc
>
> *Main> myFilter3 odd [1, 2, 3]
> [1,3]
>
> But then RWH explains that you would never use foldl in practice because it
> thunks the result, which for large lists can overwhelm the maximum memory
> alloted for a thunk. But it appears to me the same thunk problem would
> occur with foldr. So why is foldr used in practice but not foldl?
>
Since with foldr, the parentheses are grouped to the right:
x0 `f` (x1 `f` (x2 `f` ... (xn `f` z) ... )),
if f can start delivering the result without looking at its second argument,
you can start consuming the result before the fold has traversed the whole
list.
Common examples are things like
concat = foldr (++) [],
so
concat [l1,l2,l3,l4,l5] = l1 ++ (foldr (++) [] [l2,l3,l4,l5])
and the start (l1) can be used before further reducing the fold,
and = foldr (&&) True
and [True,False,..........]
needs only inspect the list until it encounters the first False (if any,
otherwise it must of course traverse the whole list)
or = foldr (||) False
foldr is useful if the combination function is lazy in its second argument.
foldl on the other hand can't deliver anything before the whole list is
consumed. So since foldl builds thunks (except in some easy cases where the
optimiser sees it should be strict), which would have to be evaluated at the
end when they've become rather large, foldl isn't as useful and one uses the
strict left fold, foldl'.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 9, Issue 9
***************************************