Re: [Haskell-cafe] CouchDB module in Yhc source tree: clarification, and small problems with other packages
Actually few days ago I run into CouchDB and started to prototype a binding using JSON and Curl from hackage. Once the base functionality is supported, I could post it for review. Adam On Aug 21, 2008, at 11:29 AM, Dimitry Golubovsky wrote: Don All, On 8/21/08, Don Stewart [EMAIL PROTECTED] wrote: I think the best result here would be to put a CouchDB binding on hackage. Is anyone in a position to do this? As for myself, honestly, I did not plan to do this at this time as I am busy with other stuff (Yhc Core conversion). I'd be glad to help anyone who is willing to put CouchDB interface on Hackage. I'd like to note though that this may be a bit premature at the moment. CouchDB has been going through significant redevelopment within Apache Incubator (I am not a developer, but just watch silently), and what is available within the Yhc source tree may not work properly with the current CouchDB: it was for 0.7.x while they have 0.8.x in the incubator. So I would wait for graduation of CouchDB from the incubator, or at least checked with its core developers regarding API stability. Besides, the CouchDB interface in question was written only to satisfy the needs of the Yhc Web Service and may be missing some pieces, although it may be good for a starting point. Thank you. -- Dimitry Golubovsky Anywhere on the Web ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ghci vi mode?
If I remember correctly, ghci uses readline framework on Linux/OS X. Is it possible to change ghci editing mode to vi? Thanks, Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A simple beginner question
Example: data SampleType = A | B Int | C String | D -- etc. sampleTypes = [A, B 5, C test] :: [SampleType] How do I find for example element A in the sampleTypes list? Do I have to create e.g.: isA :: SampleType - Bool isA A = True isA _ = False for every constructor and use find? It feels like this is not the quicker method. Thanks, Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: ReviewBoard 0.1 bindings
This package is part of a development tool designed to monitor code changes, analyze dependencies etc. Actually, we are still in process to develop the tool and this binding is the first functional ready package others might be interested in as well. The package contains a basic set of API calls to ReviewBoard server and a small demo app, a command line tool that makes submitting new code review requests as easy as: svn diff | mkrr -r [reviewers] (ReviewBoard does not support darcs) :( For details see haddock documentation. The ReviewBoard project page: http://code.google.com/p/reviewboard/ And the bindings on hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ ReviewBoard-0.1 A thanks to this list for help with this project and help in getting started with Haskell by following many good threads. Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Web server
A great step by step introduction: http://mult.ifario.us/p/wiring-haskell-into-a-fastcgi-web-server On Apr 25, 2008, at 7:28 AM, Cetin Sert wrote: Hi, What is the fastest way to set up a web server that can redirect requests to a haskell application and serve results returned by it? I need to demonstrate a simple visualization tool I have written for analytic tableaux on Monday and need something easy and simple. Best Regards, Cetin Sert ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HTTP and file upload
Thanks for the snippet. Sorry, but my question was somehow mis-formulated. I was looking for a client-side implementation how to upload a file to any server using Haskell (mainly using the Browser module from HTTP package). Going through the Browser.hs source code a little, I and came up with the following implementation and your hpaste helped me to test it. The following code is just a small wrapper around the Browser module that adds support for multipart/form-data content type. It's more or less a prototype but works fine for me. Looking forward to suggestions how to improve it. Be gentle, it's beginner code :) Adam - -- | -- Wrapper around Network.Browser module with -- support for multipart/form-data content type -- - module ReviewBoard.Browser ( formToRequest, FormVar(..), Form(..) ) where import qualified Network.Browser as HB import Network.HTTP import Network.URI import Data.Char import Control.Monad.Writer import System.Random -- | Form to request for typed form variables -- formToRequest :: Form - HB.BrowserAction Request formToRequest (Form m u vs) -- Use multipart/form-data content type when -- the form contains at least one FileUpload variable | or (map isFileUpload vs) = do bnd - HB.ioAction mkBoundary (_, enc) - HB.ioAction $ runWriterT $ multipartUrlEncodeVars bnd vs let body = concat enc return Request { rqMethod=POST , rqHeaders= [ Header HdrContentType $ multipart/form-data; boundary= ++ bnd, Header HdrContentLength (show . length $ body) ] , rqBody= body , rqURI=u } -- Otherwise fall back to Network.Browser | otherwise = return $ HB.formToRequest (HB.Form m u $ map toHVar vs) where -- Convert typed variables to Network.Browser variables toHVar (TextField n v) = (n, v) toHVar (FileUpload n f) = (n, f) toHVar (Checkbox n v) = (n, map toLower $ show v) -- Is file upload isFileUpload (FileUpload _ _) = True isFileUpload _= False -- Create random boundary string mkBoundary = do rand - randomRIO (1000 :: Integer, ) return $ ++ show rand -- | Encode variables, add boundary header and footer -- multipartUrlEncodeVars :: String - [FormVar] - RqsWriter () multipartUrlEncodeVars bnd vs = do mapM (\v - tell [--, bnd, \r\n] encodeVar v) vs tell [--, bnd, --, \r\n] -- | Encode variable based on type -- encodeVar :: FormVar - RqsWriter () encodeVar (TextField n v)= defaultEncVar n v encodeVar (Checkbox n True) = defaultEncVar n true encodeVar (Checkbox n False) = defaultEncVar n false encodeVar (FileUpload n f) = do fc - liftIO $ readFile f tell [ Content-Disposition: form-data; name=\, n, \; filename=\, f, \\r\n , Content-Type: text/plain\r\n -- TODO: add support for different types , \r\n , fc , \r\n] -- | Default encode method for name/value as string -- defaultEncVar :: String - String - RqsWriter () defaultEncVar n v = tell [ Content-Disposition: form-data; name=\, n, \\r\n , \r\n , v , \r\n] -- --- -- Types -- | Request writer -- type RqsWriter a = WriterT [String] IO a -- | Typed form vars -- data FormVar = TextField String String | FileUpload String FilePath | Checkbox String Bool deriving Show -- | And the typed form -- data Form = Form RequestMethod URI [FormVar] On Apr 15, 2008, at 1:38 AM, Adrian Neumann wrote: Yes http://hpaste.org/6990 Am 14.04.2008 um 19:07 schrieb Adam Smyczek: Is form based file upload supported in HTTP module (HTTP-3001.0.4)? Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HTTP and file upload
Is form based file upload supported in HTTP module (HTTP-3001.0.4)? Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Fighting the monad stack, MonadIO
For a small webapi binding I try to implement a session like monad by building a stack including BrowserAction from Network.Browser module as following: newtype RBAction a = RBAction { exec :: ErrorT String (StateT RBState BrowserAction) a } deriving (Functor, Monad, MonadState RBState) I would like the RBAction to implement MonadIO as well, but fight with the liftIO function for hours now, without success. Any idea how the implementation of liftIO could look like? Thanks for help, Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fighting the monad stack, MonadIO
Thanks a lot for all explanations! It looks like 'ioAction' is the key to the solution and if the Browser module did not provide/expose this function, no IO actions could be run inside the BrowserAction monad? If yes, is this a general concept/pattern how to hide functionality of a underlying monad, in this case hide IO entirely? Adam On Apr 10, 2008, at 11:02 AM, Judah Jacobson wrote: On Thu, Apr 10, 2008 at 7:50 AM, Adam Smyczek [EMAIL PROTECTED] wrote: For a small webapi binding I try to implement a session like monad by building a stack including BrowserAction from Network.Browser module as following: newtype RBAction a = RBAction { exec :: ErrorT String (StateT RBState BrowserAction) a } deriving (Functor, Monad, MonadState RBState) I would like the RBAction to implement MonadIO as well, but fight with the liftIO function for hours now, without success. Any idea how the implementation of liftIO could look like? In order to make a stack of monads an instance of MonadIO, you need to be able to run IO actions in the innermost monad (BrowserAction). Ideally, that monad itself would be an instance of MonadIO; maybe the authors of HTTP didn't do so because it would add a dependency on the mtl package (which defines the MonadIO class). Luckily, though, Network.Browser provides ioAction :: IO a - BrowserAction a which is exactly what you need to write the MonadIO instances yourself. -- Solution #1 -- instance MonadIO BrowserAction where liftIO = ioAction Then you can add MonadIO to the deriving clause for RBAction. -- Solution #2 -- instance MonadIO RBAction where liftIO = RBAction . lift . lift . ioAction This pulls IO actions manually through the stack of transformers. It might be better because if the HTTP package ever provided its own instance of MonadIO BrowserAction, that would conflict with #1. Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fighting the monad stack, MonadIO
On Apr 10, 2008, at 12:42 PM, Luke Palmer wrote: On Thu, Apr 10, 2008 at 2:50 PM, Adam Smyczek [EMAIL PROTECTED] wrote: For a small webapi binding I try to implement a session like monad by building a stack including BrowserAction from Network.Browser module as following: newtype RBAction a = RBAction { exec :: ErrorT String (StateT RBState BrowserAction) a } deriving (Functor, Monad, MonadState RBState) I would like the RBAction to implement MonadIO as well, but fight with the liftIO function for hours now, without success. Any idea how the implementation of liftIO could look like? I suspect BrowserAction does not implement MonadIO (lest you could just put MonadIO in the deriving clause). So, that depends on how BrowserAction is implemented. What package is Network.Browser in? It's correct, BrowserAction does not implement MonadIO. This are the small things that confuse beginners like me :) Package http: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HTTP-3001.0.4 Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Network.Browser and getCookies
Thanks for the tip. Turned out to be a server problem. Adam On Mar 17, 2008, at 8:55 AM, Justin Bailey wrote: On Sun, Mar 16, 2008 at 10:21 AM, Adam Smyczek [EMAIL PROTECTED] wrote: Somehow I cannot get cookies from the Response using Network.Browser module (HTTP 3001.0.4). The cookie header part seams to be empty and getCookies returns empty list as well. Network.Browser comes with a built-in HTTP trace facility - I'd first make sure you are getting the HTTP responses you expect. I believe it's setErrHandler and setDebugHandler - use putStrLn to get a trace of HTTP traffic on your console. Justin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Network.Browser and getCookies
Somehow I cannot get cookies from the Response using Network.Browser module (HTTP 3001.0.4). The cookie header part seams to be empty and getCookies returns empty list as well. Any idea how to debug this or does someone have a working example? Thanks, Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Stacking monads - beginner design question
Hi, My application has to manage a data set. I assume the state monad is designed for this. The state changes in functions that: a. perform IO actions and b. return execution status and execution trace (right now I'm using WriteT for this). Is the best solution: 1. to build a monad stack (for example State - Writer - IO) or 2. to use IORef for the data set or 3. something else? Are monad stacks with 3 and more monads common? How could an example implementation look like? What I have for now is: -- Status data Status = OK | FAILED deriving (Show, Read, Enum) -- Example data set manages by state type Config = [String] -- WriterT transformer type OutputWriter = WriterT [String] IO Status -- example execute function execute :: [String] - OutputWriter execute fs = do rs - liftIO loadData fs tell $ map show rs return OK -- run it inside e.g. main (s, os) - runWriterT $ execute files How do I bring a state into this, for example for: execute fs = do ?? conf - get ?? -- get Config from state rs - liftIO loadData conf fs ?? set conf ?? -- change Config and set to state tell new state: tell $ show conf return OK Do I have to use and how do I use StateT in this context: data DataState = StateT Config OutputWriter ?? and how do I run it runStateT . runWriterT? Thanks for help, Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Stacking monads - beginner design question
It works like a charm, thanks a lot Jonathan! Adam On Jan 29, 2008, at 10:26 PM, Jonathan Cast wrote: On 29 Jan 2008, at 9:44 PM, Adam Smyczek wrote: Hi, My application has to manage a data set. I assume the state monad is designed for this. The state changes in functions that: a. perform IO actions and b. return execution status and execution trace (right now I'm using WriteT for this). Is the best solution: 1. to build a monad stack (for example State - Writer - IO) or 2. to use IORef for the data set or 3. something else? Are monad stacks with 3 and more monads common? I'd say they're fairly common, yes; at least, they don't jump out at me as bad style (especially when the monads are fairly orthogonal, as here). How could an example implementation look like? newtype Program alpha = Program { runProgram :: StateT Config (WriterT [String] IO) alpha } deriving (Functor, Monad, MonadWriter, MonadState) What I have for now is: -- Status data Status = OK | FAILED deriving (Show, Read, Enum) -- Example data set manages by state type Config = [String] -- WriterT transformer type OutputWriter = WriterT [String] IO Status -- example execute function execute :: [String] - OutputWriter execute :: [String] - Program Status execute fs = do rs - liftIO loadData fs tell $ map show rs return OK -- run it inside e.g. main (s, os) - runWriterT $ execute files (s', (s, os)) - runWriterT (runStateT (runProgram $ execute files) inputstate) It's a bit tricky, since you have to write it inside-out, but it should only type check if you've got it right :) How do I bring a state into this, for example for: execute fs = do ?? conf - get ?? -- get Config from state Right. rs - liftIO loadData conf fs ?? set conf ?? -- change Config and set to state Right. tell new state: Right. tell $ show conf return OK Do I have to use Depends on what you mean by `have to'. If you don't want to thread the state yourself, and you don't want to use an IORef, you'll need some implementation of a state monad. That will have to be in the form of a monad transformer applied to IO, so the easy answer is `yes'. and how do I use StateT in this context: data DataState = StateT Config OutputWriter ?? This is parenthesized wrong; the output type goes outside the parentheses around WriterT: StateT Config (WriterT [String] IO) Status not StateT Config (WriterT [String] IO Status) and how do I run it runStateT . runWriterT? Other way 'round, as above. HTH jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ErrorT and catchError question
Ups, resend, first response did not make into the list. On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: It's probably a trivial question, but I cannot figure out how to implement the catchError function in: instance MonadError String Shell where throwError = error . (Shell failed: ++) catchError l h = ??? Take a look at Control.Exception.catch for starters. No, did not help and going over the source code of Control.Monad.Error did not help as well. Does someone have other tips for me? Thanks, Adam -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon university KF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ErrorT and catchError question
On Jan 15, 2008, at 7:34 PM, Brandon S. Allbery KF8NH wrote: On Jan 15, 2008, at 22:05 , Adam Smyczek wrote: Ups, resend, first response did not make into the list. On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: It's probably a trivial question, but I cannot figure out how to implement the catchError function in: instance MonadError String Shell where throwError = error . (Shell failed: ++) catchError l h = ??? Take a look at Control.Exception.catch for starters. No, did not help and going over the source code of Control.Monad.Error did not help as well. Does someone have other tips for me? Perhaps you could explain what you're looking for? Your typeclass doesn't tell us anything about the semantics. The type declaration: newtype Loader a = Loader { load :: ErrorT String IO a } deriving (Functor, Monad, MonadIO) instance MonadError String Loader where throwError = error . (Error: ++) l `catchError` h = ??? how do I implement this ??? -- Example usage data Attribute = Attribute { a_name :: Name, a_value :: Value } deriving Show -- Find a required attribute by name and throw an -- exception it if does not exist findRequired :: Name - [Attribute] - Loader Attribute findRequired n as = case find (\a - a_name a == n) as of Just a - return a Nothing - throwError $ Missing required ' ++ n ++ ' attribute! -- I would like to use catchException for -- findOptional and provide default value -- if findRequired fails findOptional :: Name - [Attribute] - Value - Loader Attribute findOptional n as defaultValue = catchError (findRequired n as) (\_ - return $ Attribute n defaultValue) As you probably can see on this code, I'm a haskell newbie and open for all tips how to improve this code. Thanks, Adam -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon university KF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ErrorT and catchError question
On Jan 15, 2008, at 8:07 PM, Jonathan Cast wrote: On 15 Jan 2008, at 7:54 PM, Adam Smyczek wrote: On Jan 15, 2008, at 7:34 PM, Brandon S. Allbery KF8NH wrote: On Jan 15, 2008, at 22:05 , Adam Smyczek wrote: Ups, resend, first response did not make into the list. On Jan 14, 2008, at 9:33 PM, Brandon S. Allbery KF8NH wrote: On Jan 15, 2008, at 0:28 , Adam Smyczek wrote: It's probably a trivial question, but I cannot figure out how to implement the catchError function in: instance MonadError String Shell where throwError = error . (Shell failed: ++) catchError l h = ??? Take a look at Control.Exception.catch for starters. No, did not help and going over the source code of Control.Monad.Error did not help as well. Does someone have other tips for me? Perhaps you could explain what you're looking for? Your typeclass doesn't tell us anything about the semantics. The type declaration: newtype Loader a = Loader { load :: ErrorT String IO a } deriving (Functor, Monad, MonadIO) instance MonadError String Loader where throwError = error . (Error: ++) I don't think this is what you want; you're throwing away the benefit of using ErrorT. You probably want throwError = Loader . throwError l `catchError` h = ??? how do I implement this ??? l `catchError` h = Loader (load l `catchError` load . h) Thanks Jonathan, this is exactly what I was looking for and I got the concept of ErrorT now, I think. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ErrorT and catchError question
Hi, I'm trying to use ErrorT transformer based on Don Stewart's Shell example: http://cgi.cse.unsw.edu.au/~dons/blog/2007/03/10#programmable-semicolons It's probably a trivial question, but I cannot figure out how to implement the catchError function in: instance MonadError String Shell where throwError = error . (Shell failed: ++) catchError l h = ??? Thanks for help, Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Patter matching beginner question
Hi all, I assume the following behavior has a trivial explanation. When I write: case name of a - ... b - ... everything works fine. But when I extract a and b to constants: c_a = a :: String c_b = b :: String case name of c_a - ... c_b - ... I get Patterns match(es) are overlapped. Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe