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. FastCGI error (Wayne R)
2. Re: Using Debug.Trace (Patrick LeBoutillier)
3. Applicative Functors: Rose Trees with an alternate behavior
(Travis Erdman)
4. Re: Trying to statically link Gtk2Hs application (Windows
XP, network drive) (Peter Schmitz)
5. Re: Re: Trying to statically link Gtk2Hs application
(Windows XP, network drive) (Felipe Lessa)
6. Why does this work in a program, but cause a seg fault in
ghci? (Kurt H?usler)
7. Re: Why does this work in a program, but cause a seg fault
in ghci? (Sebasti?n E. Peyrott)
----------------------------------------------------------------------
Message: 1
Date: Tue, 10 Aug 2010 12:35:11 -0500
From: Wayne R <[email protected]>
Subject: [Haskell-beginners] FastCGI error
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I'm trying to use Network.FastCGI with Apache2, but running into an error.
I'd like to believe that the web server is configured correctly, because I
can successfully view the following, compiled to <web
root>/fastcgi/test.fcgi:
#include <fcgi_stdio.h>
int main(void){
int count = 0;
while(FCGI_Accept()>=0){
printf("Content-Type: text/html\r\n");
printf("\r\n");
printf("Hello, World: %d", count++);
}
return 0;
}
Now I compile Fcgi.hs to <web root>/fastcgi/test2.fcgi:
import Control.Concurrent
import Network.FastCGI
action :: CGI CGIResult
action = do
setHeader "Content-type" "text/plain"
tid <- liftIO myThreadId
output $ unlines
[ "I am a FastCGI process!"
, "Hear me roar!"
, ""
, show tid
]
main = runFastCGIConcurrent' forkIO 10 action
When I view localhost/fastcgi/test.fcgi, I get the hello world page, but
attempting to view test2.fcgi shows an 'Internal Server Error" in firefox.
The apache error log says:
[Sun Aug 08 07:44:17 2010] [notice] Apache/2.2.14 (Ubuntu) mod_fastcgi/2.4.6
mod_lisp2/1.3.1 PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch mod_ssl/2.2.14
OpenSSL/0.9.8k configured -- resuming normal operations
[Mon Aug 09 11:11:23 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test.fcgi" started (pid 20354)
[Mon Aug 09 11:11:27 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20360)
[Mon Aug 09 11:11:31 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20365)
[Mon Aug 09 11:11:34 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20371)
[Mon Aug 09 11:11:37 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20375)
[Mon Aug 09 11:11:40 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20379)
[Mon Aug 09 11:11:43 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20383)
[Mon Aug 09 11:11:46 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20387)
[Mon Aug 09 11:11:49 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20391)
[Mon Aug 09 11:11:52 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20395)
[Mon Aug 09 11:11:55 2010] [warn] FastCGI: scheduled the start of the last
(dynamic) server "/var/www/fastcgi/test2.fcgi" process: reached
dynamicMaxClassProcs (10)
[Mon Aug 09 11:11:55 2010] [warn] FastCGI: (dynamic) server
"/var/www/fastcgi/test2.fcgi" started (pid 20399)
[Mon Aug 09 11:12:01 2010] [error] [client 127.0.0.1] FastCGI: comm with
(dynamic) server "/var/www/fastcgi/test2.fcgi" aborted: (first read) idle
timeout (30 sec)
[Mon Aug 09 11:12:01 2010] [error] [client 127.0.0.1] FastCGI: incomplete
headers (0 bytes) received from server "/var/www/fastcgi/test2.fcgi"
I've tried Fcgi.hs with two different sample FastCGI programs with the same
results. Any suggestions?
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100810/13287412/attachment-0001.html
------------------------------
Message: 2
Date: Tue, 10 Aug 2010 14:52:45 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] Using Debug.Trace
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I tried the bang patterns, it seems to force evaluation enough in most
cases to triger the "trace" call.
Thanks a lot,
Patrick
On Sun, Aug 8, 2010 at 2:18 PM, Daniel Fischer <[email protected]> wrote:
> On Sunday 08 August 2010 19:14:41, Patrick LeBoutillier wrote:
>> Hi all,
>>
>> I'm writing a parser for a binary format, and I'm trying to debug it
>> since I have a bug and the code is getting lost in the bits and bytes.
>> Basically my main is like this:
>>
>> import Data.Binary.Get
>> import Debug.Trace
>> import qualified Data.ByteString.Lazy as L
>>
>> main = do
>> bytes <- L.readFile "song.gp4"
>> let (version, bytes') = getVersion bytes
>> putStrLn version
>>
>> let stuff = runGet (getDocument version) bytes'
>> putStrLn $ show stuff
>
> putStrLn $ show stuff === print stuff
>
>>
>> return ()
>
> Unneeded
>
>>
>> The getVersion and getDocument functions use the Data.Binary.Get monad
>> to decode the byte string into various objects.
>> I tried sprinkling "trace" calls a bit everywhere and I realize they
>> don't always get called at the expected time.
>
> trace prints its first argument when the second is demanded, so to print
> earlier, you can in general add more strictness to your programme, but I'm
> not sure if that makes a difference for Get, since that has no freedom to
> reorder the sequence in which the values are read. So with traces in the
> right places, you should get tracing output while the deserialisation is
> underway automatically.
> Whether in
>
> getSomeObject = do
> foo <- get
> !bar <- trace ("foo is " ++ show foo) get
> let !baz = trace ("bar is " ++ show bar) $ fiddle foo bar
> return $! trace ("baz is " ++ show baz) (wibble baz foo bar)
>
> the bangs make a difference regarding trace output, I don't know.
>
>> Most of them are only
>> called when I reach the "putStrLn $ show stuff" statement.
>> Unfortunately that doesn't help me because I get a
>>
>> *** Exception: too few bytes. Failed reading at byte position 35939
>>
>> before that.
>
> That usually means the file hasn't the correct format, e.g. some size
> (length of list) has been written in little-endian order and is read in
> big-endian, so get tries to read more items than there are.
>
>>
>> Is this happening because I'm using lazy IO to read the file?
>
> Unlikely. What is the file size on disk? If it's larger than 35939 bytes,
> you have an IO problem, but still Data.ByteString.Lazy.readFile wouldn't be
> the first on my list of suspects.
>
>> Is there a way to force the evaluation of these "trace" calls?
>
> Seeing more of the code could help coming up with ideas.
>
>> Are there any other ways to debug this kind of stuff in Haskell?
>>
>
> Break things down into smaller pieces and test those.
> And there's the ghci-debugger, I hear if one has learned to use it, it's
> quite helpful.
>
>>
>> Thanks a lot,
>>
>> Patrick
>
>
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
Message: 3
Date: Tue, 10 Aug 2010 12:08:01 -0700 (PDT)
From: Travis Erdman <[email protected]>
Subject: [Haskell-beginners] Applicative Functors: Rose Trees with an
alternate behavior
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
> The correct implementation of pure looks like this:
>
> pure x = Node x (repeat (pure x))
>
> (Hooray for lazy infinite data structures!) With this definition the
> standard sequenceA works just fine.
Ha, I would never have arrived at that solution in a million years on my own,
but now that you show me, it makes perfect sense!
Following the discussion of ZipLists from
http://learnyouahaskell.com/functors-applicative-functors-and-monoids, my
initial solution attempt was
pure x = Node x (repeat x)
but that doesn't even compile. I had suspected that I needed to make the pure
tree "go down", but I couldn't see how to do it.
OK, some follow-on questions if I may ...
sequenceA [Tree a] now returns Tree [a], as indicated.
Now, I'd also like sequenceA Tree [a] to return [Tree a]. To do that, I need
to
make Tree an instance of Traversable and, hence, Foldable.
Here's my stab at doing that ...
instance Foldable Tree where
foldMap f (Node cargo subtrees) = f cargo `mappend` foldMap (foldMap f)
subtrees
instance Traversable Tree where
traverse f (Node cargo subtrees) = Node <$> f cargo <*> traverse (traverse
f) subtrees
The Foldable code appears to be correct; at least, I can the fold the trees.
"Foldable" also allows the toList Tree a to work as expected.
Given that, I don't really "get" Traversable, and the code here is just my best
guess as to what it should be. But, I think it must not
be correct, because sequenceA Tree [a] is not returning what I think it should
be returning (ie [Tree a]).
Aside from this, what other things can I do with a Traversable Tree? My
intuition suggests I might be able to do Scan's on a tree, say
calculate a cumulative sums Tree from root to leaves (or vice versa). But I've
no idea how to implement that using it's "Traversability".
As of now, I have implemented this up-and-down scanning thusly ...
treeScanDown :: (a -> b -> a) -> a -> Tree b -> Tree a
treeScanDown f x (Node y subtrees) = Node g (fmap (treeScanDown f g) subtrees)
where g = f x y
treeScanUp :: (a -> [a] -> a) -> Tree a -> Tree a
treeScanUp f (Node x []) = Node x []
treeScanUp f (Node x subtrees) = Node (f x (fmap fromNode g)) g
where g = fmap (treeScanUp f) subtrees
thanks again,
travis
------------------------------
Message: 4
Date: Tue, 10 Aug 2010 15:09:07 -0700
From: Peter Schmitz <[email protected]>
Subject: [Haskell-beginners] Re: Trying to statically link Gtk2Hs
application (Windows XP, network drive)
To: Haskell Beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Aug 6, 2010 at 2:36 PM, Peter Schmitz <[email protected]> wrote:
> I am trying to statically link Gtk2Hs applications.
...
For anyone new to using [Haskell + Gtk2Hs + MS Windows], who, like me,
is inclined to try to statically link the Windows binary (as I
described in this thread), I've done some more research and came
across this post:
Re: [Gtk2hs-users] Making a static Windows executable with gtk2hs
http://sourceforge.net/mailarchive/message.php?msg_id=1254152484.4588.632.camel%40localhost
The gist is that, as desirable as it might seem to try to do so, it's
just not a good idea, and things are going to work better overall
relying on the DLLs.
In the past, I had not noticed that
http://sourceforge.net/projects/gtk2hs/ had a mailing list
associated with it. I'm glad I found it.
(and if this "don't statically link Windows Gtk2Hs binaries" advice is
no longer current, please post. Thanks.)
Hope this helps,
-- Peter
(keywords: Haskell Gtk2Hs Gtk+ static statically link linking Windows
binary binaries executable application)
------------------------------
Message: 5
Date: Tue, 10 Aug 2010 22:58:54 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Re: Trying to statically link Gtk2Hs
application (Windows XP, network drive)
To: Peter Schmitz <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
You may want to read
http://gtk-win.sourceforge.net/home/index.php/en/Embedding
In particular, they already have a template you may use when using
NSIS to create an installer.
Cheers!
--
Felipe.
------------------------------
Message: 6
Date: Wed, 11 Aug 2010 04:51:57 +0200
From: Kurt H?usler <[email protected]>
Subject: [Haskell-beginners] Why does this work in a program, but
cause a seg fault in ghci?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hi,
I am going through the OpenGL tutorial 1
(http://www.haskell.org/haskellwiki/OpenGLTutorial1)
The first example program in chapter 2 works if I compile it and run it, but I
don't understand all of it so I am playing with bits of it in ghci. Look what
happens:
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> let myPoints = map (\k -> (sin(2*pi*k/12),cos(2*pi*k/12),0.0)) [1..12]
Prelude> myPoints
[(0.49999999999999994,0.8660254037844387,0.0),(0.8660254037844386,0.5000000000000001,0.0),(1.0,6.123233995736766e-17,0.0),(0.8660254037844388,-Segmentation
fault
Any ideas?
Thanks
------------------------------
Message: 7
Date: Tue, 10 Aug 2010 23:59:28 -0300
From: Sebasti?n E. Peyrott <[email protected]>
Subject: Re: [Haskell-beginners] Why does this work in a program, but
cause a seg fault in ghci?
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
AFAIK, that should never happen. The expression looks sane, too, so I
guess it's a bug in GHCi. 6.10.4 is not the latest stable version of
GHC, so you might want to update it.
On Tue, Aug 10, 2010 at 11:51 PM, Kurt Häusler <[email protected]> wrote:
> Hi,
> I am going through the OpenGL tutorial 1
> (http://www.haskell.org/haskellwiki/OpenGLTutorial1)
>
> The first example program in chapter 2 works if I compile it and run it, but
> I don't understand all of it so I am playing with bits of it in ghci. Look
> what happens:
>
> GHCi, version 6.10.4: http://www.haskell.org/ghc/ Â :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer ... linking ... done.
> Loading package base ... linking ... done.
> Prelude> let myPoints = map (\k -> (sin(2*pi*k/12),cos(2*pi*k/12),0.0))
> [1..12]
> Prelude> myPoints
> [(0.49999999999999994,0.8660254037844387,0.0),(0.8660254037844386,0.5000000000000001,0.0),(1.0,6.123233995736766e-17,0.0),(0.8660254037844388,-Segmentation
> fault
>
> Any ideas?
>
> Thanks_______________________________________________
> 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 26, Issue 23
*****************************************