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:  gtk2hs not rendering drawingArea (Norbert Wojtowicz)
   2.  [haskell] About CPS form funtions (=?GB2312?B?zPC5zw==?=)
   3. Re:  [haskell] About CPS form funtions (wman)
   4. Re:  Profiling haskell code (Brent Yorgey)
   5. RE:  Profiling haskell code (Sayali Kulkarni)
   6.  HDBC commit problem (Moritz Tacke)
   7.  Bit arithmetic in Haskell (Artyom Shalkhakov)
   8. Re:  Bit arithmetic in Haskell (Brent Yorgey)


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

Message: 1
Date: Sat, 6 Dec 2008 12:58:30 +0100
From: "Norbert Wojtowicz" <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] gtk2hs not rendering drawingArea
To: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Thanks Johann!

That explains what I was doing wrong. For my purposes, I switched over
to the onExposeRect, but the same idea still holds. Thanks for
pointing me in the right direction.


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

Message: 2
Date: Mon, 8 Dec 2008 20:40:16 +0800
From: "=?GB2312?B?zPC5zw==?=" <[EMAIL PROTECTED]>
Subject: [Haskell-beginners] [haskell] About CPS form funtions
To: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Hi,
I am confused by section 4.6 in Yet Another Haskell Tutorial written
by Hal Daume III.
The auther provides a CPS form of "fold" funtion, but I don't know:
1. How to transform a normal function into CPS function. I need some
hint in writting "cfold".
2. Why "cfold" is CPS form? In my mind, if a CPS funtion calls to
other CPS function, it must only feed that function with either direct
variables or continuations. But in the tutorial, cfold defines:
cfold f z l = cfold' (\x t g -> f x (g t)) z l
Note that the lambda function body is f x (g t);  which means call
g(t) first, and take the result, then call f(x, r). It is illegal in
CPS because g(t) will never return. This is not same with function f.
Here, f can be treated as atomic operation (belong the CPS system).

Anyone can help me? Thank you in advance.

---
melon


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

Message: 3
Date: Mon, 8 Dec 2008 16:38:01 +0100
From: wman <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] [haskell] About CPS form funtions
To: "=?GB2312?B?zPC5zw==?=" <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-2022-jp"

On Mon, Dec 8, 2008 at 1:40 PM, $BE<1;(B <[EMAIL PROTECTED]> wrote:

> Hi,
> I am confused by section 4.6 in Yet Another Haskell Tutorial written
> by Hal Daume III.
> The auther provides a CPS form of "fold" funtion, but I don't know:
> 1. How to transform a normal function into CPS function. I need some
> hint in writting "cfold".


Normal function(s) return value(s).

CPS functions take the same value and uses/throws it as a parameter/argument
to the "extra" argument, the Continuation.

so to transform a function into CPS just
1) make the function take one extra argument, the continuation (the "rest"
of the process, next function in chain)
2) instead of returning a value, apply the continuation to the value (call
the continuation with the result you would normally return)

Example (taken from http://en.wikibooks.org/wiki/Haskell/CPS , check it out)

square :: Int -> Int
square x = x ^ 2

main = do
  let x = square 4
  print x

in CPS :

squareCPS :: Int -> (Int -> a) -> a
squareCPS x k = k (x ^ 2)

main = squareCPS 4 print

which shows that here, the print function is the continuation for the square
function.
instead of returning the value (16, or 4*4 here), the CPS variant feeds the
value to the continuation (print here)

hope it helps.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20081208/448b7174/attachment-0001.htm

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

Message: 4
Date: Mon, 8 Dec 2008 12:21:47 -0500
From: Brent Yorgey <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] Profiling haskell code
To: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii

> --function "number" which generates an array of numbers, it takes the
> ends of the range for numbers as inputs
> 
> number s e = if s > e
>               then []
>               else s : number (s + 1) e

Just an aside: instead of 'number s e' you can just write [s..e] .
 
> Now I want the array of numbers generated by the first function "number"
> tobe the input of the second function"quicksort".
> Then how should I apply the function number to quicksort?

Like this:  quicksort (number 3 50)

You always apply a function f to an input x like this: f x .  So the
above code says to apply quicksort to the input (number 3 50), which
is of course the output from applying number to the inputs 3 and 50.
The parentheses are needed since without them, 'quicksort number 3 50'
tries to give three inputs to quicksort, namely 'number' '3' and '50',
which is obviously wrong.

> Also do tel me which is the book that I can refer to for Haskell? 

