Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: Strange behavior of program ([email protected])
2. Re: Strange behavior of program (m00nlight)
3. Re: Strange behavior of program (Carsten K?nig)
----------------------------------------------------------------------
Message: 1
Date: Sun, 8 Mar 2015 12:01:44 +0000
From: <[email protected]>
To: m00nlight <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Strange behavior of program
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hello,
Given that you specifically indicated in your code that you wanted Int?s
instance of Read and that the result of the product is way over 2 ^ 32 (or 2 ^
64 for that matter), I?d guess the difference comes from the fact that the
product of a is done with type Int (that is, modulo 32 or 64 depending on your
computer?s CPU architecture) and the product with the litteral list is done
with type Integer because that the type Haskell defaults to in this case.
ARJANEN Lo?c Jean David
http://blog.luigiscorner.com
---
?Computer science is no more about computers than astronomy is about
telescopes, biology is about microscopes, or chemistry is about beakers and
test tubes. Science is not about tools. It is about how we use them, and what
we find out when we do.?
Michael R. Fellows and Ian Parberry
De : m00nlight
Envoy? : ?dimanche? ?8? ?mars? ?2015 ?21?:?59
? : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level
topics related to Haskell
Hi Haskellers,
I encounter an strange behavior of haskell program recently. The following is
my program
```haskell
main = do
_ <- getLine
arr1 <- getLine
_ <- getLine
arr2 <- getLine
let a = map (read :: String -> Int) (words arr1)
b = map (read :: String -> Int) (words arr2)
putStrLn $ show $ (foldl (*) 1 a)
putStrLn $ show $ a == [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]
putStrLn $ show $ (foldl (*) 1
[1,2,4,8,32,64,128,256,512,1024,2048,4906,8192])
```
With the input test file as following:
```test.in
13
1 2 4 8 32 64 128 256 512 1024 2048 4906 8192
9
1 3 9 27 81 243 729 2187 6561
```
The output is as:
```output
0
True
185343439719667835347140608
```
In fact, from the program, we know that a is equal to list
[1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] ,
but the product of a and the literal list is different.
Can anyone tell me why?
Thanks
--m00nlight
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150308/5937dc8d/attachment-0001.html>
------------------------------
Message: 2
Date: Sun, 8 Mar 2015 22:08:39 +0800 (CST)
From: m00nlight <[email protected]>
To: "arjanen.loic" <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Strange behavior of program
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Carsten and Arjanen,
Thanks for your explanation. :)
--m00nlight
?2015?03?08 20?01?, "arjanen.loic"<[email protected]>??:
Hello,
Given that you specifically indicated in your code that you wanted Int?s
instance of Read and that the result of the product is way over 2 ^ 32 (or 2 ^
64 for that matter), I?d guess the difference comes from the fact that the
product of a is done with type Int (that is, modulo 32 or 64 depending on your
computer?s CPU architecture) and the product with the litteral list is done
with type Integer because that the type Haskell defaults to in this case.
ARJANEN Lo?c Jean David
http://blog.luigiscorner.com
---
?Computer science is no more about computers than astronomy is about
telescopes, biology is about microscopes, or chemistry is about beakers and
test tubes. Science is not about tools. It is about how we use them, and what
we find out when we do.?
Michael R. Fellows and Ian Parberry
De : m00nlight
Envoy? : ?dimanche? ?8? ?mars? ?2015 ?21?:?59
? : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level
topics related to Haskell
Hi Haskellers,
I encounter an strange behavior of haskell program recently. The following is
my program
```haskell
main = do
_ <- getLine
arr1 <- getLine
_ <- getLine
arr2 <- getLine
let a = map (read :: String -> Int) (words arr1)
b = map (read :: String -> Int) (words arr2)
putStrLn $ show $ (foldl (*) 1 a)
putStrLn $ show $ a == [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]
putStrLn $ show $ (foldl (*) 1
[1,2,4,8,32,64,128,256,512,1024,2048,4906,8192])
```
With the input test file as following:
```test.in
13
1 2 4 8 32 64 128 256 512 1024 2048 4906 8192
9
1 3 9 27 81 243 729 2187 6561
```
The output is as:
```output
0
True
185343439719667835347140608
```
In fact, from the program, we know that a is equal to list
[1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] ,
but the product of a and the literal list is different.
Can anyone tell me why?
Thanks
--m00nlight
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150308/f1d40595/attachment-0001.html>
------------------------------
Message: 3
Date: Sun, 08 Mar 2015 15:26:24 +0100
From: Carsten K?nig <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Strange behavior of program
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
No problem - Num can be a bit confusing at first - just make sure to
compare the right things ;)
Am 08.03.2015 um 15:08 schrieb m00nlight:
> Carsten and Arjanen,
>
> Thanks for your explanation. :)
>
>
>
> --m00nlight
>
> ?2015?03?08 20?01?, "arjanen.loic"<[email protected]>??:
>
>
> Hello,
>
> Given that you specifically indicated in your code that you
> wanted Int?s instance of Read and that the result of the product
> is way over 2 ^ 32 (or 2 ^ 64 for that matter), I?d guess the
> difference comes from the fact that the product of a is done with
> type Int (that is, modulo 32 or 64 depending on your computer?s
> CPU architecture) and the product with the litteral list is done
> with type Integer because that the type Haskell defaults to in
> this case.
>
> ARJANEN Lo?c Jean David
> http://blog.luigiscorner.com
> ---
> ?Computer science is no more about computers than astronomy is
> about telescopes, biology is about microscopes, or chemistry is
> about beakers and test tubes. Science is not about tools. It is
> about how we use them, and what we find out when we do.?
> Michael R. Fellows and Ian Parberry
>
> *De :* m00nlight <mailto:[email protected]>
> *Envoy? :* ?dimanche? ?8? ?mars? ?2015 ?21?:?59
> *? :* The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell
> <mailto:[email protected]>
>
>
> Hi Haskellers,
>
> I encounter an strange behavior of haskell program recently. The
> following is my program
>
> ```haskell
> main = do
> _ <- getLine
> arr1 <- getLine
> _ <- getLine
> arr2 <- getLine
> let a = map (read :: String -> Int) (words arr1)
> b = map (read :: String -> Int) (words arr2)
>
> putStrLn $ show $ (foldl (*) 1 a)
> putStrLn $ show $ a ==
> [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]
> putStrLn $ show $ (foldl (*) 1
> [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192])
> ```
>
> With the input test file as following:
>
> ```test.in
> 13
> 1 2 4 8 32 64 128 256 512 1024 2048 4906 8192
> 9
> 1 3 9 27 81 243 729 2187 6561
> ```
>
> The output is as:
> ```output
> 0
> True
> 185343439719667835347140608
> ```
>
> In fact, from the program, we know that a is equal to list
> [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] ,
> but the product of a and the literal list is different.
>
> Can anyone tell me why?
>
> Thanks
>
>
>
>
> --m00nlight
>
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150308/e31c460e/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 31
*****************************************