Re: [Haskell-cafe] How to make a dock window for xmonad using gtk2hs?
On Wed, Mar 04, 2009 at 10:59:53PM -0500, Brandon S. Allbery KF8NH wrote: On 2009 Mar 4, at 21:40, Magicloud Magiclouds wrote: Could someone give me a sample or something I could learn from? Thanks. (xmobar is open source, you could look through its source) xmobar is not open source. xmobar is FREE software! here's the relevant bits (from Xmobar.hs) setProperties :: Rectangle - Config - Display - Window - [Rectangle] - IO () setProperties r c d w srs = do a1 - internAtom d _NET_WM_STRUT_PARTIALFalse c1 - internAtom d CARDINAL False a2 - internAtom d _NET_WM_WINDOW_TYPE False c2 - internAtom d ATOM False v - internAtom d _NET_WM_WINDOW_TYPE_DOCK False changeProperty32 d w a1 c1 propModeReplace $ map fi $ getStrutValues r (position c) (getRootWindowHeight srs) changeProperty32 d w a2 c2 propModeReplace [fromIntegral v] hope this helps. Best, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to make a dock window for xmonad using gtk2hs?
On Thu, Mar 05, 2009 at 12:50:20PM -0500, Brandon S. Allbery KF8NH wrote: On 2009 Mar 5, at 8:21, Andrea Rossato wrote: xmobar is not open source. xmobar is FREE software! I don't do fundamentalist religion... qualifying as fundamentalism the avoidance of cheap marketing strategies is just a ... cheap marketing strategy. cheers, andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: hs-bibutils-0.1
Hello, I'm happy to announce the first release of hs-bibutils, the Haskell bindings to Chris Putnam's bibutils.[1] Bibutils is a library and a set of bibliographic utilities to interconvert between various bibliography database formats using a common MODS-format XML intermediate. hs-bibutils is meant to provide to citeproc-hs, and indirectly to pandoc, the ability to parse all the bibliographic database formats supported by bibutils. citeproc-hs[2] is a Haskell implementation of the Citation Style Language. It adds to pandoc a Bibtex like citation and bibliographic formatting and generation facility. DOWNLOADS hs-bibutils can be downloaded from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hs-bibutils The project home page can be found here: http://code.haskell.org/hs-bibutils/ INSTALLATION AND KNOWN ISSUES bibutils builds, without installing it, a static library to be used to compile the various converting utilities. But in order to use the library with pandoc (or ghci) it is necessary to create and install a shared object before building and installing hs-bibutils. hs-bibutils provides a patch to the bibutils building scripts to enable the shared object creation and installation. Alternatively a patched version of the latest release of bibutils can be downloaded from the project home page, where all the needed information for the installation are provided: http://code.haskell.org/hs-bibutils/#installation I was able to test the patched building scripts only on a Linux machine with a x86 system. Please report me any success or failure on other systems/architectures. BUG REPORTS To submit bug reports you can either contact me directly or use the citeproc-hs bug tracking system available at the following address: http://code.google.com/p/citeproc-hs/issues Hope you'll enjoy, Andrea Rossato [1] http://www.scripps.edu/~cdputnam/software/bibutils/ [2] http://code.haskell.org/citeproc-hs/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: citeproc-hs-0.2
Hello, I'm happy to announce the release of citeproc-hs-0.2. WHAT'S NEW 1. Added support for citation collapsing options. This fills the last major gap to a usable CSL implementation; 2. added a wrapper around hs-bibutils[1] (disabled by default). By installing hs-bibutils and linking citeproc-hs to it with the '-fbibutils' configuration flag, it is possible to read all the bibliographic databases supported by bibutils[2]; 3. added some haddock API documentation: http://code.haskell.org/citeproc-hs/docs/ 4. simplified and started to document the internals of the library. DOWNLOADS citeproc-hs can be downloaded from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/citeproc-hs ABOUT citeproc-hs is a Haskell implementation of the Citation Style Language. It adds to pandoc, the famous Haskell text processing tool, a Bibtex like citation and bibliographic formatting and generation facility. The Citation Style Language (CSL) is an XML language for specifying citation and bibliographic formatting, similar in principle to BibTeX .bst files or the binary style files in commercial products like Endnote or Reference Manager. CSL is used by Zotero for bibliographic style formatting, and a huge number of CSL styles have been developed by the Zotero community. More information, with installation instructions, can be found here: http://code.haskell.org/citeproc-hs/ Hope you'll enjoy, Andrea Rossato [1] http://code.haskell.org/hs-bibutils/ [2] http://www.scripps.edu/~cdputnam/software/bibutils/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can my type be allowed as return type in FFI?
On Wed, Dec 10, 2008 at 12:30:56PM +, Duncan Coutts wrote: If do recommend reading the FFI spec. It's quite readable and explains a lot of the issues. Getting familiar with the Foreign libraries will help too. The most important bits are understanding ForeignPtr and the Storable class. I would also add the chapter 17 of Real World Haskell. you can read it here: http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html It will guide you through the writing of the bindings to the PCRE library. Very useful and nicely conceived. A good collection of Storable instances that I found very helpful in understanding the subject can be found in the X11 bindings. Hope this helps, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FFI, TH or GHCI, foreign bindings and the linker(s)
For later reference: I created a minimal test case to illustrate the issue and moved to the (hopefully) more appropriate glasgow-haskell-users list: http://www.haskell.org/pipermail/glasgow-haskell-users/2008-December/016312.html cheers, andrea On Sun, Dec 07, 2008 at 07:08:28PM +0100, Andrea Rossato wrote: Hello, I know that this is somehow a recurring question, still the archives have not been helpful for finding a working solution. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] FFI, TH or GHCI, foreign bindings and the linker(s)
Hello, I know that this is somehow a recurring question, still the archives have not been helpful for finding a working solution. I'm writing the bindings[1] to bibutils[2], a set of utilities for converting from and to different bibliographic databases (MODS, bibtex, etc.). bibutilis uses a static library (which is not installed) to build a set of different binaries which are the installed utilities. Suppose I build the library in /tmp/bibutils. If I build the haskell bindings (hs-bibutils) with: runhaskell Setup.lhs configure --extra-include-dirs=/tmp/bibutils/lib --extra-lib-dirs=/tmp/bibutils/lib where libbibutils.a and the header files are located, then I can build a simple test[3] program with ghc --make test.hs and it works perfectly. When I tried to link citeproc-hs to hs-bibutils everything worked fine, too. But when I tried building pandoc, which uses the Template Haskell extension to generate some code at compilation time, I got a linker error when TH started its process: [...] [ 6 of 29] Compiling Text.Pandoc.ODT ( Text/Pandoc/ODT.hs, dist/build/Text/Pandoc/ODT.o ) Loading package ghc-prim ... linking ... done. [...] Loading package template-haskell ... linking ... done. ghc: /tmp/bibutils_3.43/lib/bibutils.o: unknown symbol `fields_add' Loading package hs-bibutils-0.1 ... linking ... ghc: unable to load package `hs-bibutils-0.1' So I went back to the test file with the original bindings. If I try to load it and run it on ghci I get the very same error: Prelude Main main Loading package syb ... linking ... done. Loading package hs-bibutils-0.1 ... linking ... interactive: /tmp/bibutils/lib/bibutils.o: unknown symbol `fields_add' ghc: unable to load package `hs-bibutils-0.1' After searching the we I found this: http://article.gmane.org/gmane.comp.lang.haskell.cafe/23635 which states that GHCi cannot load static libraries (the same can be argued by reading the GHCi docs, indeed). After reading this thread: http://article.gmane.org/gmane.comp.lang.haskell.cafe/40412 I came to know that GHCi and GHC are not using the same linker, and, as far as I understand, TH uses the first one too. So I tried to build a dynamic library. ar -t /tmp/bibutils/lib/libbibutils.a to get the list of objects to link with: gcc -shared -o libbibutils.so *.o after compiling them with the -fPIC flag. But this library is not being loaded because of some undefined symbols: lib/libbibutils.so: undefined reference to `corps' lib/libbibutils.so: undefined reference to `asis' lib/libbibutils.so: undefined reference to `progname' These symbols refer to some variables defined as external entities, for instance: extern char progname[]; these entities are initialized by a stub.c file in the Haskell bindings: http://code.haskell.org/~arossato/hs-bibutils/cbits/stub.c Unfortunately my knowledge of such low level stuff is very very limited and I'm not seeing any way out. Is there one? Thanks, Andrea [1] http://code.haskell.org/~arossato/hs-bibutils/ [2] http://www.scripps.edu/~cdputnam/software/bibutils/ [3] the test.hs file import Text.Bibutils main :: IO () main = do init_globals mods2bibtex bibl - bibl_init param - bibl_initparams mods_in bibtex_out setFormatOpts param [bibout_brackets, bibout_uppercase] setBOM param setVerbose param bibl_read param bibl /tmp/prova.biblio mods_in bibl_write param bibl -bibtex_out return () ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] handles and foreign C functions
Hello, suppose a simple C function like this: void printStuff(FILE *f) { fprintf (f, Hello World\n); } In order to use it I need to import fopen and pass to it a Ptr CFile: foreign import ccall unsafe fopen fopen :: CString - CString - IO (Ptr CFile) foreign import ccall unsafe fclose fclose :: Ptr CFile - IO CInt foreign import ccall unsafe printStuff printStuff :: Ptr CFile - IO () main = withCString tmp.txt $ \cpath - withCString w $ \cmode - do cfile - throwErrnoIfNull fopen: (fopen cpath cmode) printStuff cfile fclose cfile How can I pass to printStuff a stdout FILE pointer? If, for instance, I do: foreign import ccall unsafe stdout c_stdout :: Ptr CFile main = withCString tmp.txt $ \cpath - withCString w $ \cmode - do printStuff c_stdout I get a segmentation fault. What am I missing? TIA Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] handles and foreign C functions
On Wed, Dec 03, 2008 at 07:08:00PM +0300, Bulat Ziganshin wrote: Hello Andrea, Wednesday, December 3, 2008, 5:09:21 PM, you wrote: How can I pass to printStuff a stdout FILE pointer? afair, stdout syntax used to import variables. it was discussed just a day or two ago :) you mean this, I think: foreign import ccall unsafe stdout c_stdout :: Ptr CFile (my fault with the cutpaste of the previous message). This is causing the segmentation fault I was talking about. Thanks, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] handles and foreign C functions
Hello Bulat, On Wed, Dec 03, 2008 at 07:26:39PM +0300, Bulat Ziganshin wrote: either some error in the code (i neevr used this feature) or stdout may be defile by a macro. the second you said: /* C89/C99 say they're macros. Make them happy. */ (from stdio.h) can you try to define function for it: FILE *out() {return stdout;} This does the trick. Thank you once again. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] global variables for foreign C functions
On Mon, Dec 01, 2008 at 05:30:33PM -0800, Judah Jacobson wrote: You can limit the size of that stub file using: foreign import ccall progname progname :: Ptr (Ptr CChar) which lets you access that global variable and write the getters/setters in Haskell rather than C. this solves my problems quite nicely indeed, but I still cannot figure how to write a setter function that actually works. That is to say, after: newCString new_name = poke progname this: putStrLn . show = peekCString = peek progname would return new_name, but the library, which is using progname to produce some debugging messages, doesn't seem to get it correctly: the original bits are gone, but instead of new_name I get some garbage. Thanks to everyone for the interesting and useful hints. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] global variables for foreign C functions
Hello, I'm writing the bindings to a C library which uses, in some functions, global variables. To make it clearer, those functions need a global variable to be defined. A C program using my_function, one of the library functions, would look like: char progname[] = a_program_name; int main( int argc, char *argv[] ) { param p; my_function ( p ) etc. I've been searching the ML, the wiki, the net, etc. without finding some examples on how such things are dealt with in Haskell - is it possible, BTW? If I import those functions without defining the global variable I get a linker error: /usr/lib/mylib.a(cfile.o): In function `my_function': cfile.c:(.text+0x510): undefined reference to `progname' I hope the issue is clear. Any help would be greatly appreciated. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: citeproc-hs, a Haskell implementation of the Citation Style Language designed for Pandoc
Hi Gwern, On Fri, Sep 19, 2008 at 09:01:46PM -0400, Gwern Branwen wrote: Hi Andrea. So I was looking at the README. Does citeproc-hs only support adding refs from a .xml file when one's written in Pandoc markdown? That is, I don't see how I could take a .lhs file and a .bib file and produce one of the Pandoc-supported outputs. In particular, I'd really like to be able to go .lhs - .wiki, with refs; this would let me convert The Monad Reader articles for haskell.org. as far as I remember Pandoc can deal with literate Haskell. Check here: http://groups.google.com/group/pandoc-discuss/t/aaaf768ab730192 for bibtex databases, you can use Bibutils (check the citeproc-hs homepage for a link): bibutils is a set of utilities for converting from/to MODS to/from many different bibliographic databases. As you know, Pandoc has a mediawiki writer, so, you should be able to use extended markdown with referecnes to produce articles for the wiki. Keep in mind that pandoc latex reader doesn't use citeproc-hs (yet, I'd like to add). Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] system in forkIO
On Sun, Sep 14, 2008 at 02:24:23PM -0300, Marco Túlio Gontijo e Silva wrote: and the result of ls only after I press a key. Does getChar blocks the other threads? yes, but you can use forkOS from Control.Concurrent and compile with -threaded. See the relevant documentation for the details. Hope this helps, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: citeproc-hs, a Haskell implementation of the Citation Style Language designed for Pandoc
Hello, I'm happy to announce the first release of citeproc-hs, a Haskell implementation of the Citation Style Language. citeproc-hs adds to Pandoc, the famous Haskell text processing tool, a Bibtex like citation and bibliographic formatting and generation facility. ABOUT The Citation Style Language (CSL) is an XML language for specifying citation and bibliographic formatting, similar in principle to BibTeX .bst files or the binary style files in commercial products like Endnote or Reference Manager. CSL is used by Zotero for bibliographic style formatting, and a huge number of CSL styles have been developed by the Zotero community. There are plans to use CSL in the future release of OpenOffice: http://bibliographic.openoffice.org/ citeproc-hs is a library that exports functions to parse CSL styles and MODS collections, to process lists of citation groups and to format the processed output. The output is a Haskell data type that can be further processed for conversion to any kind of formats (at the present time plain ASCII and the Pandoc native format) citeproc-hs was developed in order to add to Pandoc Bibtex like citations and automatic reference and bibliography generation. More information, with installation instructions, can be found here: http://code.haskell.org/citeproc-hs/ DOWNLOADS citeproc-hs can be downloaded from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/citeproc-hs To get the darcs source run: darcs get http://code.haskell.org/citeproc-hs/ KNOWN ISSUES citeproc-hs is in an early stage of development and the CSL is not complete yet. Specifically, citation collapsing is not implemented, and some formatting options are not working neither. The MODS parser needs some refinement too. BUG REPORTS To submit bug reports you can you the Google code bug tracking system available at the following address: http://code.google.com/p/citeproc-hs/issues CREDITS Bruce D'Arcus, the author of CSL, has been very kind and patient with me when I was trying to understand the CSL schema, and provided me with ideas, comments and suggestions that made it possible to come to something usable. John MacFarlane, the author of Pandoc, has been very supportive of the project and provided a lot of useful feed back, comments and suggestions. Hope you'll enjoy, Andrea Rossato ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Hackage checks
Hi, the Hackage upload script performs some checks on the packages being uploaded. In my case, a library, I need to use the cabal generated Paths_package file to access some locale data stored in a data file directory. This requires to include in hs-source-dirs dist/build/autogen, which doesn't exist in the source tree, since it's generated by cabal in the build process (the inclusion is made necessary by a bug in Cabal-1.2 which doesn't automatically search dist/build/autogen, see [1]). And so Hackage complains: I needed to manually include such an empty directory in the source code archive. Any way out? TIA Andrea [1] http://www.haskell.org/pipermail/libraries/2008-July/010078.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HXT from schema to data model
On Sun, Sep 07, 2008 at 03:35:40PM +0200, Pierre-Edouard Portier wrote: Hi! Is there a way to generate a data model and a set of picklers from an XML (or RelaxNG) Schema using the HXT tool box? not that I'm aware of. There's something for generating a data type and an access interface from DTD. See, in hxt source code: examples/arrows/dtd2hxt/DTDtoHXT.hs nothing for picklers. and nothing from RelaxNG (even the validator is not complete). in HaXml there could be something worth having a look to (that depends on what you are actually search for). I had a similar problem some time ago and was looking for something like that to implement CSL (and XML macro language for citation formatting), but I handed up writing all the needed boilerplate code, for the data type and the pickler deserializer. Anyway, drop a line if you find (or write) something. Cheers, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] hxt and pickler combinations
Hello, I'm using HXT for writing a Citation Style Language (http://xbiblio.sourceforge.net) implementation in Haskell and I'm trying to use the hxt pickler library to parse XML data contained in elements that can be interleaved, that is to say, elements that can appear in any order within other elements. For instance: data stringciao/string int2/int /data or data int2/int stringciao/string /data are both permitted. I'm not able to write picklers able to parse such kind of data. I indeed noticed that this is not possible with interleaved elements, but it is possible with attributes. To make myself hopefully clearer I included some code below. Suppose we have a data structure like: data Term = T Int String deriving ( Show ) If encoded in XML without respecting the ordering (first the Int and then the String), picklers seem to fail. But if I use attributes to store the values, this doesn't happen. In other word, the xp1 pickler (taken from the example below) will fail with such an xml doc: data stringciao/string int2/int /data since it requires the 'int' element to appear before the 'string' element. To test this behaviour, run the code below and see that: - test doc1 xp1 will fail - test doc2 xp1 will succeed while: - test doc3 xp2 will succeed - test doc4 xp2 will succeed What am I getting wrong? It's just a matter of wrong combinator I'm choosing or I'm getting wrong something more fundamental? TIA. Andrea The code: import Text.XML.HXT.Arrow test :: String - PU Term - IO () test t xp = do p - runX ( constA t xread xunpickleVal xp ) putStrLn (show p) data Term = T Int String deriving ( Show ) xp1, xp2 :: PU Term xp1 = xpElem data $ xpWrap (uncurry T, \(T i s) - (i, s)) $ xpPair (xpElem intxpickle) (xpElem string xpText ) xp2 = xpElem data $ xpWrap (uncurry T, \(T i s) - (i, s)) $ xpPair (xpAttr intxpickle) (xpAttr string xpText ) doc1, doc2, doc3, doc4 :: String doc1 = datastringciao/stringint2/int/data doc2 = dataint2/intstringciao/string/data doc3 = data int=\2\ string=\ciao\ / doc4 = data string=\ciao\ int=\4\ / ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hxt and pickler combinations
On Thu, Jun 26, 2008 at 04:11:58PM +0200, Andrea Rossato wrote: Hello, I'm using HXT for writing a Citation Style Language (http://xbiblio.sourceforge.net) implementation in Haskell and I'm trying to use the hxt pickler library to parse XML data contained in elements that can be interleaved, that is to say, elements that can appear in any order within other elements. For instance: data stringciao/string int2/int /data or data int2/int stringciao/string /data are both permitted. I'm not able to write picklers able to parse such kind of data. I indeed noticed that this is not possible with interleaved elements, but it is possible with attributes. Thanks to a suggestion from Uwe (I contacted the HXT authors too, since I thought it could be a non intended behaviour: instead it is, in order to conform to the standard DTD validation), I came up with this solution. I'm leaving it here too, for the archives. This is a pickler that search the element in the contents and match it without regard to the elements' order: xpElem' :: String - PU a - PU a xpElem' name pa = PU { appPickle = ( \ (a, st) - let st' = appPickle pa (a, emptySt) in addCont (XN.mkElement (mkName name) (attributes st') (contents st')) st ) , appUnPickle = \ st - fromMaybe (Nothing, st) (unpickleElement st) , theSchema = scElem name (theSchema pa) } where unpickleElement st = do let t = contents st n - mapM XN.getElemName t case elemIndex name (map qualifiedName n) of Nothing - fail element name does not match Just i - do let cs = XN.getChildren (t !! i) al - XN.getAttrl (t !! i) res - fst . appUnPickle pa $ St {attributes = al, contents = cs} return (Just res, st {contents = take i t ++ drop (i + 1) t}) Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Announce: xmobar-0.8 released!
Hello! I'm very glad to announce the release of Xmobar-0.8. You can grab the source code from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xmobar-0.8 Xmobar is a minimalistic, text based, status bar. It was specifically designed to work with the XMonad Window Manager. Inspired by the Ion3 status bar, it supports similar features, like dynamic color management, output templates, and extensibility through plugins. A precompiled binary is available here: http://code.haskell.org/~arossato/xmobar/xmobar-0.8.bin A recent screen shot can be found here: http://code.haskell.org/~arossato/xmobar/xmobar-0.8.png A screen shot of xmonad and xmobar (my desktop): http://haskell.org/sitewiki/images/a/ae/Arossato-config.png Xmobar depends on X11-1.3.0 and Cabal-1.2 but works both with ghc-6.6.x and ghc-6.8.1. Here you can find a version of the 0.8 source tree that works with Cabal-1.1.x, but will *not* compile with ghc-6.8.1: http://code.haskell.org/~arossato/xmobar/xmobar-0.8-Cabal-1.1-ghc-6.6.tar.gz Some basic documentation is available at the following address: http://code.haskell.org/~arossato/xmobar/ I would like to thank Robert Manea and Spencer Janssen for their help in understanding X and Xlibs. Thanks to Claus Reinke for making me understand existential types (or at least for letting me think I grasp them ;). Xmobar incorporates patches from: Krzysztof Kosciuszkiewicz, Spencer Janssen, Jens Petersen, Dmitry Kurochkin, and Lennart Kolmodin. Hope you will enjoy! Andrea Rossato What's new == There are a lot of changes since the last release: a. Configuration: - removed xPos, yPos, width, height, align, and refresh configuration options; - added position and alignSep configuration options: the first is used to set the position (Top, Bottom or Static; the second to set the characters to be used to separate, in the output template, text that must be aligned to the left, centered, or aligned to the right; (please have look at xmobar.config-sample and the README for more details) b. Plugins: - added a plugin to read Unix named pipe (useful to display XMonad logs); - added a plugin to read from standard input; - a new plugin API makes it possible to write plugins that perform asynchronous actions. The new API is totally backward compatible; c. Output template: - it is now possible to align text in the output template. By default text before a '}' will be align to left, the text in between '}' and '{' will be centered, and the text after a '{' will be align to the right, like: left } centered { right - strings can have also a background color set: fc=red,white%date%fc will display the output of the date command in red with a white background. d. Concurrency: now Xmobar uses Software Transactional Memory and the main window is updated only when needed e. Documentation: I now use Pandoc for the README, this way I have also created an HTML version of. I hope that makes the documentation a bit more accessible: http://code.haskell.org/~arossato/xmobar/ f. The darcs repository has been moved to: http://code.haskell.org/xmobar g. XRandR: since positioning is now done automatically, XRandR should be supported too, even thought support could be buggy due to the fact that I cannot actually test it, since I don't have capable hardware. h. Cabal-1.2 and ghc-6.8.1 support. i. Many other small changes and code cleanup: darcs changes will tell you everything. Configuration Example = This is my ~/.xmobarrc: Config { font = -bitstream-charter-*-r-normal-*-10-*-*-*-*-56-*-* , bgColor = black , fgColor = grey , position = Top , commands = [ Run Weather LIPB [-L,18,-H,27,--normal,green,--high,red,--low,lightblue] 36000 , Run Network eth1 [-L,0,-H,32,--normal,green,--high,red] 10 , Run Cpu [-L,3,-H,50,--normal,green,--high,red] 10 , Run Memory [-t,Mem: usedratio%] 10 , Run Battery [-L,50,-H,75,--high,green,--normal,yellow, --low, red] 10 , Run Swap [] 10 , Run Com uname [-s,-r] 36000 , Run Date %a %b %_d %Y * %H:%M:%S mydate 10 , Run PipeReader /home/andrea/.xmonad-status xlog ] , sepChar = % , alignSep = }{ , template = %xlog% }{ %cpu% | %memory% * %swap% | %eth1% | %LIPB% | fc=orange%mydate%/fc | %battery% } ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] hoogle broken?
On Wed, Nov 07, 2007 at 10:36:05AM +0100, Thomas Schilling wrote: On Tue, 2007-11-06 at 19:20 -0800, Michael Vanier wrote: It looks as if hoogle isn't working. I get 404s whenever I try to do any search on hoogle. Mike Yes, that's because the ghc-docs now have been slightly reorganized. Neil said he's working on it. I'm trying to package ghc-6.8.1 and I'm getting literally crazy in trying to properly build the documentation. The problem is that I do not find any track of something documenting this document reorganization. Can you point me somewhere? Thanks Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tutorial: Curry-Howard Correspondence
On Tue, Oct 16, 2007 at 08:03:52PM -1000, Tim Newsham wrote: A tutorial on the Curry-Howard Correspondence in Haskell: http://www.thenewsh.com/%7Enewsham/formal/curryhoward/ Feedback appreciated. Very clear and useful for me. Thank you for sharing it. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bindings to the xmms_remote API, GList and something more
On Mon, Sep 24, 2007 at 11:00:00AM +0100, Jules Bean wrote: I saw it. In total, four messages from you in this thread. I'm really sorry about that, but it was due to a problem and a misunderstanding with the administrator of my STMP server: at first it appeared the server was dropping my mail, instead the mail was just delayed due to a virus infection affecting one of the clients and overloading the server. I apologize. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bindings to the xmms_remote API, GList and something more
On Fri, Sep 21, 2007 at 09:08:13AM +0200, Andrea Rossato wrote: To make a short story long, I needed some client for the Audacious media player, something I could use to remote control it and, since I'm addicted to Haskell, instead of surfing the web to find a suitable client I surfed the web to find the API documentation. With the FFI, in a matter of half an hour I had the client with all the commands I needed. [...] So far so good, but, since everything was so easy, I thought: Why not packaging a library (and the client) for Hackage? Maybe others may be willing to use it, maybe... Not only I found out that Audacious comes with a command line client named audtool, not even mentioned on their web site, but also that the API I was writing a binding for is deprecated. Forgetting to document such changes and publishing on your project's web site misleading information is harmful to others, as this example shows. I learned quite a lot today, and not only about FFI. Sorry for the noise. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bindings to the xmms_remote API, GList and something more
On Fri, Sep 21, 2007 at 11:44:38AM +0200, Andrea Rossato wrote: I apologize for the noise. The auto-replay is for documentation (who knows, maybe others searching the list archives may find this info useful). I tried to send a couple of messages to inform that the API I was writing a binding for has been (undocumentedly) deprecated. The messages didn't get through, but I nonetheless finished the job. I wanted to try out also the new Cabal-1.2 - that seems to me quite an impressive improvement over 1.1, btw. I planned also a feature-full client, instead there's just a nasty test/harc.hs file. The client will not be written I'm afraid...;-) My FFI experience will be used for other libraries though. Bibutils could be the first one... I'm not even sure if this message will get through. Actually this is the only mailing list I have some problem with... perhaps some filter may be considering my messages as spam. I'd like to have a copy of that filter installed on my system! Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: interaction between OS processes
On Fri, Sep 14, 2007 at 01:55:32AM +, Aaron Denney wrote: On 2007-08-31, Andrea Rossato [EMAIL PROTECTED] wrote: Thanks for your kind attention, but I don't think it's a matter of buffering (I indeed tried playing with hSetBuffering with no results). I'd like to convince you otherwise: Sorry if I came back so late, but I wanted to thank you for taking the time to show me I was making not one, but two errors. Yes indeed, you are right, if I have access to the buffering of both processes I can send messages from one to the other. Now I start grasping something more about buffering and terminals. Thank you. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] bindings to the xmms_remote API, GList and something more
Hi, I think there's a huge flaw in the Haskell design: if you conceive such a powerful and expressive programming language, one that empowers even the most ignorant computer user to write complex applications, instead of sticking to basic shell scripting - the only domain graspable by such stupid pseudo-coders -, well you end up with messages like this one flooding the mailing list you are providing for your users. This is what I call inevitability... To make a short story long, I needed some client for the Audacious media player, something I could use to remote control it and, since I'm addicted to Haskell, instead of surfing the web to find a suitable client I surfed the web to find the API documentation. With the FFI, in a matter of half an hour I had the client with all the commands I needed. (The long introduction was written just to let you know that you'd better not waste too much time with what follows...;-) So far so good, but, since everything was so easy, I thought: Why not packaging a library (and the client) for Hackage? Maybe others may be willing to use it, maybe... And then the problems start, problems due to my basic ignorance of the C language (How comes you dare to import in Haskell functions written in a language you don't even understand? you should replay!). Basically there are two C types I'm having problem with: 1. GList: even though I read the gtk2hs code I do not exactly understand how to create a GList to feed to this function: void xmms_remote_playlist_add(gint session, GList * list); As far as I understand this function takes a session number and a list of files' names. Still I seem not to be able to create a wrapper function around the imported one. 2. what a gchar ** list is? As far as my C goes, it should be an array of strings, right? What should I use on the Haskell side, newArray? void xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue); 3. c2hs v. hsc2hs? Which should I prefer? In c2hs I write {#pointer * GList#}. What is the equivalent in hsc2hs? 4. As I said, I solved my personal problem: I imported enough functions to create the client I needed. Releasing the library is just something I would like to do, to give something back to the Haskell community. So this is something useful if I can provide robust and well designed code. This is a name space question: what is the name of the exported module? Sound.XMMS, Sound.XmmsRemote? Is the some kind of convention I should be referring to? Sorry if I was too long. Moreover I'm asking help I need just to publish a piece of software that is probably useless. Do not waste your time. But if you do, well... thank you, I really appreciate. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bindings to the xmms_remote API, GList and something more
On Fri, Sep 21, 2007 at 09:08:13AM +0200, Andrea Rossato wrote: Hi, I think there's a huge flaw in the Haskell design: I don't know if this is a feature, the fact that most of the times you can find a solution to your problems by yourself, but only after polluting the haskell-cafe mailing list with your question... Basically there are two C types I'm having problem with: 1. GList: even though I read the gtk2hs code I do not exactly understand how to create a GList to feed to this function: void xmms_remote_playlist_add(gint session, GList * list); As far as I understand this function takes a session number and a list of files' names. Still I seem not to be able to create a wrapper function around the imported one. Well I used gtk2hs more carefully and that's the wrapper: foreign import ccall unsafe beepctrl.h xmms_remote_playlist_add c_xmms_remote_playlist_add :: CInt - GList - IO () xmms_remote_playlist_add :: Session - [String] - IO () xmms_remote_playlist_add s fns = do l - mapM newCString fns = toGList c_xmms_remote_playlist_add (fromIntegral s) l -- stolen from gtk2hs #include glib.h {# context lib=glib prefix=g #} {#pointer * GList#} toGList :: [Ptr a] - IO GList toGList pl = makeList nullPtr pl where makeList :: GList - [Ptr a] - IO GList makeList current (x:xs) = do newHead - {#call unsafe list_prepend#} current (castPtr x) makeList newHead xs makeList current [] = return current 2. what a gchar ** list is? As far as my C goes, it should be an array of strings, right? What should I use on the Haskell side, newArray? void xmms_remote_playlist(gint session, gchar ** list, gint num, gboolean enqueue); yes, indeed: foreign import ccall unsafe beepctrl.h xmms_remote_playlist c_xmms_remote_playlist :: CInt - Ptr CString - CInt - {# type gboolean #} - IO () xmms_remote_playlist :: Session - [String] - Bool - IO () xmms_remote_playlist s l b = do la - newArray = mapM newCString l c_xmms_remote_playlist (fromIntegral s) la (fromIntegral $ length l) (fromBool b) The next two question are still waiting for an answer though...;-) 3. c2hs v. hsc2hs? Which should I prefer? In c2hs I write {#pointer * GList#}. What is the equivalent in hsc2hs? 4. As I said, I solved my personal problem: I imported enough functions to create the client I needed. Releasing the library is just something I would like to do, to give something back to the Haskell community. So this is something useful if I can provide robust and well designed code. This is a name space question: what is the name of the exported module? Sound.XMMS, Sound.XmmsRemote? Is the some kind of convention I should be referring to? I apologize for the noise. The auto-replay is for documentation (who knows, maybe others searching the list archives may find this info useful). Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] yi-gtk
On Tue, Sep 18, 2007 at 09:20:44AM +0800, clisper wrote: who knows how to compile yi-gtk? i tried,but it told me mine miss gtk. probably what you need is gtk2hs: http://haskell.org/gtk2hs/ andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: getting crazy with character encoding
On Thu, Sep 13, 2007 at 11:07:03AM +0200, Stephane Bortzmeyer wrote: On Thu, Sep 13, 2007 at 12:23:33AM +, Aaron Denney [EMAIL PROTECTED] wrote a message of 76 lines which said: the characters read and written should correspond to the native environment notions and encodings. These are, under Unix, determined by the locale system. Locales, while fine for things like the language of the error messages or the format to use to display the time, are *not* a good solution for things like file names and file contents. Even on a single Unix machine (without networking), there are *several* users. Using the locale to find out the charset used for a file name won't work if these users use different locales. Yes indeed. And I find it a real mess. And I don't see any way out. Same thing for file contents. The charset used must be marked in the file (XML...) or in the metadata, somehow. Otherwise, there is no way to exchange files or even to change the locale (if I switch from Latin1 to UTF-8, what do my files become?) Ok, you are perfectly right, but we live in an imperfect world and we must come up with a solution. In my case I'm developing this prompt for xmonad and a Chinese user wants directory and file names to be correctly displayed. What else can I do but using locale technologies? This is something I don't know. The code below is not perfect but it works to some extent. Nonetheless, if you have 2 users using an iso-8859-1 locale the first and utf-8 one the second, non ascii characters in file names of the first users will produce invalid character sequences for the second users. The reverse will work, though. I'm still puzzled and still find the thread title appropriate. Thanks for your kind attention. Andrea The locale aware version of the previous code (needs hsc2hs) {-# OPTIONS -fglasgow-exts #-} import Prelude hiding (catch) import System.Process import System.IO import Control.Monad import System.Directory import Foreign import Foreign.C import Data.Char import Control.Exception runProcessWithInput cmd args input = do (pin, pout, perr, ph) - runInteractiveProcess cmd args Nothing Nothing hPutStr pin input hClose pin output - hGetContents pout when (output==output) $ return () hClose pout hClose perr waitForProcess ph return output main = do setupLocale l - fmap lines $ runProcessWithInput /bin/bash [] ls ab*\n l' - mapM fromLocale l l'' - mapM toLocale l' putStrLn (show l') mapM_ putStrLn l'' mapM_ (putStrLn . show . length) l' -- This code comes from John Meacham's HsLocale -- http://repetae.net/john/repos/HsLocale/ toLocale :: String - IO String toLocale s = catch (stringToBytes s = return . map (chr . fromIntegral)) (const $ return invalid character sequence) fromLocale :: String - IO String fromLocale s = bytesToString (map (fromIntegral . ord) s) `catch` \_ - return invalid character sequence stringToBytes :: String - IO [Word8] stringToBytes cs = (withIConv UTF-32 $ \ic - convertRaw ic cs) bytesToString :: [Word8] - IO String bytesToString xs = (withIConv UTF-32 $ \ic - convertRaw ic xs) = return . f where f ('\65279':xs) = xs -- discard byte order marker f xs = xs newtype IConv = IConv (#type intptr_t) deriving(Num,Eq,Show) foreign import ccall unsafe iconv.h iconv_open iconv_open :: Ptr CChar - Ptr CChar - IO IConv foreign import ccall unsafe iconv.h iconv_close iconv_close :: IConv - IO CInt foreign import ccall unsafe iconv.h iconv iconv :: IConv - Ptr (Ptr CChar) - Ptr CSize - Ptr (Ptr CChar) - Ptr CSize - IO CInt withIConv :: String - String - (IConv - IO a) - IO a withIConv to from action = bracket open close action where close ic = throwErrnoIfMinus1_ iconv_close (iconv_close ic) open = throwErrnoIfMinus1 iconv_open iopen iopen = do withCAString to $ \to - do withCAString from $ \from - do iconv_open to from convertRaw :: (Storable a, Storable b) = IConv - [a] - IO [b] convertRaw ic xs = do with (fromIntegral $ sizeOf (head xs) * length xs) $ \inptrSz - do withArray xs $ \arr - do with (castPtr arr) $ \inptr - do allocaBytes (1024) $ \outptr - do with outptr $ \outptrptr - do with 1024 $ \outptrSz - do let outSz = fromIntegral $ sizeOf $ unsafePerformIO (peek outptr) let go = do ret - iconv ic inptr inptrSz (castPtr outptrptr) outptrSz err - getErrno case (ret,err) of (-1,_) | err == e2BIG - do oz - peek outptrSz x - peekArray ((1024 - fromIntegral oz) `div` outSz) (castPtr outptr) poke outptrptr outptr poke outptrSz 1024 y - go return $ x ++ y (-1,_) - throwErrno iconv (_,_) - do oz - peek outptrSz peekArray ((1024
[Haskell-cafe] getting crazy with character encoding
Hi, supposed that, in a Linux system, in an utf-8 locale, you create a file with non ascii characters. For instance: touch abèèè Now, I would expect that the output of a shell command such as ls ab* would be a string/list of 5 chars. Instead I find it to be a list of 8 chars...;-) That is to say, each non ascii character is read as 2 characters, as if the string were an ISO-8859-1 string - the string is actually treated as an ISO-8859-1 string. But when I print it, now it is displayed correctly. I don't understand what's wrong and, this is worse, I don't understand what I should be studying to understand what I'm doing wrong. After reading about character encoding, the way the linux kernel manages file names, I would expect that a file name set in an utf-8 locale should be read by locale aware application as an utf-8 string, and each character a unicode code point which can be represented by a Haskell char. What's wrong with that? Thanks for your kind attention. Andrea Here the code to test my problem. Before creating the file remember to set the LANG environmental variable. Something like: export LANG=en_US.utf8 should be fine. (Check your available locales with locale -a) import System.Process import System.IO import Control.Monad main = do l - fmap lines $ runProcessWithInput /bin/bash [] ls ab* putStrLn (show l) mapM_ putStrLn l mapM_ (putStrLn . show . length) l runProcessWithInput cmd args input = do (pin, pout, perr, ph) - runInteractiveProcess cmd args Nothing Nothing hPutStr pin input hClose pin output - hGetContents pout when (output==output) $ return () hClose pout hClose perr waitForProcess ph return output ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
On Wed, Sep 12, 2007 at 10:53:29AM -0400, Brandon S. Allbery KF8NH wrote: That is expected. The low level filesystem storage doesn't know about character sets, so non-ASCII filenames must be encoded in e.g. UTF-8. 8 characters is therefore correct, and you must do UTF-8 decoding on input because Haskell does not do so automatically. Ahh, now I eventually get it! So, as far as I understand, I'm getting bytes that are automatically translated into an iso-8859-1 string, if I'm correctly reading this old post by Glynn: http://tinyurl.com/2fhl43 And so it's my job to convert it in what I need. Luckily I've just discovered (and now I'm reading) some of John Meacham's code on locale. This is going to be very helpful (unfortunately I don't see Licenses coming with HsLocale, but if I'm reading correctly there is something like this in Riot - and this was BSD3 released). Thanks for your kind attention. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
On Wed, Sep 12, 2007 at 11:16:25AM -0400, Seth Gordon wrote: It appears that in spite of the locale definition, hGetContents is treating each byte as a separate character without translating the multi-byte sequences *from* UTF-8, and then putStrLn sends each of those bytes to standard output without translating the non-ASCII characters *to* UTF-8. So the second line of your program's output is correct...but only by accident. that's it indeed. As I said in the message I've just sent, I've read that the String/CString conversion is automatically done in ISO-8859-1, so èèè, which are 6 bytes in utf-8, are translated into 6 iso-8859-1 characters. What puzzles me is the behavior of putStrLn. Thanks for your time. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: getting crazy with character encoding
On Wed, Sep 12, 2007 at 04:35:50PM +0200, Stephane Bortzmeyer wrote: This is not an Haskell issue but a ls issue. use System.Directory.getDirectoryContents and we'll see. I get the very same output. Thanks for you kind attention. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] getting crazy with character encoding
On Wed, Sep 12, 2007 at 11:40:11AM -0400, Seth Gordon wrote: The Unix utility od can be very helpful in figuring out problems like this. Thanks for pointing me to od, I didn't know it. [*]At least on my computer, I get the same result *even if* I change LANG from en_US.utf8 to C. As far as I understand it is the terminal emulator responsible for translating the bytes to characters. If I run it in a console I get abAAA (sort of) no matter what my LANG is - 8 single 8 -bit characters. Cheers, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] interaction between OS processes
On Sat, Sep 01, 2007 at 09:12:30PM -0400, Albert Y. C. Lai wrote: Andrea Rossato wrote: loop s = do putStrLn s Most likely, the content of s sits in a local buffer and never leaves this process, following most OS conventions and as others point out. Another process waiting for it will deadlock. Most similar process deadlock problems are not specific to Haskell or even relevant to Haskell; they are misunderstandings of the underneath OS. I recommend every Haskell programmer to take an in-depth Unix course. Yes, I knew it was something related to the underneath OS. I'll have to study Unix seriously Thanks you guys for your kind attention. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC-API: a few questions
Hi, I'm trying to acquire some confidence with the GHC-API and I'm having some problems, related to error handling, I seem not be able to solve. Basically there are 3 functions to (interactively) compile/run Haskell expressions: compileExpr, dyCompileExpr and runStmt. The first 2 will return the value of the compiled expression, as a Maybe HValue the first, and a Maybe Dynamic the second, while the third can bind names and report them, or report exceptions. But my problem is related to the first two. I run expressions (string_expression) wrapped around some let x = string_expression in take 2048 (show x) to avoid infinite list or loops. According to the documentation one should be able to control how error messages are dealt with, by manipulation the GHC session's state. One component of the session state, indeed, is the log_action which, by default, prints errors and warnings to the standard error (compiler/main/DynFlags.hs). Now, no matter what I do, I seem not to be able to change the log_action to collect error messages and warnings. In any case everything seem to be printed to standard error. This way I can only collect exceptions raised by the compiler. For instance: Prelude.last: empty list for string_expression = last [] But if my expression raises a type error, this is printed to stderr. Like in the case of string_expression = last which would produce a No instance for (Show ([a] - a)) What am I doing wrong? Thanks for your kind attentions. Andrea ps: there are quite a lot of other questions I'd like to ask about some programming techniques I've seen applied in GHC. For instance, sometime a list of actions is given as a string, to be compiled to a HValue which is written to a IORef. Running those actions is just a matter of reading the IORef (you can see this in compiler/ghci/InteractiveUIhs, when it comes to buffer management. For instance: flushInterpBuffers). I ask to myself: Why? Just to amaze the reader? ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] interaction between OS processes
Hi, there's something I don't get about interaction among OS processes and Haskell handles/channels. Suppose I have a very small program that takes a line and prints it till you write quit: main = do s - getLine case s of quit - putStrLn quitting return () _ - loop s where loop s = do putStrLn s main This is a small interactive process I would like to talk to from another Haskell program, like the following one which, indeed, is just a wrapper around the first. Now, if I write a single line with quit, I get quitting back, otherwise the program doesn't work. I think I need some direction in order to understand how handles work. The same with channels, I'm afraid. Could you please point me in the right direction? Thanks for your kind attention. Andrea The not working code: import Control.Concurrent import System.Process import System.IO main = do c - runInteractiveCommand ./main2 loop c loop c@(i,o,e,p) = do s - getLine hPutStrLn i s hFlush i -- now i is closed, right? s' - hGetLine o putStrLn s' loop c ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Help with a project design
Hi, I'm going to be long, sorry for it. And probably also off topic, a bit at least...;-) I need a way to manage bibliographies, pretty common problem isn't it? I used to use a wiki I developed also for such a task.[1] The wiki was basically based on Bibtex. I thought I could rewrite that bibliographic management system in Haskell, but I've been also following the work of some guys who are trying to develop a style citation language in XML.[2] Since my confidence with Haskell is growing, I though I could try to write an implementation of that Citation Style Language, but now I start hitting my basic lack of computer science education. Such an effort would be useful if I could write a library and release it, which requires a clean architecture and a simple exported API. But, while I can grasp difficult computational concepts like monads or arrows, choosing a given path of development and create that API is probably out of my reach. This is why I'm asking for help. Or, probably better, for directions on how to start acquiring such capacities. The task this library should do is simple: given an xml object (representing a bibliographic reference), render it with rules stored in a different xml object (the citation style). While I think I can find solutions for this problem - the rendering -, what I find difficult is the design of the reference xml objects. Bibliographic entries have different types, which must be rendered differently. These types can be classified into 3 main classes (books, articles, parts of a book) that can be rendered with the same methods. That seems to fit Haskell perfectly. Now, I basically see 2 approaches: 1. create some data structures (most part of them is common) to map different types of bibliographic entries, and create the needed classes with the render methods; 2. keep the xml objects as xml and create an abstract interface to the xml objects to get the data required for rendering and classifying the xml objects. This way I would have to: - create data types to store different types of xml objects (data Book = Book XmlTree, data Artilce, etc.): these data types represent my reference classes; - create a class of 'render'-able types with the render method and define the instances; - create an existential type to set the type of the xml objects with some kind of setType :: XmlTree - ExistentialContainer I think that the first approach is not abstract enough and requires a lot of boilerplate code to translate into a Haskell type a specific type of bibliographic entry. Moreover, this brings me back to Bibtex, that maps each entry type to a set of rendering rules, while xml objects (MODS[3]) have no type (type must be deduced by the presence of given elements). The second one is the one I'm leaning to. But I'm also thinking that probably I should first study a bit the scrap your boilerplate approach ... on the other side I think that I should probably take a path, follow it and see what happens. In other words, I keep on testing the feasibility of different approaches, probably because I did not grasp the problem entirely. And then there is the API, function names, argument disposition, and so on. Is there some material I could read to have some guidelines for such a task? I know that this is some kind of meta question that is not really Haskell specific, even though I would like to have Haskell specific answers...;-) But any kind of suggestion will be appreciated, especially if you can give me directions to materials that, even if not directly connected with my specific problem, can help me in understanding the basic principle of functional programming design. Thanks for your kind attention and sorry for such a long message. Andrea [1] http://uniwakka.sf.net [2] xbiblio.sf.net [3] Metadata Object Description Schema (MODS) http://www.loc.gov/standards/mods/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] arrow question HXT related
Hi, I think this is just a stupid arrow question. Still I cannot find where my mistake is located. Suppose I have a simple xml document I want to process with HXT: root elem sub / risubtext/risub /elem /root After extracting elem I want to duplicate the children trees with the arrow operator () and process them to get each sub element, like I try in treMe2. Below the example code. While I can get each sub element with tryMe and tryMe1, tryMe2 will produce a []. Instead I want something like tryMe3. I think I'm missing something stupid but right now I just feel stupidly blind. Thanks for your help, Andrea import Text.XML.HXT.Arrow xml = rootelemsub /risubtext/risub/elem/root tryMe = runLA arrow [] where arrow = constA xml xread deep (hasName elem) getChildren (hasName risub getChildren getText) tryMe1 = runLA arrow [] where arrow = constA xml xread deep (hasName elem) getChildren (hasName sub withDefault (getChildren getText) ciao) tryMe2 = runLA arrow [] where arrow = constA xml xread deep (hasName elem) getChildren (hasName sub withDefault (getChildren getText) ciao) (hasName risub getChildren getText) tryMe3 = runLA arrow [] where arrow = constA xml xread constA first constA second The output: *test tryMe [text] *test tryMe1 [ciao] *test tryMe2 [] *test tryMe3 [(first,second)] *test ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] arrow question HXT related
On Sat, Aug 11, 2007 at 11:50:19AM +0200, Andrea Rossato wrote: Hi, I think this is just a stupid arrow question. Still I cannot find where my mistake is located. well, it was not an arrow problem but a HXT problem. This new version of tryMe2 does work as expected: tryMe2 = runLA arrow [] where arrow = constA xml xread listA ( deep (hasName elem) (deep (hasName sub) withDefault (getChildren getText) ciao) (deep (hasName risub) getChildren getText) ) Sorry for the noise. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Avoiding boilerplate retrieving GetOpt cmd line args
On Thu, Jul 26, 2007 at 10:25:06PM -0700, Dave Bayer wrote: Ok, I'm writing a command line tool, using System.Console.GetOpt to handle command line arguments. My Flags structure so far is data Flag = Filter String | DateFormat String | DocStart String | DocEnd String ... and I want to write accessor functions that return the strings if specified, otherwise returning a default. The best I've been able to do is I don't know if my reply is going to be helpful to you. This is what I would suggest: why don't you create a data type with label records, and than you store that data type in a IORef and update the IORef. At the end you just read the IORef with your updated data: data Config = { filter :: String , dateFormat :: String , etc ... } Then you create a new IOref with config, and, with getOpt, you update the IOref with modifyIORef. At the very end you read the modified IOref. This way you can have default options to be modified with command line options. I don't know if it is clear, but I adopted this approach in a program I'm writing. A program with 14 command line options. Have a look at this part here (starting from data Opts=): http://gorgias.mine.nu/repos/xmobar/Main.hs This way I can load a configuration file and change some of the options, configured in that file, with the given command line options. I hope this is going to help you. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] [meta] the haskell wiki management
Hi, this is what happened to me recently. Recently I had the opportunity to join the community around XMonad, a project, you should know something about it, led by some well know haskellers. It's a very exiting project, and by joining it you have the opportunity to code with people who know Haskell very well. Moreover those guys are very friendly and willing to help newcomers like me. Thanks to them I came to build up some knowledge about X window programming in Haskell - Robert and Spencer being my two principal mentors. I have this problem of mine, that when I feel grateful to someone I must find a way to get even, and I thought that writing a tutorial for newcomers could be a form of paying back the XMonad community, a subgroup of the Haskell community after all. I though that using the Haskell wiki was appropriate, so I started writing down what I learned thanks to those guys. As you may understand writing a tutorial is time consuming: not only you have to write the code and the code must be possibly clear. But I have also another problem: English is not my mother tongue, I'm sure you know that by now. So, while writing - eventually it took me up to 20 hours of work to finish the tutorial -, I started a new wiki page and updated it as new stuff was written: X Window Programming in Haskell was the page title. Then suddenly, Sunday night, I could not find my page anymore. So I went to recent changes to find out that someone had decided to change the page title to X window programming, right after editing it. Not to remove some of the huge amount of typos, not to rephrase a sentence that a (properly) English speaker could not understand, not to debug some code, not to improve the content. No, just to enforce a rule, written here: http://www.haskell.org/haskellwiki/HaskellWiki:Guidelines A rule that reads: Titles should use sentence-style capitalization (see [1] - wikipedia). Capitalizing more words seems to be only appropriate in larger documents like books. Seems to be only appropriate in larger documents like books. This makes me laugh, really. I got really upset and went to the talk page of the guy who moved the page to ask for an explanation. And I moved the page back to its original title: it was not a tutorial about x window programming, but about x window programming in Haskell. And so I found out these guidelines I was not even aware of. And that people were actually enforcing them. Now, that's fine, it is a wiki after all, and authorship must be forgotten. I didn't have this feeling when I discovered the wiki for the first time. In many tutorial you could and still can find a signature. You know, I'm an academic type of guy: I don't care about copyright at all, but I care a lot about authorship. I know, this is my fault. Now, what happened next? The guy I was upset with decided to change the rules and added this to the guidelines page: When doing a signficant renaming of a page, (i.e., something more than just correcting the case as per the guidelines), use the Discuss this page link to suggest the new title and the reasons why. After a reasonable amount of time, if there are no objections, go ahead and move / rename the page. But five minutes later he also decided that it was time for the new rule to be violated by the rule setter himself, and renamed other tutorials of mine, something I've written a year ago or so, without making any suggestion in the discussion page. You know, changing a wiki page title means breaking all links to that page from other sites. So, changing an old page title, means taking that page off the Net. This is fine with me and my contributions to the Haskell wiki: useless stuff that is better not reading than reading. On the other side, I'm not going to stand such behaviour and I'm not going to write a single word on that wiki anymore. I removed my signature from the x window tutorial. I'm human too, I would add. Nonetheless I do not understand if this is an explicit policy of getting rid of unwanted contributors, like me, or just a stupid way of managing a collective resource like a wiki. Having a group of people in charge of setting, enforcing and violating rules at their will is a nice form of government, that usually pisses people off. And it is very difficult to adopt such an attitude to piss only unwanted people off. You usually end up repelling people you would like to attract too. I believe it is inevitable. This is the only reason I'm writing this. Sorry for such a long useless letter, but I've seen that the Haskell community loves to talk about maintaining itself, and so on. I thought that my 2 cents could be enjoyable too. Regards, Andrea Rossato ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [meta] the haskell wiki management
On Wed, Jul 25, 2007 at 11:14:59AM +0100, Neil Mitchell wrote: You know, changing a wiki page title means breaking all links to that page from other sites. So, changing an old page title, means taking that page off the Net. Not if the redirect is done, certainly wikipedia does this. I must confess I did not know about this redirect stuff, and I apologize for that. I did not want to insinuate that changing the page title was done with the intent of taking that page off the Net, either. I thought it was only an unintended by product of the renaming. Clearly something here has violated the be friendly policy which I think is the most important policy that governs all wiki/IRC/mailing list stuff. If something as simple as a redirect can solve it all, then great. I don't think you are right on this point. I do not think that what happened to me is due to some kind of personal problem. I think that the person I had some problem with, did so because he perceived that in doing so he was improving the wiki. And he is probably right. This is why I addressed the issue openly. I think it's a problem of wiki management. Producing wiki content is a difficult task, not much less than writing good software. It takes time, and you get no public recognition - yes, you can sign the page but the reader doesn't perceive he's using it as it would with a piece of code. In other words, you must be double motivated to write wiki content like a long tutorial. Sometimes you write it for teaching people how to use your software, indeed. You must be very careful with rising the level of entrance with guidelines and other rules. And if you do that, you must be very careful not to use those rules in a way that is perceived as unmotivated. It turned out that one of the rules that was applied to me was wrongly applied. And it was wrongly applied because no attention to the content I was writing had been paid. And I had to invest time to get the problem sorted out. Now, having people messing with the content you are providing, without paying attention to it, just to have it conformed to some stylistic guidelines is just what pisses the author off. Am I right? Why not using this energy to help the author with the content itself. Isn't this *the* wiki way? I'm asking because I invested time in wiki technologies myself. I was the author of a wiki - UniWakka it was called - and I had to face wiki management issues too. I do believe that some kind of style should be imposed by the software itself, without any more guidelines. Some lack of uniformity may be the price to be paid to have a leaving, ever growing wiki. If you want a nice looking web site, well, stay away from wikis. But this is a topic we can discuss if someone has some interest in it. Thanks for your kind attention. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [meta] the haskell wiki management
On Wed, Jul 25, 2007 at 11:14:59AM +0100, Neil Mitchell wrote: You know, changing a wiki page title means breaking all links to that page from other sites. So, changing an old page title, means taking that page off the Net. Not if the redirect is done, certainly wikipedia does this. btw, it should be clear that wiki page titles are URI and as such they should be treated and the relevant RFC should be applied to them. Redirects is not a solution: changing an URI should be avoided as possible. http://www.w3.org/Provider/Style/URI I think that wiki management means taking care of this issue too. All the best, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.6.1: Where is Graphics.SOE ?
On Tue, Jul 17, 2007 at 06:52:43PM +0400, Dmitri O.Kondratiev wrote: I am trying to use Graphics.SOE (that was present at least in GHC 6.4) to go through Simple Graphics examples as described in Pail Hudak book The Haskell School of Expression. Learning functional programming through multimedia. It looks like Graphics.SOE does not anymore exist in GHC 6.6.1. Where one can get it or what to use instead of it? Do I understand right that Graphics library in GHC 6.6.1 is split between OpenGL and GLUT modules? Any tutorials on OpenGL and GLUT modules similar to Paul Hudak Simple Graphics? Hi! as far as I know what you are looking for (Graphics.SOE) is part of HGL. Have a look here: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HGL-3.1 Hope I got it right and that this helps. All the best, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 6.6.1: Where is Graphics.SOE ?
On Wed, Jul 18, 2007 at 03:58:58PM +0400, Dmitri O.Kondratiev wrote: Andrea thanks! I tried to install HGL on Win32 and got this unresolved dependency: HGL-3.1runghc Setup.hs configure Configuring HGL-3.1... configure: Dependency base-any: using base-2.1.1 Setup.hs: cannot satisfy dependency X11-any Any ideas? yes, you need to install the X11 package: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/X11-1.2.2 I must tell you the truth: I don't run Windows (and never did in the last 8 years) and I don't know if/how you can install X11 on it. But since HGL is a simple graphics library, designed to give the programmer access to most interesting parts of the Win32 Graphics Device Interface and X11 library ... I think that runhaskell Setup.hs etc etc should do the job. I tried HGL on linux recently and it worked smoothly without any complain (very fun playing with it, btw). Otherwise try coming back here, I'm sure some else will give you an advise. Hope this helps. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining the community
On Sat, Jul 14, 2007 at 11:24:36AM +0800, Michael T. Richter wrote: I've seen this pattern so often in communities. I've also seen it in management (the supervisor/manager who can do the job better than his underlings -- so he does) or in teaching (the popular teacher gets a heavier courseload, in effect being punished for being good) or in a myriad of other social enterprises. I may be wrong, but I think you do not get the specificity of the Haskell community, that is quite peculiar, I'd say. When I first met Haskell, about a year ago, I started asking to the mailing list but, since I wanted to contribute back, I started also answering, with the results I told you about. I then decided to start using the wiki, possibly a more friendly place: I wrote a(nother) tutorial about monads, intended for beginners. I also wrote something that I hope could be funny and yet give some ideas on monads (it is called Meet Bob The Monadic Lover). The only reaction I received was a couple of Haskell Top Gurus making fun of me in the #haskell IRC channel (they did not know I was reading, probably). As a reaction I just wanted to erase my wiki pages and quit the community. I did only the later, but the tutorial remains unfinished (I was thinking to finish it, but read on). I came back a year later - some weeks ago - because of a renewed interest for Haskell and for some compiling projects I wanted to get involved to. So I started sending patches and writing support code (not to be included in the project I was collaborating too). Another Top Haskeller, instead of reading my code and telling me if it was good or not, started investigating if my using of a given compiler flags was due to library function abuse or not. Probably something a Top Hakseller is supposed to ask to a supposed novice. Now, that reminds me of a typical academic community, where people, just because they have a higher rank than yours, are supposed to check if you are doing things right or wrong. Now, not because they know more, they studied more the topic you are dealing with. No, it's just a matter of ranking. Every member of a faculty or a department knows what I'm talking about. And even I'm doing my academic career in Italy, known to have a very corrupted academic system - I've been abroad and I still have to find an academic system that is not suffering the very same problems of the Italian one: rank and not knowledge matters. Now, I understand why this is affecting the Haskell community: most of the Top Haskell Gurus here are Ph.D students, with very low academic ranks, and it is not a surprise they are sort of taking their sort of revenge here. Or just importing here that kind of academic attitude they live in. This is human, far too human. The problem is that, by doing so, they hurt their community and keep the outsiders outside, like me. Indeed, the fact that I should be used to this kind of shit, it's my job after all, does not mean I'm going to stand it even in a community I may decide not to join. I don't like speaking bad about a community I'm not part of. Still I really wanted to be part of this community. All the best Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining the community
On Sun, Jul 15, 2007 at 07:05:53PM +1000, Donald Bruce Stewart wrote: So how would you think we can approve? We have to help in more specific ways, and listen more carefully to what people are asking? I usually do this when I want a newcomer to join my community (for instance my research community): I study him, I read his stuff, I try to get to know him, so that I can find for him a place that can suit his needs, feed his curiosity, and help him improve while maximizing his contribution to the community. I treat him as she were my fellow researcher, and not a student I'm supposed to teach to. Just an example: I find it so much irritating when you give a paper to someone and, before even reading it, the receiver starts asking you if you have already read the just published papers of authors x and y about a topic that could slightly resemble the one of your paper (even if actually does not)? This a the kind of behaviour I always try to avoid with new comers. I suppose they know more then me, even if in different area of knowledge. We are all experts of almost nothing. But I'm talking about a small research community, with one or two new members a year. I have no experience in managing such a large community as this one. I just thought that the fact that I felt repelled by the behaviour of some of the members of this community, and please believe me when I say that that behaviour was far from being intentionally offensive or even disrespectful in my regards, could be useful for someone that has such a difficult task. All my best wishes. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Finance.Quote.Yahoo 0.1 on hackage
On Fri, Jul 13, 2007 at 09:24:48PM -0700, brad clawsie wrote: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Finance-Quote-Yahoo-0.1 this is a simple module to get stock quote information from yahoo finance, considered alpha quality Hi, cool! I wanted to use it to write a small plugin for xmobar, a text based status bar I'm developing.[1] But, in order to use it I would need to install: 1. SimpleHTTP 2. MssingH (just for join, replace and split?) which in turns requires: a. QuickCheck and hslogger (these are the package I'm muissing at the present time). Too much for a single plugin. I think that removing some of those dependencies would make your package really useful. With all those dependencies it is quicker, for me, to just reimplement it. Sorry if this may sound rude, it is not my intention. I really like your idea and would be willing to use it. Obviously your package is intended for those who already have those packages installed, and probably everyone has them already installed, so please forget my remarks. And take this message as my way to thank you for your contribution. In other words: thanks! All the best, Andrea [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xmobar-0.6 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Finance.Quote.Yahoo 0.1 on hackage
On Sat, Jul 14, 2007 at 10:20:56AM +0200, Andrea Rossato wrote: On Fri, Jul 13, 2007 at 09:24:48PM -0700, brad clawsie wrote: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Finance-Quote-Yahoo-0.1 this is a simple module to get stock quote information from yahoo finance, considered alpha quality Hi, cool! I wanted to use it to write a small plugin for xmobar, a text based status bar I'm developing.[1] But, in order to use it I would need to install: 2. MssingH (just for join, replace and split?) which in turns requires: the attached patch removes the MissingH requirement, the most important I believe. All the best Andrea --- Finance/Quote/Yahoo.hs.orig 2007-07-14 06:18:17.0 +0200 +++ Finance/Quote/Yahoo.hs 2007-07-14 16:15:35.0 +0200 @@ -35,7 +35,6 @@ module Finance.Quote.Yahoo (getQuote,defaultFields, QuoteField,QuoteSymbol,QuoteValue) where import qualified Network.HTTP.Simple as H (httpGet) -import qualified Data.String as S (join,replace,split) import qualified Network.URI as U (parseURI,escapeURIString, isUnescapedInURI) @@ -63,7 +62,7 @@ quoteReq symbols fields = U.escapeURIString U.isUnescapedInURI (baseURI ++ ?s= ++ - (S.join + symbols) ++ f= ++ (concat fields)) + (join_ + symbols) ++ f= ++ (concat fields)) -- | getQuote takes two args - the symbols, and list of the fields you want. -- The return value is a list of lookup lists, one list per symbol requested, @@ -92,7 +91,21 @@ Nothing - return Nothing Just csv - return (Just (map (zip fields) -(map (S.split ,) - (lines (S.replace \r - (S.replace \ csv)) - +(map (split_ ',') + (lines (remove_ '\r' + (remove_ '\' csv)) + +join_ :: [a] - [[a]] - [a] +join_ _ [] = [] +join_ a (s:ss) = s ++ a ++ join_ a ss + +remove_ :: Eq a = a - [a] - [a] +remove_ c = concat . split_ c + +split_ :: Eq a = a - [a] - [[a]] +split_ _ [] = [] +split_ c s = +[f] ++ split_ c (rest ss) +where (f,ss) = (takeWhile (/= c) s, dropWhile (/=c) s) + rest str | str == [] = [] + | otherwise = tail str ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Finance.Quote.Yahoo 0.1 on hackage
On Sat, Jul 14, 2007 at 08:20:04AM -0700, brad clawsie wrote: i'm not sure i understand - you want to rewrite these functions that are already implemented in Data.String? why? this is why hackage exists - so you don't have to rewrite these functions. MissingH is well maintained by an experienced haskell coder and is easily installed from hackage, i don't see using it as an issue. Sorry, I did not want to sound disrespectful towards anyone. I was just someone who wanted to use your package in a project of mine but was discouraged by the number and the nature of the needed dependencies. Please forget my patch and accept my apologies. Andrea BTW: if someone can point me towards a tool that will take care of installing all needed dependencies, keeping my tool chain updated and not messing up my file system in the long run (say 2 to 4 years: I'm using a quite clean slackware gnu/linux distribution installed in 2003 and regularly updated) I'd really appreciate. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] reading existential types
On Mon, Jul 09, 2007 at 09:41:32PM +0100, Claus Reinke wrote: hiding concrete types in existentials sometimes only defers problems instead of solving them, but exposing class interfaces instead of types is a useful way to mitigate that effect. it just so happens that this particular problem, reading an existential type, slightly exceeds that pattern, as 'read' needs to know the hidden type to do its job ('read' does not determine the type from the input form, but uses the type to determine what form.the input should have). a workaround is to try to read all possible types, then hide the type again once a match is found. the main disadvantage of this method is that we need a list of all the types that could possibly be hidden As a follow up, mainly meant to thank you, I wanted to let you know that I adopted this approach in a piece of software I'm writing. It's a status bar for the XMonad Window Manager, the tiling WM written in Haskell.[1] Actually it is a text based status bar that can be used with any WM, but we love XMonad particularly...;-) More information about this status bar can be found here: http://www.haskell.org/pipermail/xmonad/2007-July/001442.html with link to the source code, a screen shot and eve a link to a binary. I obviously credited you for the help and the code![2] One again, thank you. All the best, Andrea [1] http://xmonad.org/ [2] http://gorgias.mine.nu/repos/xmobar/Runnable.hs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maintaining the community
On Fri, Jul 13, 2007 at 12:11:58PM +1000, Donald Bruce Stewart wrote: As we sit here riding the Haskell wave: http://www.cse.unsw.edu.au/~dons/tmp/cafe.png [..] That is, to help people progress from newbie, to intermediate, to expert, and thus ensure the culture is maintained (avoiding `Eternal September'). This graphic[1] sums the main issue up nicely, in my view: http://headrush.typepad.com/photos/uncategorized/buildingausercommunity.jpg I feel somehow in the Nothing area and I feel somehow ashamed for that: I used to ask a lot when I was a newbie, but now I'm not answering very much. I ask some questions sometimes, and that's it. At first, when I was learning, I tried to help others who seemed even more novice then I was, but usually the experts used to jump in, and show, with their wonderfully conceived examples, how basically ridiculous my code was and how many better ways there are to do things. I did not want to sound clever, and, moreover, I was just trying to make my code as simple as clear as I, newbie, I would have wanted to see. Nevertheless it's not very rewarding to publicly face your ignorance at ever single message you dare to send. So you just quit. Now, I'm telling this because I believe that the expert ones are in part responsible for the gap the picture shows. But only when I'll be an expert I'll be able to prove that. In the meanwhile I'd better shut up! ;-) Just my 2 cents. all the best, andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Yet another implementation of cond
On Wed, Jun 27, 2007 at 05:07:54PM -0500, Jon Cast wrote: I discovered this trick the other day, and didn't remember seeing it anywhere as a cond implementation: head $ [ e1 | cond1 ] ++ [ e2 | cond2 ] ++ [ e3 | cond3 ] Cool! Thanks for sharing it. All the best, andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: ANN: Scripting.Lua 0.1
On Tue, Jun 26, 2007 at 07:54:26AM -0500, Maxim Khailo wrote: You have just combined two of my favorite languages! Gracjan Polak wrote: Hi all, I'm pleased to announce the first public release of Scripting.Lua. I quote: this is a really nice news. I'll be trying to use it in project of mine very soon (I'm developing a sort of Ion3 like status bar, which is scriptable through Lua). Please follows Donald's suggestion and upload it on Hackage. All the best. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Plugin Problem - Weirder
On Fri, Jun 22, 2007 at 03:32:19PM +0200, Daniel Fischer wrote: Am Freitag, 22. Juni 2007 04:29 schrieb Donald Bruce Stewart: The file system was down here, sorry. Should be up now. Ah, just unlucky timing. darcs got, installed, all well. I Know I'm probably late, but with the darcs ource I keep getting: [ 6 of 22] Compiling System.Plugins.Consts ( src/System/Plugins/Consts.hs, dist/build/System/Plugins/Consts.o ) src/System/Plugins/Consts.hs:32:60: lexical error in string/character literal at character '\ESC' Am I missing something? thanks, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] runInteractiveProcess leaks memory, runInteractiveCommand does not
Hi, after many test I found out that System.Process.runInteractiveProcess leaks memory while runInteractiveCommand does. The issue of memory leaks related to running external program was raised here: http://www.haskell.org/pipermail/haskell-cafe/2007-June/027234.html and Bryan noted that after a while the process hits a steady state: http://www.haskell.org/pipermail/haskell-cafe/2007-June/027278.html This is true for runInteractiveCommand, but not for runInceractiveProcess, even though, both relay on the same foreign C imported function. I think this is a ghc bug, but before reporting it I'd like to have someone to confirm it. I wrote this code that demonstrate my point. Could you please have a look? Thanks for you kind attention. Andrea here's the code.: module Main where import System.Process import System.Posix.IO import System.IO import Control.Concurrent readOutput rh = do str - hGetLine rh return str runWith c f = do (i,o,e,p) - f c exit - waitForProcess p str - readOutput o putStrLn str cHandles i o e threadDelay $ 10 * 1 runWith c f runRunIntProcess c = do (inp,out,err,p) - runInteractiveProcess c [] Nothing Nothing return (inp,out,err,p) runRunIntCommand c = do (inp,out,err,p) - runInteractiveCommand c return (inp,out,err,p) cHandles i o e = do hClose i hClose o hClose e -- this does not leaks -- this reaches a steady state after a while: --virt --5528 3404 668 S 6.6 0.7 13:07.48 procRunInComm main = runWith date runRunIntProcess -- this keep on growing --10548 8436 676 S 8.6 1.6 13:15.24 procRunInProc main' = runWith date runRunIntCommand ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] memory usage in repeated reading of an external program's output
Hello, I have this very simple program that executes an external program, reads its output and prints it (the program is date). The readings is done with pipes. The problem is that memory usage constantly increases over time. Profiling does not show garbage collection of any sort. File descriptors and handles seem to be properly closed. Still I cannot find out where the problem lays. Can it be related to the fact that runProcess closes the handles so that the write file descriptor of the pipe is left open? using a closeFd w after runProcess gives a Bad fd error. Moreover, fdToHandle converts the fd into a handle, so I presume that closing the second should be enough. And indeed removing or inserting rc - handleToFd rh and closeFd rc doesn't change anything. Thanks for your help. Andrea The code: module Main where import System.Process import System.Posix.IO import System.IO import Control.Concurrent runComLoop :: String - IO () runComLoop command = do (r,w) - createPipe wh - fdToHandle w hSetBuffering wh LineBuffering p - runProcess command [] Nothing Nothing Nothing (Just wh) (Just wh) rh - fdToHandle r str - hGetLine rh rc - handleToFd rh hClose rh closeFd rc -- get and print the status of handles swh - hShow wh srh - hShow rh putStrLn $ show swh putStrLn $ show srh putStrLn str threadDelay $ 10 * 1 runComLoop command main = runComLoop date ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory usage in repeated reading of an external program's output
On Thu, Jun 21, 2007 at 08:18:23AM -0400, Brandon S. Allbery KF8NH wrote: On Jun 21, 2007, at 6:40 , Andrea Rossato wrote: I have this very simple program that executes an external program, reads its output and prints it (the program is date). The readings is done with pipes. The problem is that memory usage constantly increases over time. Profiling does not show garbage collection of any sort. Huh. Thank you; I'd observed that behavior in one of my programs but hadn't sat down to figure out why yet, mostly because I have a workaround: if you cap the heap (+RTS -M...) it *does* do GC. Which makes it sound like something I don't know how to debug. :/ well, I followed Dougal's suggestion and riduced the program into pieces. I'm also testing the difference of runProcess and runInteractiveProcess. The first seems better but I need some more test. In the first case pipes2Handles gets 80.4% alloc. In the second is runRunIntProcess to get 88%. Results are pretty much the same after all. Now I'm going to profile for memory usage: I've seen that some GC happens if you are patient enough. Thanks for your kind attention. Andrea This is the code broken up: module Main where import System.Process import System.Posix.IO import System.IO import Control.Concurrent readOutput rh = do str - hGetLine rh return str mkPipe = do (r,w) - createPipe return (r,w) pipes2Handles r w = do wh - fdToHandle w rh - fdToHandle r return (rh,wh) runRunProcess wh c = do p - runProcess c [] Nothing Nothing Nothing (Just wh) (Just wh) return p closeHandle rh wh = do hClose wh hClose rh runWithRunProcess c = do (r,w) - mkPipe (rh,wh) - pipes2Handles r w p - runRunProcess wh c exit - waitForProcess p str - readOutput rh closeHandle wh rh putStrLn str threadDelay $ 10 * 1 runWithRunProcess c runRunIntProcess c = do (sin,sout,serr,p) - runInteractiveProcess c [] Nothing Nothing return $! (sin,sout,serr,p) cHandles i o e = do hClose i hClose o hClose e runWithRunIntProcess c = do (i,o,e,p) - runRunIntProcess c exit - waitForProcess p str - readOutput o cHandles i o e putStrLn str threadDelay $ 10 * 1 runWithRunIntProcess c main' = runWithRunProcess date main = runWithRunIntProcess date ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Filesystem access
On Thu, Jun 21, 2007 at 09:19:51PM +0100, Andrew Coppin wrote: OK, a few questions... 1. Is there *any* way to determine how large a file is *without* opening it? The only library function I can find to do with file sizes is hFileSize; obviously this only works for files that you have permission to open! System.Posix.Files fileSize 2. Is there any way to discover Windoze-style attributes for files? (Read-only, archive, system, hidden, et al.) The module before, if I understand correctlu. all the best andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Filesystem access
On Thu, Jun 21, 2007 at 09:38:49PM +0100, Andrew Coppin wrote: Andrea Rossato wrote: On Thu, Jun 21, 2007 at 09:19:51PM +0100, Andrew Coppin wrote: 2. Is there any way to discover Windoze-style attributes for files? The module before, if I understand correctlu. No, AFAIK the archive attribute doesn't even exist on POSIX. It's a Windoze-specific thang. is Windoze-style Windows or something that is not windows, such as POSIX? I did not understand correctly, but you were far from being clear. Which is the first step to get hep, btw. sorry for you problems. don't do windows, me. andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory usage in repeated reading of an external program's output
On Thu, Jun 21, 2007 at 01:36:16PM -0700, Bryan O'Sullivan wrote: Andrea Rossato wrote: Still I do not understand you reference to the leak problem. Could you please elaborate a bit? The runProcess function returns a ProcessHandle. If you don't call waitForProcess on that handle, you'll leak those handles. On Unix-like systems, this means you'll accumulate zombie processes and potentially fill your process table, DoSing your machine. ahhh, yes, I found out the hard way. By the way, in the code I'm writing I was waiting for the exit code of the process. I forgot to copy it in the first example, and when I run it...;-) as you can see, the second version already corrected the problem. Thanks for your kind attention. All the best. andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Xlib: problem creating a window with override_redirect set
Hi, I'm trying, without success, to create a window with the attribute override_redirect set to True (this way the window manager should not take care of it). Obviously with Xlib (X11-1.2.2). No meter how I try I seem not to be able to get there. In test1 I try with the correct method (createWindow), but I get an error message: X Error of failed request: BadMatch (invalid parameter attributes) Major opcode of failed request: 1 (X_CreateWindow) Serial number of failed request: 7 Current serial number in output stream: 9 With test2 I can open the window, but I'm not able to set that attribute. Any help would be greatly appreciated. TIA. Andrea the example code: module Main where import Graphics.X11.Xlib import Graphics.X11.Xlib.Misc import Graphics.X11.Xlib.Extras import Control.Concurrent import Data.Bits main = test2 test1 = do dpy - openDisplay let dflt = defaultScreen dpy rootw - rootWindow dpy dflt win - mkWindow dpy (defaultScreenOfDisplay dpy) rootw 0 0 100 100 mapWindow dpy win sync dpy True threadDelay $ 2 * 100 mkWindow dpy scr rw x y h w = do let attrmask = cWOverrideRedirect visual = defaultVisualOfScreen scr attributes - allocaSetWindowAttributes (\s - return $ s ) set_override_redirect attributes True window - createWindow dpy rw x y -- x, y w h -- width, height 1 -- border_width 1 inputOutput visual attrmask attributes putStrLn Done! return window test2 = do dpy - openDisplay let dflt = defaultScreen dpy rootw - rootWindow dpy dflt win - createSimpleWindow dpy rootw 0 0 100 100 1 0x00 0xFF mapWindow dpy win sync dpy True threadDelay $ 2 * 100 wa - getWindowAttributes dpy win allocaXEvent $ \ev - do setEventType ev configureNotify setConfigureEvent ev win win 100 100 20 20 1 win True sendEvent dpy win False cWOverrideRedirect ev --nextEvent dpy ev getEvent ev sync dpy True a - getWindowAttributes dpy win putStrLn $ show (wa_override_redirect a) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Xlib: problem creating a window with override_redirect set
On Sat, Jun 16, 2007 at 07:03:24PM +0200, Andrea Rossato wrote: Hi, I'm trying, without success, to create a window with the attribute override_redirect set to True (this way the window manager should not take care of it). Obviously with Xlib (X11-1.2.2). just for the sake of documentation, this is the solution I've been able to find thans to the help of the guys of the xmonad comunity. thanks for your kind attentions. andrea the bits: module Main where import Graphics.X11.Xlib import Graphics.X11.Xlib.Misc import Control.Concurrent import Data.Bits main = test test = do dpy - openDisplay let dflt = defaultScreen dpy rootw - rootWindow dpy dflt win - mkUnmanagedWindow dpy (defaultScreenOfDisplay dpy) rootw 0 0 100 100 0x00 mapWindow dpy win sync dpy True threadDelay $ 2 * 100 mkUnmanagedWindow dpy scr rw x y h w bgcolor = do let visual = defaultVisualOfScreen scr attrmask = cWBackPixel .|. cWOverrideRedirect window - allocaSetWindowAttributes $ \attributes - do set_background_pixel attributes bgcolor set_override_redirect attributes True createWindow dpy rw x y w h 0 (defaultDepthOfScreen scr) inputOutput visual attrmask attributes return window ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Xlib: problem creating a window with override_redirect set
On Sat, Jun 16, 2007 at 11:39:51PM +0200, Andrea Rossato wrote: On Sat, Jun 16, 2007 at 07:03:24PM +0200, Andrea Rossato wrote: Hi, I'm trying, without success, to create a window with the attribute override_redirect set to True (this way the window manager should not take care of it). Obviously with Xlib (X11-1.2.2). just for the sake of documentation, this is the solution I've been able to find thans to the help of the guys of the xmonad comunity. I was thinking about the quality of the documentation I have left behind. by the way, the bottom line is that I was trying to manipulate a foreign structure (from the Xlib) getting it out of where it belongs with this trick by the means of allocaSetWindowAttributes: attributes - allocaSetWindowAttributes (\s - return $ s ) attributes resulted garbage but the compiler did not complain. the right thing to do is to manipulate it from within the place where it was possible for the two of you to meet: window - allocaSetWindowAttributes $ \attributes - do and do what ever you want to do. I don't know if now it is clearer than before, but hopefully that could be that case for someone searching for xlib and overright_redirect. hopefully. andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More documentation: how to create a Haskell project
On Mon, Oct 30, 2006 at 09:54:08AM +0100, Ketil Malde wrote: How to make cabal projects into distribution-specific (.deb, .rpm, and so on) packages? for slackware you can have a look to this slackBuild script: http://gorgias.mine.nu/repos/slackBuild/hxt/hxt/hxt.SlackBuild regards, andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory, garbage collection and other newbie's issues
Hello! On Sun, Oct 22, 2006 at 12:27:05AM +0400, Bulat Ziganshin wrote: as Udo said, it should be better to evaluate thunks just when they are created, by using proper 'seq' calls. While I understand why you and Udo are right, still it is difficult for me to related this discussion to my code. So I wrote a small example that reproduces my problem, with the hope that this will help me understand your point. This is my specific problem, I believe. There is a StateT monad with a list of string as a state. The list is populated with the lines of a file entered by the user. The user may read some lines of this file or request another one: - lFilename will load a file - sNumber will show a line number. The input file is evaluated at the very beginning (in my case that is forced by the xml parser, as far as I understand) and stored as the state. Now, the state will not be entirely consumed/evaluated by the user, and so it will not become garbage. Am I right? Where should I force evaluation? Is it clear my confusion (sorry for this kind of nasty recursion...;-)? Thanks for your kind attention. Best regards, Andrea here's the code: -- module Main where import Control.Monad.State import IO data Mystate = Mystate {mystate :: [String]} type SL = StateT Mystate IO getState :: SL [String] getState = do s - get return $ mystate s setState ns = modify (\s - s {mystate = ns}) getFile :: String - SL () getFile p = do f - liftIO $ readFile p let lns = lines f -- forces evaluation of lns liftIO $ putStrLn $ Number of lines: ++ show (length lns) setState lns promptLoop showLine :: Int - SL () showLine nr = do s - getState liftIO $ putStrLn $ s !! nr promptLoop promptStr = lFilename [load the file Filename] - sNr [show the line Nr of Filename] - q to quit promptLoop :: SL () promptLoop = do liftIO $ putStrLn promptStr str - liftIO getLine case str of ('l':ss) - getFile ss ('s':nr) - showLine (read nr) ('q':[]) - liftIO $ return () _ - promptLoop main = evalStateT promptLoop $ Mystate [] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory, garbage collection and other newbie's issues
Hello Bullat, first of all, thanks for your lengthy and clear explanation. On Sun, Oct 22, 2006 at 04:08:49PM +0400, Bulat Ziganshin wrote: f a b = let x = a*b y = a+b in x `seq` y `seq` (x,y) this f definition will not evaluate x and y automatically. BUT its returned value is not (x,y). its returned value is x `seq` y `seq` (x,y) and when further computation try to use it in any way, it can't put hands on the pair before it will evaluate x and y values. are you understand? Yes, I do understand. But, as far as I know, seq will just evaluate x and y enough to see if they are not bottom. So, if x and y are a deep data structure, they won't be evaluated entirely, right? That is to say: to get real advantage, you need to build your value sequentially in monad and force evaluation of each step results: main = do let x = f 1 return $! x let y = f 2 return $! y let z = f 3 return $! z let a = T x y z .. ... setState ns = modify (\s - s {mystate = ns}) here you modify state, but don't ensure that string list is evaluated on both levels. well, it will be ok if you ensure evaluation at _each_ call to this function. alternatively, you can force evaluation before assignment by: setState ns = do return $! map length ns modify (\s - s {mystate = ns}) this is the crucial point. You are forcing evaluation with $! map length, I'm doing it with writeFile. I do not see very much difference. That's an ad hoc solution. Since I need to write the state, instead of (needlessly) looking for the length of it's members, I write it...;-) By the way, the problem is not ns, but s, the old state. The new state has been evaluated by the code below (when we display the number of lines). So you need to change your code with: do s - getState modify (\s - s {mystate = ns}) otherwise you are going to have the same space leak as my original code had. In other word, it is possible to have a user who keeps on loading files without looking at any line (in this case getState is never called and so there is no return $! mystate s!). This produces the same as: setState ns = do s - getState -- that does: return $ mystate s liftIO $ writeFile /dev/null s modify (\s - s {mystate = ns}) if StateT is strict monad transformer, this code don't have space leaks. you create thunks in two places, in one place you already evaluate it, and i wrote what to do in second place. Yes, indeed. But just because we forced evaluation in a way that `seq` cannot do. Am I right? Thanks a lot for you patience. You did help me a lot. And this is not the first time. I appreciate. Really. Best regards, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory, garbage collection and other newbie's issues
Hallo Bulat! On Fri, Oct 20, 2006 at 10:21:51PM +0400, Bulat Ziganshin wrote: first, GC don't occurs automatically when you close file. you can help GHC by using performGC from System.Mem. i does it in my own prog I did not get an appreciable improvement with performGC, as you can see from here: http://gorgias.mine.nu/haskell/a.out.withPerformGC.ps But I found a solution: just write the opml state component to a file! At first I decided to write it and reload it: http://gorgias.mine.nu/haskell/a.out.withFileReload.ps But I get a better result by just writing it (to /dev/null or to a real file): http://gorgias.mine.nu/haskell/a.out.withFileWrite.ps This way everything is garbage collected and the graph is what I would expect. Now, this is a good solution since the opml file is generally small (I have a file with 100 subscribed feeds and it is just 46Kbyte) and it stores information on the folder layout, so it must be saved anyway. second, each Char in ghc occupies 12 bytes (!), so each of your files occupies about 5 mb of memory. if you will count the previous problem, the 2 or 3 files can be hels in memory at the same time (just because they was not yet GCd) so memory usage may become, say, 10 mb multiplying this at 2.5 or even 3 factor which i described in previous letter means, say, 30 mb used 30 Mega used for reading a feed is a number that I seem to get. I also prevent the user from opening more then one feed at once. When a new feed is opened, the old feed gets removed, the opml file is written, the old stuff is garbage collected and the new stuff is added. Now, the memory fingerprint of the program is given by the most memory consuming feed. It is running at about 60-65 Mega. Not that bad, compared to the previous situation. Thank you very much for your suggestions. Regards Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory, garbage collection and other newbie's issues
Hallo! Thanks a lot for stopping by. On Sat, Oct 21, 2006 at 06:41:32PM +0200, Udo Stenzel wrote: The correct solution however, is the application of 'seq' at the right places. To understand where these are, perform a simulation of Haskell's reduction strategy on paper. I will definitely try that. 30 Mega used for reading a feed is a number that I seem to get. Depends on what you're doing with the data. If you scan a stream of Chars exactly once, the space requirement per Char is next to irrelevant. If you're keeping lots of Strings around, using PackedStrings will help (and be sure to pack strictly). But I actually suspect, you are running a backtracking parser over your input, so the whole input is read into a String and cannot be disposed of as long as the parser might backtrack. If this is Parsec, you need to remove a redundant 'try'. If it is the Read class, you need to replace it by Parsec or ReadP... No. I'm actually using the ReadDocument module of HXT for reading my input and writeDocument for writing. So, it's parsec, on your side...;-) The application I'm writing is basically a HXT application, with an hscurser gui. If you have some hints on how to make memory consumption go down that would be great. Thanks for your kind attention. Andrea pgp6mLPTDHpCe.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory, garbage collection and other newbie's issues
On Sat, Oct 21, 2006 at 09:09:13PM +0200, Andrea Rossato wrote: So, it's parsec, on your side...;-) I sorry, I was a bit confused when I wrote that. I confused you for another person, obviously. Sorry about that. Andrea pgpx3F8PsFdVW.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] memory, garbage collection and other newbie's issues
On Thu, Oct 19, 2006 at 06:23:35PM +0400, Bulat Ziganshin wrote: Hello Andrea, Wednesday, October 18, 2006, 9:34:28 PM, you wrote: solution? Or just some hints on the kind of problem I'm facing: is it related to strictness/laziness, or it's just that I did not understand a single bit of how garbage collection works in Haskell? i think, the second. unfortunately, i don't know good introduction to the actual GC implementation although i can give you a pair of not-so-friendly references: [...[ shortly speaking, memory allocated by GHC never shrinks. Hello Bulat, well, you gave me a wonderfully clear introduction to Haskell GC, and now I have a better understanding of the output of the various profiling I'm doing. Thank you very much! Still, I cannot understand my specific problem, that is to say, why the function that reads a file retains so much memory. I did some test and the results are puzzling: - I tried reading the feed and directly converting it into the opml chunk to be inserted into the opml component of my StateT monad. The problem becomes far worse. Here the output of a heap profile: http://gorgias.mine.nu/haskell/a.out.feed2opml.ps as you can see, after opening one feed (397868 bytes), closing it, opening another one (410052 bytes), closing it and reopening the first one brings memory consumption to 152 Mega. Using the intermediate datatype (that is to say, reading the feed, transforming it into my datatype and then to the opml tree), reduces the problem: http://gorgias.mine.nu/haskell/a.out.feed2feedNotStrict.ps only 92 Mega of memory consumption for the very same operations. Making the intermediate datatype strict gives almost the same results: http://gorgias.mine.nu/haskell/a.out.feed2feedStrict.ps 98 Mega. Now, I come to believe the file reading is indeed strict, and that my problem could be related to StateT laziness. Does this makes sense? I'm now going to try to implement my opml state as a IORef and use a ReaderT monad to see if something new happens. ps: if your program uses a lot if string, FPS will be a very great. it don;t change the GC behavior, just makes everything 10 times smaller :) yes, but I'm using HXT and this is using normal strings to store xml text nodes. So I could have some improvements with IO but not that much in memory consumption, unless I totally change my implementation. Anyway, even if I could reduce from 152 to 15 mega the memory consumption for reading 2 feeds, I'd be running out of memory, on my laptop, in one day instead that 5 minutes. Anyway I should face the fact that it is not the string implementation in Haskell that is causing the problem. The problem is probably me! Thanks for your kind attention. Regards Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] memory, garbage collection and other newbie's issues
Hi! I'm a newbie and, as a learning experience, I'm writing a feed reader with hscurses and hxt. For the present time the feed reader just reads a Liferea cache but, as you can imagine, I'm running into the usual newbie problems of memory consumption and garbage collection, probably (I'm not sure) related to strictness/laziness. Even though I spent a couple of hours search the mailing list archives, I did not come up with something I can relate to, so I'll try to explain my problem. The feed reader, that should be compatible with Liferea, takes an opml (1.0) file, that stores information on folders and subscribed feeds. It uses it as the major component of the state of a ST monad, after adding some attributes used by the reader UI. The UI, that uses the widget library of hscurses and is derived from the Contact Manager example, will just display this opml file, and every UI event (collapsing/expanding of folders, displaying feeds, tagging, flagging, and so on) is just an XML transformation of this opml state component. So, when the feed reader boots, only the layout of folders and subscribed feeds is presented to the user. When the user selects a feed do be displayed, the cached file containing up to 100 saved posts, is read and transformed into a data type (called Feed, obviously). After that this data type is transformed into an opml (xml) tree, that is inserted as a child in the appropriate place of the opml state component. Moreover the parent element of the opml state component (which holds the original information of the subscribed feed) is edited for adding general feed information (such as last update, feed's attributes, and so on) retrieved by reading the file. When the user collapses the feed, the added opml chunk is deleted from the state component (but not the added information to the parent of this chunk). Now, I would expect that after the opml chunk is deleted all the memory allocated for reading the cached file would be garbage collected. This is not happening, so, every time you open (or reopen) a feed, the used memory of the feed reader increases, and never decreases. After profiling I've seen that the problem is occurring in the function that reads the cached file: loadFeed :: String - IO [Feed] readFeed id = do [a] - runX $ readDocument [(a_validate, v_0)] (cachePath ++ id) return $ runLA toFeed a What this function does is reading the file with: h - openFile ... hGetContents h and applying some XML filters to get the Feed type populated with the needed information. I tried making the function strict with $!. I tried using fps. It doesn't change this behaviour, obviously. Now, I know that this is a typical newbie problem: could you give me some direction on how to debug this problem and possibly find a solution? Or just some hints on the kind of problem I'm facing: is it related to strictness/laziness, or it's just that I did not understand a single bit of how garbage collection works in Haskell? Thanks for your kind attention. If I'll be able to solve this problem probably I'll be also able to share the feed reader (I know that you are not going to answer after reading this;-) regards, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] cutting long strings into lines
Hello! I've been trying for quite some time to find an elegant solution to cut long strings into lines, but the only solution I was able to come up is the following piece of ugly code. Is there a library function for that? What kind of approach would you suggest? Thanks for your kind attention. Andrea Here's the code: -- does the actual job wrapString str = foldr addNL $ rmFirstSpace $ concat $ splitS (getIndx $ indx str) str -- gets the indexes of the spaces within a string indx = findIndices (\x - if x == ' ' then True else False) -- gets the indexes of where to split the string into lines: lines -- must be between 60 and 75 char long getIndx :: [Int] - [Int] getIndx = takeFirst . checkBound . (delete 0) . nub . map (\x - if x 60 x `rem` 60 = 0 x `rem` 70 = 10 then x else 0) -- groups indexes when their distance is too short checkBound = groupBy (\x y - if y - x 10 then True else False) -- takes the first index of a group of indexes takeFirst = map (\(x:xs) - x) -- split a string given a list of indexes splitS _ [] = [] splitS (x:xs) (ls) = [take x ls] : splitS (map (\i - i - x) xs) (drop x ls) splitS _ ls = [ls]:[] -- remove the first space from the begging of a string in a list of strings rmFirstSpace = map (\(x:xs) - if x == ' ' then xs else x:xs) -- used by foldr to fold the list of substrings addNL s s1 = s ++ \n ++ s1 try with putStrLn $ wrapString longString where: longString = The Haskell XML Toolbox (HXT) is a collection of tools for processing XML with Haskell. The core component of the Haskell XML Toolbox is a domain specific language, consisting of a set of combinators, for processing XML trees in a simple and elegant way. The combinator library is based on the concept of arrows. The main component is a validating and namespace aware XML-Parser that supports almost fully the XML 1.0 Standard. Extensions are a validator for RelaxNG and an XPath evaluator. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cutting long strings into lines
On Sat, Sep 30, 2006 at 08:56:24PM +0400, Bulat Ziganshin wrote: i think that your algorithm is too complex. standard algorithm, imho, is to find last space before 80 (or 75) chars margin, split here and then repeat this procedure again. so, one line split may look like splitAt . last . filter (80) . findIndices (==' ') ... Thank you very much for your analysis. I find it extremely helpful. btw, are you seen http://haskell.org/haskellwiki/Simple_unix_tools ? I did not! But I'm studying this page right now. Thanks for mentioning it. Once again, thank you! Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] cutting long strings into lines
On Sat, Sep 30, 2006 at 08:56:24PM +0400, Bulat Ziganshin wrote: splitByLen len_f [] = [] splitByLen len_f xs = y : splitByLen len_f ys where (y,ys) = splitAt (len_f xs) xs ... so, splitByLen len_f should give you that you need, you need only to add checks for some additional conditions (first word in line is more than 80 bytes long, it is a last line) and removing of the extra space on each line I came up with this solution that seem to be fine, to me. I does the checking of those additional conditions: findSplitP at = last . filter (at) . findIndices (==' ') where last [] = at last [x] = x last (_:xs) = last xs wrapLS at [] = [] wrapLS at s = take ln s ++ \n ++ rest where ln = findSplitP at s remain = drop ln s rest = if length remain at then wrapLS at (tail remain) else tail remain then you can use lines/unlines to split it. Thanks for your help. Best regards, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Java or C to Haskell
On Wed, Sep 20, 2006 at 01:31:22AM -0700, Carajillu wrote: I'm trying to write in Haskell a function that in Java would be something like this: char find_match (char[] l1, char[] l2, char e){ //l1 and l2 are not empty int i = 0; while (l2){ char aux = l2[i]; char[n] laux = l2; while(laux){ int j = 0; if(laux[j] = aux) laux[j] = e; j++; } if compare (l1, laux) return aux; else i++; } return ''; } compare function just compares the two lists and return true if they are equal, or false if they are not. I know that this is far too simple. But I'm simple minded: comp [] [] = True comp (x:xs) (y:ys) = if x == y then comp xs ys else False andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Java or C to Haskell
On Wed, Sep 20, 2006 at 01:31:22AM -0700, Carajillu wrote: compare function just compares the two lists and return true if they are equal, or false if they are not. it is really a simple function, but I've been thinking about it a lot of time and I can't get the goal. I forgot, obviously, that lists are an instance of the Eq class... so, this is enough: comp l1 l2 = if l1 == l2 then True else False You never stop learning! andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Java or C to Haskell
On Wed, Sep 20, 2006 at 07:20:23PM +1000, Donald Bruce Stewart wrote: comp l1 l2 = if l1 == l2 then True else False You never stop learning! andrea which you would just write as: comp = (==) and then you'd just use == anyway :) this is why I came to love haskell: it remembers me when I was doing mathematics at the high school. The most challenging stuff, for me, was finding a way to simplifying expressions... It's just an endless chess game. Sending mails to this mailing list, I mean. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 02:51:34AM -0700, Carajillu wrote: Hi, I'm a student and I have to do a program with Haskell. This is the first time I use this languaje, and I'm having problems with the indentation. I want to check if this function is correct, but when I try to make the GHCi interpret it, I get line 18:parse error (possibly incorrect indentation) The function is: ... if x == e then return l2 I did not understand what you are trying to do, anyway the error message is due to the expression above, and not to indentation. The Haskell if constructions is: if ... then ... else, and else cannot be missing. Moreover, return is not a way to return a value. It is a special function that works with the monad class. Actually it is one of the two methods of the monad class, and it inserts a value into a monad. As far as your code goes, I'd suggest you to read some tutorials, like The Gentle Introduction, or Hasekll for C Programmers. Have a look here: http://haskell.org/haskellwiki/Learning_Haskell and here http://haskell.org/haskellwiki/Books_and_tutorials Hope this helps. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 12:54:34PM +0200, Albert Crespi wrote: Thank you very much for your reply! As I said, it is my first experience with Haskell, I have been programming in Java and C for some years, and I find this language very different from them. Anyway I'll try to fix the function with the information that you gave me. Thanks again! You're welcome. By the way, this is what the comments say you are trying to do: -- Replaces a wildcard in a list with the list given as the third argument substitute :: Eq a = a - [a] - [a] - [a] substitute e l1 l2= [c | c - check_elem l1] where check_elem [] = l1 check_elem (x:xs) = if x == e then (l2 ++ xs) else check_elem xs This is the result: *Main substitute 1 [1,2,3] [] [2,3] *Main substitute 1 [1,2,3] [7,8,9] [7,8,9,2,3] *Main Have fun with Haskell. Ciao Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 04:16:55AM -0700, Carajillu wrote: Wow! I'm starting to love this languaje, and the people who uses it!:) You spoke too early. My code had a bug, a huge one... this is the right one: -- Replaces a wildcard in a list with the list given as the third argument substitute :: Eq a = a - [a] - [a] - [a] substitute e l1 l2= [c | c - check_elem l1] where check_elem [] = l1 check_elem (x:xs) = if x == e then (l2 ++ xs) else [x] ++ check_elem xs Ciao, Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 12:25:21PM +0100, Neil Mitchell wrote: Why not: check_elem (x:xs) = if x == e then (l2 ++ xs) else x : check_elem xs Thanks Thank you! Lists are my personal nightmare...;-) Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Problems interpreting
On Mon, Sep 18, 2006 at 12:42:59PM +0100, Jón Fairbairn wrote: And if you do that, you can write it like this: subst e l' = concat . map subst_elem where subst_elem x | x == e = l' | otherwise = [x] Pretty. Just to many keystrokes. This should take two keystrokes less, probably: subst e l [] = [] subst e l (x:xs) = if x == e then l ++ xs else x : subst e l xs ;-) andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 05:42:47AM -0700, Carajillu wrote: Not a good solution, it just substitutes the first occurrence of the item in the list. I'll try the others I did not get this point. You must take Jón's approach with map. andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 02:52:45PM +0200, Andrea Rossato wrote: On Mon, Sep 18, 2006 at 05:42:47AM -0700, Carajillu wrote: Not a good solution, it just substitutes the first occurrence of the item in the list. I'll try the others I did not get this point. You must take Jón's approach with map. or use this line in mine: check_elem (x:xs) = if x == e then l2 ++ check_elem xs else x : check_elem xs that is to say, you must check also the tail after the matched element. andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems interpreting
On Mon, Sep 18, 2006 at 05:35:47AM -0700, Carajillu wrote: I'm testing it and it's working really well. The other solutions are a little complicated for me, but I'm still trying to undestand them. Jón's approach (the last version of his message), usually cleaner and more concise, is called point-free and is quite common in functional programming. It can be a bit confusing to newcomers, though, since part of the function's arguments do not appear explicitly in the expressions' body (as the list to be matched and modified in your example). You can read something more about this style here: http://haskell.org/haskellwiki/Pointfree Hope this helps. Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Problems interpreting
On Mon, Sep 18, 2006 at 04:52:33PM +0400, Bulat Ziganshin wrote: but the goal is not keystrokes itself but easy of understanding. for me, first solution looks rather idiomatic and intuitively understandable. second solution requires more time to got it, but seems easier for novices that are not yet captured higher-level Haskell idioms. I was obviously kidding, as the ;-) should have made clear. ;-) Apart for the bug (I did not understand that all the occurrences should be replaced) I wrote something that was as close as possible to Albert's first attempt. For the rest, I completely agree with you and find the second one a lot easier... Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Problems interpreting
On Mon, Sep 18, 2006 at 11:04:27AM -0400, Lennart Augustsson wrote: Or even shorter: subst e l = concatMap $ \x-if x==e then l else [x] I kinda like the list comprehension version too subst e l1 l2 = [ r | x - l2, r - if x==e then l1 else [x] ] This is the version I first wanted to (try to) implement (improvements thanks to the thread, obviously :-): newtype SF a b = SF { runSF :: [a] - [b] } instance Arrow SF where arr f = SF (map f) SF f SF g = SF (f g) first (SF f) = SF (unzip first f uncurry zip) substitute e l = arr (\x-if x==e then l else [x]) SF concat I was studying Hughes when I read the first mail of this thread. But you can see it yourself... Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] parsing long numbers
Hello! I'm trying to learn parsing and parser combinations in Haskell, using, as usual, Wadler's Monads in Functional Programming as my text book. Everything works fine except for a small but annoying problem related to read. I'm sure it must be something easy, some kind of stupid faq. Still I'm not able to find a way out. I created a simple parser and made it an instance of monad and MonadPlus. I then created iterateP to combine recursive parsers, and filterP to apply some filters. Then I created a function number, to parse numbers. This function returns a string and works fine. But I wanted to have integers back from parsing. So I created a filter, digitS, and a new parser for numbers, number1, that applies recursively digitS and should be returning an Int using read. The problem is that, when I run it with strings containing a number more then 10 digit long, I get unexpected integers back: *Main runP number1 1234567890 and the rest [(1234567890, and the rest)] *Main runP number1 12345678901 and the rest [(-539222987, and the rest)] Obviously if I use Parsec I can parse that number perfectly. So I tried with another approach: number2 recursively applies a filter, digitI, that returns an Int. asNumber is a function that takes a list of single digit integers and returns the corresponding integer. *Main runP number2 12345678901 and the rest [(Just 1234567890, and the rest)] *Main runP number2 12345678901 and the rest [(Just (-539222987), and the rest)] The very same result. Can you please help me understand why I seem not to be able to get the number I'd like to get? As I said, I think I'm missing something that must be pretty obvious, but still I cannot see it! Thanks for your kind attention. Andrea ps: sorry for such a long message. Moreover, here's the code: module Main where import Control.Monad import Data.Char newtype M a = S {unpack :: String - [(a,String)]} instance Monad M where return a = S $ \s - [(a,s)] m = f = S $ \s - [(b,z) | (a,y) - unpack m s, (b,z) - unpack (f a) y] instance MonadPlus M where mzero = S $ \x - [] mplus a b = a `bchoice` b bchoice (S m) (S m1) = S $ \s - case m s of [] - m1 s other - other iterateP m = do { a - m ; b - iterateP m ; return (a:b) } `mplus` return [] filterP p = S (\xs - case xs of [] - [] (x:xs') - if p x then [(x,xs')] else []) number = do { a - filterP isDigit ; b - number ; return (a:b) } `mplus` return [] digitS = do a - filterP isDigit return a number1 :: M Int number1 = do a - iterateP digitS return (read a) -- a different approach maybeAdd a b = do x - a y - b return (x + y) asNumber :: [Int] - Maybe Int asNumber [] = Nothing asNumber (x:[]) = Just x asNumber (x:xs) = Just (x * 10 ^ length xs) `maybeAdd` asNumber xs digitI = do a - filterP isDigit return $ ord a - ord '0' number2 :: M (Maybe Int) number2 = do a - iterateP digitI return $ asNumber a runP (S f) = f ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbied question on IO Monad
Il Tue, Sep 12, 2006 at 08:05:42AM -0400, Sara Kenedy ebbe a scrivere: Hello all, update :: String - String update sss = ... main = do writeFile myFile.txt sss x - callSystem myFile.txt y - openFile result.txt ReadMode zzz - hGetContents y return zzz I know that function main returns IO String, function update returns String. And my purpose is to get the string zzz from main for the value return of function update. But I do not know which way I can do. Did you mean something like this? update :: String - String update sss = Hi! ++ sss main = do writeFile myFile.txt $ update What are you trying to do? x - callSystem myFile.txt y - openFile result.txt ReadMode zzz - hGetContents y return zzz In this case main :: IO String so you will not see any output (quite useless). I'd suggest you to have a look at this tutorial that explain quite well the IO Monad: http://haskell.org/haskellwiki/IO_inside Ciao Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbied question on IO Monad
Il Tue, Sep 12, 2006 at 09:00:19AM -0400, Sara Kenedy ebbe a scrivere: Hello, Maybe what I talk is not clear. I want to take the input string sss of update to use in: writeFile myFile.txt sss of function main and get the value zzz from main to assign for the value return of update. I think I need to change the way to declare two functions to get what I want, but I do not know how. update :: String - String update sss = zzz main = do writeFile myFile.txt sss x - callSystem myFile.txt y - openFile result.txt ReadMode zzz - hGetContents y return zzz S. this is what you are trying to do with this code: 1. open a file and write to it an undefined string called sss 2. binding x with the value of a function name callSystem that takes a string (we do not know what it returns because it's undefined in this piece of code, but it must be a string). 3. open a file, result.txt, read its content and put it in the IO Monad. Instead you would like to insert into the file myFile.txt a string, sss, that is the result of applying a function to the content of result.txt. Am I right? If yes, here some code: update :: String - String update sss = This is the content of result.txt:\n ++ sss main = do y - openFile result.txt ReadMode zzz - hGetContents y writeFile myFile.txt $ update zzz putStrLn Done! return () Ciao Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] haskell toolchain for slackware
Hello! Since there seems to be very little support for haskell in Slackware Linux, I'm putting together a repository with the most useful (for me) hasekll utilities. For the time being there are: 1. ghc-6.4.2 (precompiled binaries packaged for slackware) 2. haddock 3. darsc 4. hscurses 5. HaXml-1.13.2 6. HXT-6.1 with HTTP-20060707 I'm planning to add, very soon, Hugs, hs-plugins and fps-0.7. The repository should be accessible with slapt-get and swaret. I hope dependency checking is working with slapt-get. Here's the repo: http://gorgias.mine.nu/slack/ You can also grab the SlackBuild scripts (I started using Cabal with HaXml, HXT and HTTP) here: http://gorgias.mine.nu/repos/slackBuild/ or darcs get http://gorgias.mine.nu/repos/slackBuild/ I build my stuff in an almost current slack. Ciao Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXml and ghci unresolved symbol
Il Mon, Sep 11, 2006 at 11:30:41AM +0200, Udo Stenzel ebbe a scrivere: Whatever it is, I cannot reproduce any of your problems. I installed HaXml-1.13.2 from source using Cabal, and both ghc -c Xml.hs and ghc --make xml.hs work as expected, even without the -package switch. This is GHC 6.4.1 on Linux. I installed HaXml-1.13.2 from source using Cabal ... Instead I did not!! I followed the instruction on the HaXml web site: ./configure; make; make install... I'm using Linux too. So, first I installed a fresh ghc-6.4.1 and got the same problem. Than I tried installing HaXml using just Cabal: runhaskell Setup.hs configure|build|install and... HaXml started working fine! I went back to ghc-6.4.2 and did the same, with Cabal. And it works perfectly! I don't know what to say... Well, I do know, in fact: first, thank you all, thank you so much for you kind patience and the time you spent to help me. Second, never trust developers' instruction on how to install their software...;-) Thank you once again! Andrea ps: needless to say, even hxml works perfectly now! pgpmNRmgU9wne.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXml and ghci unresolved symbol
Il Sat, Sep 09, 2006 at 05:20:55PM -0400, Mark T.B. Carroll ebbe a scrivere: FWIW I have the same problem - I can't use HaXml with ghci. So it's not just you. (-: Indeed! So I found my first bug in ghc... And now I'll dig into ghc bug reports to see if someone is working on the problem... This is going to be hard, but it's the way you start learning something;-) Thanks for your kind attention. Below the full error messages with the code producing them. Andrea The code below works fine with Hugs: Main :load xml.hs Main main prova Main If I try to compile it with ghc I get this: [11:16:[EMAIL PROTECTED]:~/devel/haskell/xml]$ ghc --make xml.hs -package HaXml -package hxml -o prova Chasing modules from: xml.hs Compiling Main ( xml.hs, xml.o ) Linking ... /usr/local/lib/hxml-0.2/lib/libhxml.a(HaXmlAdapter.o)(.text+0x12c1): In function `spZc_dflt': : undefined reference to `TextziXMLziHaXmlziPretty_zdwelement_infó /usr/local/lib/hxml-0.2/lib/libhxml.a(HaXmlAdapter.o)(.text+0x1435): In function `spZy_dflt': : undefined reference to `TextziXMLziHaXmlziPretty_zdwelement_infó /usr/local/lib/hxml-0.2/lib/libhxml.a(HaXmlAdapter.o)(.rodata+0xa4): undefined reference to `TextziXMLziHaXmlziPretty_zdwelement_closure` /usr/local/lib/hxml-0.2/lib/libhxml.a(HaXmlAdapter.o)(.rodata+0xc4): undefined reference to `TextziXMLziHaXmlziPretty_zdwelement_closure` collect2: ld returned 1 exit status Loading HaXml and hxml in ghci will produce: [11:15:[EMAIL PROTECTED]:~/devel/haskell/xml]$ ghci -package HaXml -package hxml ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.4.2, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \/\/ /_/\/|_| Type :? for help. Loading package base-1.0 ... linking ... done. Loading package Cabal-1.1.4 ... linking ... done. Loading package haskell98-1.0 ... linking ... done. Loading package haskell-src-1.0 ... linking ... done. Loading package HaXml-1.13.1 ... linking ... done. Loading package hxml-0.2 ... linking ... ghc-6.4.2: /usr/local/lib/hxml-0.2/lib/hxml.o: unknown symbol `TextziXMLziHaXmlziTypes_AttValue_con_info` ghc-6.4.2: unable to load package `hxml-0.2' This is the code: module Main where import Text.XML.HaXml import HaXmlAdapter -- from hxml xml = aprova/a doc = xmlParse tmp xml getContent (Document prolog _ (Elem name _ content) _) = content cont = getContent doc showDoc :: [Content] - IO () showDoc [] = return () showDoc (x:xs) = do putStrLn $ showContent x showDoc xs main = showDoc cont ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXml and ghci unresolved symbol
Il Sat, Sep 09, 2006 at 04:34:04AM +0100, Marco André F. de Almeida ebbe a scrivere: I know this will not solve your problem, but just so that you know that with Hugs, you code works without any problems. If you don't want/need to compile the program, I guess one interpreter (Hugs) is as good as the other (GHCi) ;-) Marco Hi Marco! For the time being, that is to say, for learning xml transformation in haskell Hugs is just fine. But I'd like to start working on a project of a command line tool with hscurses that requires xml processing. I'm going to do that mostly as a learning exercise and I'm still in the preliminary phase, looking for libraries and tools. I'd like to start writing real code for the xml part, though. Thanks, Andrea pgpDF5a7eJoav.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXml and ghci unresolved symbol
Il Sun, Sep 10, 2006 at 11:41:45AM +0200, Lemmih ebbe a scrivere: It looks a bit like 'HaXml' has been updated after 'hxml' was built. Try rebuilding 'hxml' against the 'HaXml' you've got installed. No, I installed the together, HaXml first and then hxml In hxml there where a couple of bugs, and no cabal file - AFAIK hxml is not maintained anymore - last release was done in 2002. I put everything in order and compiled it. Works fine in Hugs. Who knows, it could be just me. But! Look at this code, only pure HaXml. The output should be a and works with Hugs: module Main where import Text.XML.HaXml xml = aprova/a doc = xmlParse tmp xml elemName (Document prolog _ (Elem name _ content) _) = name name = elemName doc main = putStrLn name And now: [12:03:[EMAIL PROTECTED]:~/devel/haskell/xml]$ ghc --make xml1.hs -package HaXml -o prova Chasing modules from: xml1.hs Compiling Main ( xml1.hs, xml1.o ) Linking ... [12:03:[EMAIL PROTECTED]:~/devel/haskell/xml]$ ./prova a [12:03:[EMAIL PROTECTED]:~/devel/haskell/xml]$ ghci -package HaXml xml1.hs [logo] Loading package base-1.0 ... linking ... done. Loading package haskell98-1.0 ... linking ... done. Loading package HaXml-1.13.1 ... linking ... done. Skipping Main ( xml1.hs, xml1.o ) Ok, modules loaded: Main. Prelude Main main interactive: xml1.o: unknown symbol `TextziXMLziHaXmlziParse_xmlParse_closure' Prelude Main :quit Leaving GHCi. This is just amazing for a Haskell newbie! Ciao Andrea ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXml and ghci unresolved symbol
Il Sun, Sep 10, 2006 at 01:56:25PM +0200, Udo Stenzel ebbe a scrivere: Hrm, you're accessing a symbol presumably found in a library that isn't loaded. Either GHC cannot find the library, which shouldn't happen if you're using the right package switch, or the .hi file you compiled against is out of synch with the library, which also shouldn't happen, as both were compiled from the same source. - Did you compile and install HaXml from source? If not, was the binary meant for the version of GHC you're using? I installed from source, compiling by myself. - Did you update anything after doing so? Some library, GHC itself, ...? No. Installed HaXml and tried it with this results. - Did you use weird compiler switches (profiling on/off with missing profiling libraries)? No. Just the HaXml default ones. Nothing weird as far as I can see. - Did you move things around after compiling? Broken package database? configure --user with install --global or vice versa? No. Also because that would result in ghc not compiling the code, I think. Instead, the code *gets* compiled by ghc, *but not* loaded by ghci: same code, obviously. - Did you install more than one version of HaXml? Or are remnants of failed installation attempts still in the search path? No, just version 1.13.1. No failed attempts whatsoever. You could try the brute force approach of just exploding the source tree of HaXml right into your project directory and not using the installed package at all. ghc --make should be able to pick up the sources and compile them without further ado. For hxml this might actually be the right thing to do, because it's so small. However, if you didn't mess with the internals of some package, your problem is just weird. I did not mess with anything. I believe my problem is weird, indeed. The solution you describe is feasible, but I'd like to get the general problem solved...;-) Andrea pgpb0bNuRmKlc.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaXml and ghci unresolved symbol
Il Sat, Sep 09, 2006 at 02:17:36PM +0200, Andrea Rossato ebbe a scrivere: probably it's me, but I cannot understand what I'm doing wrong. Thanks to the discussion of this thread I was able to (sort of) isolate the problem and understand why I cannot get hxml (if linked with HaXml) to work with ghci. It seems related to dynamic linking: I created a separated module (Xml.hs) that imports Text.XML.HaXml and parses a xml string. I then created a file (xml.hs) that imports Xml and prints name, defined in Xml.hs. The expected output should be elementTest. Now: if I compile Xml.hs alone it compiles without warnings or errors. But when I try to load Xml.o with ghci I get an unresolved symbol error. If I load in ghci the file xml.hs (that imports Xml.hs), it loads fine, but when I try to evaluate main I get the same unresolved symbol error. If I compile xml.hs, statically linking it to Xml.hs, I get a perfectly working a.out that runs as expected. So, I'm not able to create an object file (dynamically) linked to HaXml. This is the reason why hxml doesn't work with ghc (and ghci) but works perfectly with hugs. hxml works fine if I do not link it to HaXml (that is to say, without using the HaXmlAdapter module). Now, I don't know whether I should contact the HaXml author or submit a bug report to the ghc developers wiki. Can you please help me with this point? And, if you happen to have a second and HaXml installed, can you reproduce my problem? Thank you very much for your kind attention. Below the code with the output of my attempts. Sorry for such a long message. Ciao Andrea Xml.hs: --- module Xml where import Text.XML.HaXml xml = elementTestThis is a test/elementTest doc = xmlParse tmp xml elemName (Document prolog _ (Elem name _ content) _) = name name = elemName doc xml.hs: --- module Main where import Xml main = putStrLn name - Results: $ ghc --make -package HaXml Xml.hs Chasing modules from: Xml.hs Compiling Xml ( Xml.hs, Xml.o ) $ ghci -package HaXml Xml.o [logo] Loading package base-1.0 ... linking ... done. Loading package haskell98-1.0 ... linking ... done. Loading package HaXml-1.13.1 ... linking ... done. Loading object (static) Xml.o ... done final link ... ghc-6.4.2: Xml.o: unknown symbol `TextziXMLziHaXmlziParse_xmlParse_closure' ghc-6.4.2: linking extra libraries/objects failed $ ghci -package HaXml xml.hs [logo] Loading package base-1.0 ... linking ... done. Loading package haskell98-1.0 ... linking ... done. Loading package HaXml-1.13.1 ... linking ... done. Skipping Xml ( ./Xml.hs, ./Xml.o ) Compiling Main ( xml.hs, interpreted ) Ok, modules loaded: Main, Xml. *Main main interactive: ./Xml.o: unknown symbol `TextziXMLziHaXmlziParse_xmlParse_closure' *Main :quit Leaving GHCi. $ ghc --make -package HaXml xml.hs Chasing modules from: xml.hs Skipping Xml ( ./Xml.hs, ./Xml.o ) Compiling Main ( xml.hs, xml.o ) Linking ... $ ./a.out elementTest $ ghci -package HaXml /usr/lib/ghc-6.4.2/HSHaXml.o [logo] Loading package base-1.0 ... linking ... done. Loading package haskell98-1.0 ... linking ... done. Loading package HaXml-1.13.1 ... linking ... done. Loading object (static) /usr/lib/ghc-6.4.2/HSHaXml.o ... done final link ... done Prelude :quit Leaving GHCi. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe