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.  what does (# a, s #) mean? (Amitava Shee)
   2. Re:  what does (# a, s #) mean? (Krzysztof Skrz?tnicki)
   3. Re:  what does (# a, s #) mean? (Henk-Jan van Tuyl)
   4.  Calling a foreign function: superlinear  comlexity (Serguei Son)
   5. Re:  Calling a foreign function: superlinear      comlexity
      (David McBride)
   6. Re:  Calling a foreign function: superlinear      comlexity
      (Serguei Son)
   7. Re:  Calling a foreign function: superlinear      comlexity
      (Antoine Latter)


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

Message: 1
Date: Sun, 10 Apr 2011 13:29:38 -0400
From: Amitava Shee <[email protected]>
Subject: [Haskell-beginners] what does (# a, s #) mean?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I came across this definition in ghc source

$GHC/compiler/utils/State.hs
=======================
newtype State s a = State { runState' :: s -> (# a, s #) }


What does the construct (# a, s #) mean?

Thanks & Regards,
Amitava Shee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110410/e2d175a6/attachment-0001.htm>

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

Message: 2
Date: Sun, 10 Apr 2011 20:00:29 +0200
From: Krzysztof Skrz?tnicki <[email protected]>
Subject: Re: [Haskell-beginners] what does (# a, s #) mean?
To: Amitava Shee <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

It's the syntax for unboxed tuple. See:
http://www.haskell.org/ghc/docs/latest/html/users_guide/primitives.html#unboxed-tuples

<http://www.haskell.org/ghc/docs/latest/html/users_guide/primitives.html#unboxed-tuples>Best
regards,
Krzysztof Skrz?tnicki

On Sun, Apr 10, 2011 at 19:29, Amitava Shee <[email protected]> wrote:

> I came across this definition in ghc source
>
> $GHC/compiler/utils/State.hs
> =======================
> newtype State s a = State { runState' :: s -> (# a, s #) }
>
>
> What does the construct (# a, s #) mean?
>
> Thanks & Regards,
> Amitava Shee
>
> _______________________________________________
> 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/20110410/5cc9826c/attachment-0001.htm>

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

Message: 3
Date: Sun, 10 Apr 2011 20:04:58 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] what does (# a, s #) mean?
To: [email protected], "Amitava Shee" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Sun, 10 Apr 2011 19:29:38 +0200, Amitava Shee <[email protected]>  
wrote:

> I came across this definition in ghc source
>
> $GHC/compiler/utils/State.hs
> =======================
> newtype State s a = State { runState' :: s -> (# a, s #) }
>
>
> What does the construct (# a, s #) mean?
>

This is an unboxed tuple, see:
   
http://www.haskell.org/ghc/docs/latest/html/users_guide/primitives.html#unboxed-tuples

Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--



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

Message: 4
Date: Sun, 10 Apr 2011 23:26:16 +0000 (UTC)
From: Serguei Son <[email protected]>
Subject: [Haskell-beginners] Calling a foreign function: superlinear
        comlexity
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

I call GSL's gsl_ran_ugaussian function in the following way (using
bindings-gsl):

module Main where

import Bindings.Gsl.RandomNumberGeneration
import Bindings.Gsl.RandomNumberDistributions
import Foreign
import Control.Monad
import Data.List

main = do
        let n = 100000
        p <- peek p'gsl_rng_mt19937
        rng <- c'gsl_rng_alloc p
        lst <- replicateM n $ c'gsl_rng_uniform rng
        print $ sum lst 

As I increase n from 10^4 to 10^5 to 10^6 execution time grows superlinearly.

To forestall the answer that the reason is the overhead of List, 
this code scales approximately linearly:

module Main where


import Foreign
import Control.Monad
import Data.List

main = do
        let n = 100000
        let lst = map sin [1..n]
        print $ sum lst 

Another interesting observation: when I wrap the sin function 
of math.h with signature CDouble -> IO CDouble calling it 
repeatedly scales superlinearly, whereas when I wrap it as a pure 
function calling it repeatedly scales linearly.

What is the reason for this performance and how can 
I make the first code scale linearly in execution time?







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

Message: 5
Date: Sun, 10 Apr 2011 21:53:50 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Calling a foreign function:
        superlinear     comlexity
To: Serguei Son <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

The problem isn't the list or the library library.  It is the use of
the function sum, which is lazy and when you try to sum a very large
list, it makes a thunk for every single element in the list before
finally evaluating them all backwards to get the sum.

main = do
       let n = 40000000
       let lst = map sin [1..n]
       print $ sum' lst
  where
    sum' = foldl1' (+)

This is linear, repeatable and quite a bit faster.

On Sun, Apr 10, 2011 at 7:26 PM, Serguei Son <[email protected]> wrote:
> I call GSL's gsl_ran_ugaussian function in the following way (using
> bindings-gsl):
>
> module Main where
>
> import Bindings.Gsl.RandomNumberGeneration
> import Bindings.Gsl.RandomNumberDistributions
> import Foreign
> import Control.Monad
> import Data.List
>
> main = do
> ? ? ? ?let n = 100000
> ? ? ? ?p <- peek p'gsl_rng_mt19937
> ? ? ? ?rng <- c'gsl_rng_alloc p
> ? ? ? ?lst <- replicateM n $ c'gsl_rng_uniform rng
> ? ? ? ?print $ sum lst
>
> As I increase n from 10^4 to 10^5 to 10^6 execution time grows superlinearly.
>
> To forestall the answer that the reason is the overhead of List,
> this code scales approximately linearly:
>
> module Main where
>
>
> import Foreign
> import Control.Monad
> import Data.List
>
> main = do
> ? ? ? ?let n = 100000
> ? ? ? ?let lst = map sin [1..n]
> ? ? ? ?print $ sum lst
>
> Another interesting observation: when I wrap the sin function
> of math.h with signature CDouble -> IO CDouble calling it
> repeatedly scales superlinearly, whereas when I wrap it as a pure
> function calling it repeatedly scales linearly.
>
> What is the reason for this performance and how can
> I make the first code scale linearly in execution time?
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 6
Date: Mon, 11 Apr 2011 02:22:18 +0000 (UTC)
From: Serguei Son <[email protected]>
Subject: Re: [Haskell-beginners] Calling a foreign function:
        superlinear     comlexity
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Tried using foldl' (+) instead of sum, unfortunately it 
has not made the comlexity linear.







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

Message: 7
Date: Sun, 10 Apr 2011 23:05:23 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Calling a foreign function:
        superlinear     comlexity
To: Serguei Son <[email protected]>
Cc: [email protected], haskell mailing list
        <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Sun, Apr 10, 2011 at 6:26 PM, Serguei Son <[email protected]> wrote:
> I call GSL's gsl_ran_ugaussian function in the following way (using
> bindings-gsl):
>
> module Main where
>
> import Bindings.Gsl.RandomNumberGeneration
> import Bindings.Gsl.RandomNumberDistributions
> import Foreign
> import Control.Monad
> import Data.List
>
> main = do
> ? ? ? ?let n = 100000
> ? ? ? ?p <- peek p'gsl_rng_mt19937
> ? ? ? ?rng <- c'gsl_rng_alloc p
> ? ? ? ?lst <- replicateM n $ c'gsl_rng_uniform rng
> ? ? ? ?print $ sum lst
>
> As I increase n from 10^4 to 10^5 to 10^6 execution time grows superlinearly.
>

Not sure if it is related, but this thread also documents issues folks
had with replicateM and performance:

http://www.haskell.org/pipermail/haskell-cafe/2011-March/090419.html

Antoine

> To forestall the answer that the reason is the overhead of List,
> this code scales approximately linearly:
>
> module Main where
>
>
> import Foreign
> import Control.Monad
> import Data.List
>
> main = do
> ? ? ? ?let n = 100000
> ? ? ? ?let lst = map sin [1..n]
> ? ? ? ?print $ sum lst
>
> Another interesting observation: when I wrap the sin function
> of math.h with signature CDouble -> IO CDouble calling it
> repeatedly scales superlinearly, whereas when I wrap it as a pure
> function calling it repeatedly scales linearly.
>
> What is the reason for this performance and how can
> I make the first code scale linearly in execution time?
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

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


End of Beginners Digest, Vol 34, Issue 20
*****************************************

Reply via email to