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. Monadic fixed-point combinator. (Lyndon Maydwell)
2. Re: Monadic fixed-point combinator. (Edward Z. Yang)
3. Re: Re: Trying to statically link Gtk2Hs application
(Windows XP, network drive) (Peter Schmitz)
4. Re: FastCGI error (Dmitry Simonchik)
5. Re: ghci access to .hs functions (Brent Yorgey)
6. Re: ghci access to .hs functions (prad)
7. Re: Re: ghci access to .hs functions (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Thu, 12 Aug 2010 05:33:14 +0800
From: Lyndon Maydwell <[email protected]>
Subject: [Haskell-beginners] Monadic fixed-point combinator.
To: Biginners Haskell Mailinglist <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
Hi beginners.
I've been looking at fixed-point combinators for the purpose of
memoization for a few days recently and was wondering if there is a
nice way to add monadic actions to an implicitly recursive[1]
function. For example: If I have fib defined like so:
> fib :: (Integer -> Integer) -> Integer -> Integer
> fib f 0 = 0
> fib f 1 = 1
> fib f n = f (n-1) + f (n-2)
I can create an inefficient fib' using fix:
> fix :: (a -> a) -> a
> fix f = f (fix f)
>
> fib' :: Integer -> Integer
> fib' = fix fib
Or a memoized fib'' using memoFix and a memoization scheme:
> type MFB a b = (a -> b) -> a -> b
> memoFix :: MFB a b -> MFB a b -> a -> b
> memoFix mem f = let mf = mem (f mf) in mf
>
> integer :: (Int -> b) -> Int -> b
> integer f = (A.listArray (0,200) (L.map f [0..200]) A.!)
>
> fib'' = memoFix integer fib
But would there be a way to add, say, execution tracing using an IO combinator?
> ioFix :: (a -> IO a) -> IO a
> fix f = print "step" >> f (fix f)
I've had a play around with these functions, attempting to lift them
into monadic actions, but I really have no idea how to approach this.
Thanks for your help!
[1] - What do you call the form of a function where recursion is
implemented by a fixed point combinator?
------------------------------
Message: 2
Date: Wed, 11 Aug 2010 17:43:31 -0400
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Monadic fixed-point combinator.
To: Lyndon Maydwell <[email protected]>
Cc: Biginners Haskell Mailinglist <[email protected]>
Message-ID: <1281562947-sup-7...@ezyang>
Content-Type: text/plain; charset=UTF-8
Excerpts from Lyndon Maydwell's message of Wed Aug 11 17:33:14 -0400 2010:
> But would there be a way to add, say, execution tracing using an IO
> combinator?
>
> > ioFix :: (a -> IO a) -> IO a
> > fix f = print "step" >> f (fix f)
>
> I've had a play around with these functions, attempting to lift them
> into monadic actions, but I really have no idea how to approach this.
Hello Lyndon,
You're looking for monadic recursion, described in Levent Erkok's thesis.
Check out:
http://www.haskell.org/haskellwiki/MonadFix
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.5313
Cheers,
Edward
------------------------------
Message: 3
Date: Wed, 11 Aug 2010 15:02:52 -0700
From: Peter Schmitz <[email protected]>
Subject: Re: [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 Tue, Aug 10, 2010 at 6:58 PM, Felipe Lessa <[email protected]> wrote:
> 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.
>
Felipe,
Thanks very much for mentioning this; looks great.
-- Peter
------------------------------
Message: 4
Date: Thu, 12 Aug 2010 10:57:14 +0400
From: Dmitry Simonchik <[email protected]>
Subject: Re: [Haskell-beginners] FastCGI error
To: Wayne R <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
I beleive the problem is in your Apache config as your program seems to be
correct. You can doublecheck it if use plain CGI instead of FastCGI (just
change import and use runCGI) and run the programm from console. You should
see the output.
On Tue, Aug 10, 2010 at 9:35 PM, Wayne R
<[email protected]>wrote:
> 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
> _______________________________________________
> 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/20100812/cdd5a2da/attachment-0001.html
------------------------------
Message: 5
Date: Thu, 12 Aug 2010 09:01:42 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] ghci access to .hs functions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
It's hard to tell just looking at what you have given. Can you show
us the exact contents of your .hs file?
On Wed, Aug 11, 2010 at 01:17:09PM -0700, prad wrote:
> in an effort to figure out type declarations i thought i'd let ghci do
> the work.
>
> so i wrote a program:
>
> import ...
> main = do
> ...
> func1
> func2
>
> now when i load this into ghci i can't to :t func1 etc and get a not in
> scope error
>
> however, if i put a return () onto the end of main:
>
> import ...
> main = do
> ...
> return ()
> func1
> func2
>
> the functions are in scope of ghci and i can find out the types.
>
> so what is happening here? i understand that return is different in
> haskell than in other languages, but i don't understand just what it is
> doing. :(
>
> --
> In friendship,
> prad
>
> ... with you on your journey
> Towards Freedom
> http://www.towardsfreedom.com (website)
> Information, Inspiration, Imagination - truly a site for soaring I's
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 6
Date: Thu, 12 Aug 2010 01:42:58 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: ghci access to .hs functions
To: [email protected]
Message-ID: <20100812014258.52bc3...@gom>
Content-Type: text/plain; charset=US-ASCII
On Thu, 12 Aug 2010 09:01:42 +0100
Brent Yorgey <[email protected]> wrote:
> Can you show
> us the exact contents of your .hs file?
certainly! but now i take it all back! :(
it's working fine without the return().
it compiles main when i :l or when i ghci the file from the command
line.
so now i think i'm delusional. :D :D
anyway, here's some of the code below and i'll ask another question. in
the function:
-- edFil: edits a file with vim
-- edFil :: String -> IO GHC.IO.Exception.ExitCode (not in scope error)
edFil kV = rawSystem "vim" ["+source ~/.vim/ftplugin/html/HTML.vim",kV]
i got the type from ghci, but if i actually put it in i get error:
Not in scope: type constructor or class `GHC.IO.Exception.ExitCode'
if i don't do the type definition that ghci gives me, everything
compiles fine.
so i don't understand the type definition, much less what's happening
here.
======
import System (getArgs)
import System.Cmd (rawSystem)
import Data.List(elemIndices)
import Database.HDBC
import Database.HDBC.PostgreSQL (connectPostgreSQL)
main = do
args <- getArgs
let act = head args
conn <- connectPostgreSQL "host=localhost dbname=lohv user=pradmin"
case act of
"add" -> do
kV1 <- dbDef conn
upDbs conn (fromSql kV1)
return ()
"upd" -> do
upDbs conn (last args)
return ()
"all" -> do
gtKys conn
return ()
_ -> putStrLn "add, upd num, all only!!"
commit conn
disconnect conn
putStrLn "All Done!"
return ()
-- bkS2L: break a string into a list of strings
-- dC char delimiter; oS original string
bkS2L :: (Char -> Bool) -> String -> [String]
bkS2L dC [] = []
bkS2L dC oS = let (h,t) = break dC oS
in h : case t of
[] -> []
_:t -> bkS2L dC t
-- dbDef: adds a default entry to db
dbDef :: (IConnection conn) => conn -> IO SqlValue
dbDef conn = do
run conn "INSERT INTO main DEFAULT VALUES" []
((r:z):zs) <- quickQuery conn "SELECT last_value from
main_key_seq" [] return r
-- edFil: edits a file with vim
-- edFil :: String -> IO GHC.IO.Exception.ExitCode (not in scope
error)
edFil kV = rawSystem "vim" ["+source ~/.vim/ftplugin/html/HTML.vim",kV]
-- gtInx: gets indices for each element of substring in string
gtInx :: (Eq a) => [a] -> [a] -> [(a,[Int])]
gtInx hL nL = map (\x -> (x,elemIndices x hL)) nL
-- gtKys: gets all key values in database
gtKys :: (IConnection conn) => conn -> IO [()]
gtKys conn = do
r <- quickQuery conn "SELECT key from main" []
let kL = concat $ map (map fromSql) r
mapM (mkPag conn) kL
...
=======
there are more functions, but it is all working fine.
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
------------------------------
Message: 7
Date: Thu, 12 Aug 2010 10:50:07 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Re: ghci access to .hs functions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Thu, Aug 12, 2010 at 01:42:58AM -0700, prad wrote:
> On Thu, 12 Aug 2010 09:01:42 +0100
> Brent Yorgey <[email protected]> wrote:
>
> > Can you show
> > us the exact contents of your .hs file?
> certainly! but now i take it all back! :(
> it's working fine without the return().
>
> it compiles main when i :l or when i ghci the file from the command
> line.
>
> so now i think i'm delusional. :D :D
>
> anyway, here's some of the code below and i'll ask another question. in
> the function:
>
> -- edFil: edits a file with vim
> -- edFil :: String -> IO GHC.IO.Exception.ExitCode (not in scope error)
> edFil kV = rawSystem "vim" ["+source ~/.vim/ftplugin/html/HTML.vim",kV]
>
> i got the type from ghci, but if i actually put it in i get error:
> Not in scope: type constructor or class `GHC.IO.Exception.ExitCode'
In order to be able to refer to a type you must import a module which
exports it. However you are free to *use* a type without importing it,
as long as you do not actually refer to it in a type signature. This
is why your code works without the type signature. Just add
import GHC.IO.Exception
and then you will be able to give the type signature
edFil :: String -> ExitCode
-Brent
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 26
*****************************************