There are many available books and online tutorials.  Some ones I might 
recommend for you:

  The Haskell wikibook -- http://en.wikibooks.org/wiki/Haskell 
  Yet Another Haskell Tutorial -- http://en.wikibooks.org/wiki/Haskell/YAHT
  Learn You a Haskell -- www.learnyouahaskell.com

  Programming in Haskell -- 
http://www.amazon.com/Programming-Haskell-Graham-Hutton/dp/0521692695
  
There are many other books and tutorials as well -- e.g., the Gentle
Introduction to Haskell, the Haskell School of Expression, and Real
World Haskell (just google them if you are interested).  Check these
out and hopefully you can find something that you like.

-Brent

> 
> 
> Regards,
> Sayali. 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Brent Yorgey
> Sent: Friday, December 05, 2008 6:54 PM
> To: [email protected]
> Subject: Re: [Haskell-beginners] Profiling haskell code
> 
> To get the output of one function to be the input to another, you just
> apply one to the other.  For example:
> 
>   -- This function generates a list
>   foo :: Int -> [Int]
>   foo n = [1..n]
> 
>   -- This function expects a list as input
>   bar :: [Int] -> Int
>   bar = sum . filter (>5)
> 
>   -- Use the output of foo as input to bar
>   main = print $ bar (foo 20)
> 
> Are you asking about something more than this?
> 
> -Brent
> 
> On Thu, Dec 04, 2008 at 05:42:42PM +0530, Sayali Kulkarni wrote:
> > Hey thanks Brent. This helped.
> > 
> > I have one more question now.
> > 
> > Consider I have two functions 
> > 1. gives me a range of numbers in an array.
> > 2. has to get an array input for further process.
> > 
> > Then how can I get the array generated by the first function tobe the
> > input of the second function?
> > 
> > Regards,
> > Sayali
> > 
> > -----Original Message-----
> > From: Brent Yorgey [mailto:[EMAIL PROTECTED] 
> > Sent: Tuesday, November 18, 2008 5:47 PM
> > To: Sayali Kulkarni
> > Subject: Re: [Haskell-beginners] Profiling haskell code
> > 
> > > I have just given it any random input array to be sorted.
> > > The commands that I had sent earlier were tried on Cygwin...
> > > (
> > > > > $ ghc --make Project.hs -prof -auto-all
> > > > >  
> > > > >  
> > > > > $ Project +RTS -p
> > > > >  ) 
> > 
> > This ought to work fine.  Just a note, to do any reasonable profiling
> > you will need to give it a *much* larger list to sort.  Otherwise it
> > will
> > execute so quickly that the timing data you get will be meaningless.
> > 
> > > 
> > > Also can you tell me any other method for profiling the code that
> you
> > > know? 
> > 
> > If you just want to see how long it takes to evaluate certain
> > expressions, you can type ':set +s' in ghci; from then on after every
> > expression you type it will tell you how long it took to evaluate and
> > how much memory was used.
> > 
> > -Brent
> > 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
> 


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

Message: 5
Date: Mon, 8 Dec 2008 10:28:24 +0530
From: "Sayali Kulkarni" <[EMAIL PROTECTED]>
Subject: RE: [Haskell-beginners] Profiling haskell code
To: "Brent Yorgey" <[EMAIL PROTECTED]>, <[email protected]>
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain;       charset="us-ascii"

Hello Brent , 

Thanks for the solution....

Now I have the 2 functions called number and quicksort resp. as follows:


--function "number" which generates an array of numbers, it takes the
ends of the range for numbers as inputs

number s e = if s > e
              then []
              else s : number (s + 1) e

-- this is the same quicksort function that I had used before
quicksort [] = []
quicksort (x : xs) = quicksort larger ++ [x ] ++ quicksort smaller
                                                where
                                                        smaller = [a | a
<- xs, a <= x ]
                                                        larger = [b | b
<- xs, b > x ]


Now I want the array of numbers generated by the first function "number"
tobe the input of the second function"quicksort".
Then how should I apply the function number to quicksort?

Can you help me out with this?
Also do tel me which is the book that I can refer to for Haskell? 


Regards,
Sayali. 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Brent Yorgey
Sent: Friday, December 05, 2008 6:54 PM
To: [email protected]
Subject: Re: [Haskell-beginners] Profiling haskell code

To get the output of one function to be the input to another, you just
apply one to the other.  For example:

  -- This function generates a list
  foo :: Int -> [Int]
  foo n = [1..n]

  -- This function expects a list as input
  bar :: [Int] -> Int
  bar = sum . filter (>5)

  -- Use the output of foo as input to bar
  main = print $ bar (foo 20)

Are you asking about something more than this?

-Brent

On Thu, Dec 04, 2008 at 05:42:42PM +0530, Sayali Kulkarni wrote:
> Hey thanks Brent. This helped.
> 
> I have one more question now.
> 
> Consider I have two functions 
> 1. gives me a range of numbers in an array.
> 2. has to get an array input for further process.
> 
> Then how can I get the array generated by the first function tobe the
> input of the second function?
> 
> Regards,
> Sayali
> 
> -----Original Message-----
> From: Brent Yorgey [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, November 18, 2008 5:47 PM
> To: Sayali Kulkarni
> Subject: Re: [Haskell-beginners] Profiling haskell code
> 
> > I have just given it any random input array to be sorted.
> > The commands that I had sent earlier were tried on Cygwin...
> > (
> > > > $ ghc --make Project.hs -prof -auto-all
> > > >  
> > > >  
> > > > $ Project +RTS -p
> > > >  ) 
> 
> This ought to work fine.  Just a note, to do any reasonable profiling
> you will need to give it a *much* larger list to sort.  Otherwise it
> will
> execute so quickly that the timing data you get will be meaningless.
> 
> > 
> > Also can you tell me any other method for profiling the code that
you
> > know? 
> 
> If you just want to see how long it takes to evaluate certain
> expressions, you can type ':set +s' in ghci; from then on after every
> expression you type it will tell you how long it took to evaluate and
> how much memory was used.
> 
> -Brent
> 
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

Message: 6
Date: Mon, 8 Dec 2008 17:55:56 +0100
From: "Moritz Tacke" <[EMAIL PROTECTED]>
Subject: [Haskell-beginners] HDBC commit problem
To: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Hi!

I am running into problems while using HDBC with the sqlite3 backend.
The HDBC "commit" statement frequently results in exceptions with the
sqlite3 errorcode 1, "SQL logic error or no database". As far as I
know, and as far as the HDBC docs tell me, "commit" simply writes all
yet open transactions onto the disk. How can it fail? The HDBC
documetation mentions the prepare- and execute-steps as the ones which
might throw exceptions - what are the problems a call to "commit"
might encounter? I do not suspect SQL errors to be the cause - those
should lead to earlier exceptions - and the database is definitly
present and opened, as select calls following the failing commit
statments succeed.
Greetings!


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

Message: 7
Date: Tue, 9 Dec 2008 17:30:28 +0600
From: "Artyom Shalkhakov" <[EMAIL PROTECTED]>
Subject: [Haskell-beginners] Bit arithmetic in Haskell
To: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=UTF-8

Hello,

I'm trying to do some bit arithmetic. Here's the function:

> import Data.Bits
> import Data.Word
>
> g :: Word32 -> [Word32]
> g x = [(x `shiftR` 24) .&. 0xFF,
>        (x `shiftR` 16) .&. 0xFF,
>        (x `shiftR` 8) .&. 0xFF,
>        x .&. 0xFF]

This function should give bytes for the given number, like this:

g 255 -> [0,0,0,255]
g 256 -> [0,0,1,255]
g 65535 -> [0,0,255,255]

In reality, I get very strange answers.

Can anybody help me please?

Regards,
Artyom Shalkhakov.


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

Message: 8
Date: Tue, 9 Dec 2008 08:02:46 -0500
From: Brent Yorgey <[EMAIL PROTECTED]>
Subject: Re: [Haskell-beginners] Bit arithmetic in Haskell
To: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii

On Tue, Dec 09, 2008 at 05:30:28PM +0600, Artyom Shalkhakov wrote:
> Hello,
> 
> I'm trying to do some bit arithmetic. Here's the function:
> 
> > import Data.Bits
> > import Data.Word
> >
> > g :: Word32 -> [Word32]
> > g x = [(x `shiftR` 24) .&. 0xFF,
> >        (x `shiftR` 16) .&. 0xFF,
> >        (x `shiftR` 8) .&. 0xFF,
> >        x .&. 0xFF]
> 
> This function should give bytes for the given number, like this:
> 
> g 255 -> [0,0,0,255]

This is the answer I get when I evaluate (g 255).

> g 256 -> [0,0,1,255]

This is incorrect -- the bytes for 256 are [0,0,1,0], which is
correctly computed by g.  [0,0,1,255] would be 1*256 + 255 = 511, and
giving 511 as input to g indeed results in [0,0,1,255].

> g 65535 -> [0,0,255,255]

When I evaluate (g 65535) this is what I get, too.

In short, it seems to me that g works perfectly.  If it doesn't work
for you, can you give specific examples of the output it should give,
and the output you get instead?

-Brent


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

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


End of Beginners Digest, Vol 6, Issue 3
***************************************

Reply via email to