[Haskell-cafe] JSON Querry examples
Hi, I am trying to search known-in-advance fields in JSON object with unknown structure. It looks like Data.JSON2.Query is most appropriate for this task. Yet, I can not figure out how to use filters this package provides to filter JSON arrays and objects. Are there any end-to-end examples of making queries of unknown JSON objects? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Using Acid-State for IPC?
Hi, I am wondering if Acid-State (http://hackage.haskell.org/package/acid-state) can be used to share data between processes running in different address spaces? For example, one demon system process (not thread!) periodically collects data from Web and stores it in a list. On regular intervals this process checkpoints the list to a disk file. Another independent process randomly starts and reads this list from the checkpoint file. Can this simple scenario be done with Acid-State? Any conflicts accessing checkpoint file from two system processes simultaneously? What other Haskell libs can be used for such a task? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Web Framework to Show Experimental Data
Hi! I am looking for the Haskell libraries to quickly create some Web Framework to Show Experimental Data. Please share your experience and ideas. What tools would you chose for such a framework: == Architecture There are several unsynchronized processes: 1) Finder - demon that periodically searches and collects JSON data from the Web and stores this data in some sort of Archive (DB). 2) Processor - demon that periodically process new data from Archive collected by Finder and stores results of its work in the same Archive. 3) Web application that shows processed data in a browser. == General Requirements *** Main requirement - simplicity and high speed of development *** - Max Data storage capacity - 10 Mb - Max number of Web users - 50 - Web UI shows what Archive has at the moment of user request. == Web UI Requirements - Multi-page view of long data sets (some sort of scrolling) - Simple graphs and charts (desirable) == Questions 1) What to use for the Archive? Though input data is in JSON format, data generated from it is binary vectors. Not sure that CouchDB is a good choice in this case. What simple (Haskell lib + DB) combination one may advise that support concurrent read / write access with simple locking (don't need full transactional support)? 2) Web framework? Don't need AJAX, just basic stuff but simple and easy to code forms? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web Framework to Show Experimental Data
Chris, thank you so much for pointing me into the right direction! From acid-state package description: Use regular Haskell data structures as your database... - exactly what I need! Snap looks very lively too, simple and you can code view in Haskell, which means concentrate on the problem, not on the boilerplate code! Capital advice, thanks! Chris Smith cdsmith at gmail.com wrote: Thu Jul 7 15:11:10 CEST 2011 Previous message: [Haskell-cafe] Web Framework to Show Experimental Data Next message: [Haskell-cafe] Installation failure crypto-api on MAC Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] On Thu, 2011-07-07 at 13:21 +0400, Dmitri O.Kondratiev wrote: 1) What to use for the Archive? Though input data is in JSON format, data generated from it is binary vectors. Not sure that CouchDB is a good choice in this case. What simple (Haskell lib + DB) combination one may advise that support concurrent read / write access with simple locking (don't need full transactional support)? I think this might be an excellent place to use Lemmih's acid-state package. If I read you correctly, you basically want to store a small enough amount of data that it's not a concern that it will need to reside in memory, and it's fairly regular so there won't be a lot of value in ad hoc queries? If this is the case, then acid-state will let you store it in Haskell data types, and with a bit of Template Haskell, you can access it in a persistent way. 2) Web framework? Don't need AJAX, just basic stuff but simple and easy to code forms? Well, I like Snap enough that I became a core developer for the project, but this seems like a place it's particularly well suited. If you just want something really simple and clean and easy to use, Snap is that thing. Snap itself is very lightweight, but if you want some kind of automated form support, then there is a snap backend for digestive-functors. That's a little complex for my taste, but it is one way to do composing of forms by sticking together form handlers, validators, and the like. Personally, I'm a fan of just using getParam to retrieve the data and writing Haskell code to do what you want. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web Framework to Show Experimental Data
According to acid-state package description: Use regular Haskell data structures as your database... - exactly what I need! Snap looks very lively too, simple and you can code view in Haskell, which means concentrate on the problem, not on the boilerplate code! Capital advice, thanks Chris! Chris Smith cdsmith at gmail.com wrote: Thu Jul 7 15:11:10 CEST 2011 Previous message: [Haskell-cafe] Web Framework to Show Experimental Data Next message: [Haskell-cafe] Installation failure crypto-api on MAC Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] On Thu, 2011-07-07 at 13:21 +0400, Dmitri O.Kondratiev wrote: 1) What to use for the Archive? Though input data is in JSON format, data generated from it is binary vectors. Not sure that CouchDB is a good choice in this case. What simple (Haskell lib + DB) combination one may advise that support concurrent read / write access with simple locking (don't need full transactional support)? I think this might be an excellent place to use Lemmih's acid-state package. If I read you correctly, you basically want to store a small enough amount of data that it's not a concern that it will need to reside in memory, and it's fairly regular so there won't be a lot of value in ad hoc queries? If this is the case, then acid-state will let you store it in Haskell data types, and with a bit of Template Haskell, you can access it in a persistent way. 2) Web framework? Don't need AJAX, just basic stuff but simple and easy to code forms? Well, I like Snap enough that I became a core developer for the project, but this seems like a place it's particularly well suited. If you just want something really simple and clean and easy to use, Snap is that thing. Snap itself is very lightweight, but if you want some kind of automated form support, then there is a snap backend for digestive-functors. That's a little complex for my taste, but it is one way to do composing of forms by sticking together form handlers, validators, and the like. Personally, I'm a fan of just using getParam to retrieve the data and writing Haskell code to do what you want. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
Hi, Continuing my search of Haskell NLP tools and libs, I wonder if the following Haskell libraries exist (googling them does not help): 1) End of Sentence (EOS) Detection. Break text into a collection of meaningful sentences. 2) Part-of-Speech (POS) Tagging. Assign part-of-speech information to each token. 3) Chunking. Analyze each tagged token within a sentence and assemble compound tokens that express logical concepts. Define a custom grammar. 4) Extraction. Analyze each chunk and further tag the chunks as named entities, such as people, organizations, locations, etc. Any ideas where to look for similar Haskell libraries? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
On Wed, Jul 6, 2011 at 8:32 PM, wren ng thornton w...@freegeek.org wrote: On 7/6/11 9:27 AM, Dmitri O.Kondratiev wrote: Hi, Continuing my search of Haskell NLP tools and libs, I wonder if the following Haskell libraries exist (googling them does not help): 1) End of Sentence (EOS) Detection. Break text into a collection of meaningful sentences. Depending on how you mean, this is either fairly trivial (for English) or an ill-defined problem. For things like determining whether the . character is intended as a full stop vs part of an abbreviation; that's trivial. But for general sentence breaking, how do you intend to deal with quotations? What about when news articles quote someone uttering a few sentences before the end-quote marker? So far as I'm aware, there's no satisfactory definition of what the solution should be in all reasonable cases. A sentence isn't really very well-defined in practice. I am looking for Haskell implementation of sentence tokenizer such as described by Tibor Kiss and Jan Strunk’s in “Unsupervised Multilingual Sentence Boundary Detection”, which is implemented in NLTK: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize.punkt-module.html 2) Part-of-Speech (POS) Tagging. Assign part-of-speech information to each token. There are numerous approaches to this problem; do you care about the solution, or will any one of them suffice? I've been working over the last year+ on an optimized HMM-based POS tagger/supertagger with online tagging and anytime n-best tagging. I'm planning to release it this summer (i.e., by the end of August), though there are a few things I'd like to polish up before doing so. In particular, I want to make the package less monolithic. When I release it I'll make announcements here and on the nlp@ list. I am looking for some already working POS tagging framework that can be customized for different pidgin languages. 3) Chunking. Analyze each tagged token within a sentence and assemble compound tokens that express logical concepts. Define a custom grammar. 4) Extraction. Analyze each chunk and further tag the chunks as named entities, such as people, organizations, locations, etc. Any ideas where to look for similar Haskell libraries? I don't know of any work in these areas in Haskell (though I'd love to hear about it). You should try asking on the nlp@ list where the other linguists and NLPers are more likely to see it. I will, though n...@projects.haskell.org. looks very quiet... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell Platform on Ubuntu: Installation Problems
Hi, I am trying to install Haskell Platform on latest Ubuntu desktop: ( uname -a: Linux frigate 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux ) I started with installing GHC. Ubuntu could only install version 6.12.3: without Cabal! Now I am trying to install haskell-platform which is a separate package. Ubuntu suggests to insatll version 2010.1.0.0.1 and fails (see bellow). What sould I do now to get GHC + Cabal? Should I: 1) De-insatll GHC 6.12.3 and all related libraries and try then installing Haskell Platform again? 2) Should I install Caball separately and forget about Haskell Platform? 3) Provide somehow for two different installations? Thanks! === Installation errors: This error could be caused by required additional software packages which are missing or not installable. Furthermore there could be a conflict between software packages which are not allowed to be installed at the same time. haskell-platform: Depends: ghc6 ( 6.12.1+) but 6.12.3-1ubuntu7 is to be installed Depends: libghc6-cgi-dev (= 3001.1.7.2) but 3001.1.7.2-1build1 is to be installed Depends: libghc6-fgl-dev ( 5.4.2.2+) but 5.4.2.2-2build2 is to be installed Depends: libghc6-glut-dev ( 2.1.2.1+) but 2.1.2.1-1build1 is to be installed Depends: libghc6-haskell-src-dev ( 1.0.1.3+) but 1.0.1.3-2build1 is to be installed Depends: libghc6-html-dev ( 1.0.1.2+) but 1.0.1.2-3build2 is to be installed Depends: libghc6-hunit-dev ( 1.2.2.1+) but 1.2.2.1-2build2 is to be installed Depends: libghc6-mtl-dev ( 1.1.0.2+) but 1.1.0.2-10build2 is to be installed Depends: libghc6-network-dev ( 2.2.1.7+) but 2.2.1.7-1build2 is to be installed Depends: libghc6-opengl-dev ( 2.2.3.0+) but 2.2.3.0-2build2 is to be installed Depends: libghc6-parallel-dev ( 2.2.0.1+) but 2.2.0.1-1build1 is to be installed Depends: libghc6-parsec2-dev ( 2.1.0.1+) but 2.1.0.1-2build2 is to be installed Depends: libghc6-quickcheck2-dev ( 2.1.0.3+) but 2.1.0.3-1build2 is to be installed Depends: libghc6-regex-base-dev ( 0.93.1+) but 0.93.1-8build1 is to be installed Depends: libghc6-regex-compat-dev ( 0.92+) but 0.92-6build2 is to be installed Depends: libghc6-regex-posix-dev ( 0.94.1+) but 0.94.1-2build1 is to be installed Depends: libghc6-stm-dev ( 2.1.1.2+) but 2.1.1.2-5build2 is to be installed Depends: libghc6-xhtml-dev (= 3000.2.0.1) but 3000.2.0.1-6build2 is to be installed Depends: libghc6-zlib-dev ( 0.5.2.0+) but 0.5.2.0-4build2 is to be installed Depends: libghc6-http-dev (= 4009) but 4009-2build1 is to be installed Depends: libghc6-deepseq-dev ( 1.1.0.0+) but 1.1.0.0-2build1 is to be installed Depends: alex ( 2.3.3+) but 2.3.3-1 is to be installed Depends: happy ( 1.18.4-2+) but 1.18.4-2 is to be installed Depends: haddock but it is a virtual package ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Platform on Ubuntu: Installation Problems
Adrien Haxaire adrien at adrienhaxaire.org wrote: I dropped the idea of installing Haskell Platform with synaptic. I installed it manually and I don't have any problem since then. To install GHC 7, have you completely de-installed GHC 6.12.3 and all related libraries ? On Mon, Jul 4, 2011 at 5:04 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: Hi, I am trying to install Haskell Platform on latest Ubuntu desktop: ( uname -a: Linux frigate 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux ) I started with installing GHC. Ubuntu could only install version 6.12.3: without Cabal! Now I am trying to install haskell-platform which is a separate package. Ubuntu suggests to insatll version 2010.1.0.0.1 and fails (see bellow). What sould I do now to get GHC + Cabal? Should I: 1) De-insatll GHC 6.12.3 and all related libraries and try then installing Haskell Platform again? 2) Should I install Caball separately and forget about Haskell Platform? 3) Provide somehow for two different installations? Thanks! === Installation errors: This error could be caused by required additional software packages which are missing or not installable. Furthermore there could be a conflict between software packages which are not allowed to be installed at the same time. haskell-platform: Depends: ghc6 ( 6.12.1+) but 6.12.3-1ubuntu7 is to be installed Depends: libghc6-cgi-dev (= 3001.1.7.2) but 3001.1.7.2-1build1 is to be installed Depends: libghc6-fgl-dev ( 5.4.2.2+) but 5.4.2.2-2build2 is to be installed Depends: libghc6-glut-dev ( 2.1.2.1+) but 2.1.2.1-1build1 is to be installed Depends: libghc6-haskell-src-dev ( 1.0.1.3+) but 1.0.1.3-2build1 is to be installed Depends: libghc6-html-dev ( 1.0.1.2+) but 1.0.1.2-3build2 is to be installed Depends: libghc6-hunit-dev ( 1.2.2.1+) but 1.2.2.1-2build2 is to be installed Depends: libghc6-mtl-dev ( 1.1.0.2+) but 1.1.0.2-10build2 is to be installed Depends: libghc6-network-dev ( 2.2.1.7+) but 2.2.1.7-1build2 is to be installed Depends: libghc6-opengl-dev ( 2.2.3.0+) but 2.2.3.0-2build2 is to be installed Depends: libghc6-parallel-dev ( 2.2.0.1+) but 2.2.0.1-1build1 is to be installed Depends: libghc6-parsec2-dev ( 2.1.0.1+) but 2.1.0.1-2build2 is to be installed Depends: libghc6-quickcheck2-dev ( 2.1.0.3+) but 2.1.0.3-1build2 is to be installed Depends: libghc6-regex-base-dev ( 0.93.1+) but 0.93.1-8build1 is to be installed Depends: libghc6-regex-compat-dev ( 0.92+) but 0.92-6build2 is to be installed Depends: libghc6-regex-posix-dev ( 0.94.1+) but 0.94.1-2build1 is to be installed Depends: libghc6-stm-dev ( 2.1.1.2+) but 2.1.1.2-5build2 is to be installed Depends: libghc6-xhtml-dev (= 3000.2.0.1) but 3000.2.0.1-6build2 is to be installed Depends: libghc6-zlib-dev ( 0.5.2.0+) but 0.5.2.0-4build2 is to be installed Depends: libghc6-http-dev (= 4009) but 4009-2build1 is to be installed Depends: libghc6-deepseq-dev ( 1.1.0.0+) but 1.1.0.0-2build1 is to be installed Depends: alex ( 2.3.3+) but 2.3.3-1 is to be installed Depends: happy ( 1.18.4-2+) but 1.18.4-2 is to be installed Depends: haddock but it is a virtual package ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell Platform on Ubuntu: Installation Problems
On Mon, Jul 4, 2011 at 6:24 PM, anonymous qubi...@gmail.com wrote: No, you shouldn't need to do that. Just download the Haskell Platform and GHC 7: http://lambda.galois.com/hp-tmp/2011.2.0.1/haskell-platform-2011.2.0.1.tar.gz http://haskell.org/ghc/dist/7.0.3/ghc-7.0.3-i386-unknown-linux.tar.bz2 Extract ghc, change into the directory, run configure, then make install as root. After that, extract the haskell platform, change into the directory, configure, make, make install as root. Then run cabal update. The haskell platform is broken on Natty. https://bugs.launchpad.net/ubuntu/+source/haskell-platform/+bug/742052 I noticed that ) I removed GHC 6 completely. Then installed platform-independent GHC 7 compiler. Next to configure and eventually compile Haskell Platform I had to install libgmp3-dev, zlib and OpenGL libraries. Istall and 'cabal update' went smoothly. Now I got : GHCi, version 7.0.3 Great! Thanks! On Mon, Jul 4, 2011 at 9:12 AM, Dmitri O.Kondratiev doko...@gmail.comwrote: Adrien Haxaire adrien at adrienhaxaire.org wrote: I dropped the idea of installing Haskell Platform with synaptic. I installed it manually and I don't have any problem since then. To install GHC 7, have you completely de-installed GHC 6.12.3 and all related libraries ? On Mon, Jul 4, 2011 at 5:04 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: Hi, I am trying to install Haskell Platform on latest Ubuntu desktop: ( uname -a: Linux frigate 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux ) I started with installing GHC. Ubuntu could only install version 6.12.3: without Cabal! Now I am trying to install haskell-platform which is a separate package. Ubuntu suggests to insatll version 2010.1.0.0.1 and fails (see bellow). What sould I do now to get GHC + Cabal? Should I: 1) De-insatll GHC 6.12.3 and all related libraries and try then installing Haskell Platform again? 2) Should I install Caball separately and forget about Haskell Platform? 3) Provide somehow for two different installations? Thanks! === Installation errors: This error could be caused by required additional software packages which are missing or not installable. Furthermore there could be a conflict between software packages which are not allowed to be installed at the same time. haskell-platform: Depends: ghc6 ( 6.12.1+) but 6.12.3-1ubuntu7 is to be installed Depends: libghc6-cgi-dev (= 3001.1.7.2) but 3001.1.7.2-1build1 is to be installed Depends: libghc6-fgl-dev ( 5.4.2.2+) but 5.4.2.2-2build2 is to be installed Depends: libghc6-glut-dev ( 2.1.2.1+) but 2.1.2.1-1build1 is to be installed Depends: libghc6-haskell-src-dev ( 1.0.1.3+) but 1.0.1.3-2build1 is to be installed Depends: libghc6-html-dev ( 1.0.1.2+) but 1.0.1.2-3build2 is to be installed Depends: libghc6-hunit-dev ( 1.2.2.1+) but 1.2.2.1-2build2 is to be installed Depends: libghc6-mtl-dev ( 1.1.0.2+) but 1.1.0.2-10build2 is to be installed Depends: libghc6-network-dev ( 2.2.1.7+) but 2.2.1.7-1build2 is to be installed Depends: libghc6-opengl-dev ( 2.2.3.0+) but 2.2.3.0-2build2 is to be installed Depends: libghc6-parallel-dev ( 2.2.0.1+) but 2.2.0.1-1build1 is to be installed Depends: libghc6-parsec2-dev ( 2.1.0.1+) but 2.1.0.1-2build2 is to be installed Depends: libghc6-quickcheck2-dev ( 2.1.0.3+) but 2.1.0.3-1build2 is to be installed Depends: libghc6-regex-base-dev ( 0.93.1+) but 0.93.1-8build1 is to be installed Depends: libghc6-regex-compat-dev ( 0.92+) but 0.92-6build2 is to be installed Depends: libghc6-regex-posix-dev ( 0.94.1+) but 0.94.1-2build1 is to be installed Depends: libghc6-stm-dev ( 2.1.1.2+) but 2.1.1.2-5build2 is to be installed Depends: libghc6-xhtml-dev (= 3000.2.0.1) but 3000.2.0.1-6build2 is to be installed Depends: libghc6-zlib-dev ( 0.5.2.0+) but 0.5.2.0-4build2 is to be installed Depends: libghc6-http-dev (= 4009) but 4009-2build1 is to be installed Depends: libghc6-deepseq-dev ( 1.1.0.0+) but 1.1.0.0-2build1 is to be installed Depends: alex ( 2.3.3+) but 2.3.3-1 is to be installed Depends: happy ( 1.18.4-2+) but 1.18.4-2 is to be installed Depends: haddock but it is a virtual package ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] NLP libraries and tools?
Hi, Please advise on NLP libraries similar to Natural Language Toolkit ( www.nltk.org) First of all I need: - tools to construct 'bag of words' ( http://en.wikipedia.org/wiki/Bag_of_words_model), which is a list of words in the article. - tools to prune common words, such as prepositions and conjunctions, as well as extremely rare words, such as the ones with typos. - stemming tools - Naive Bayes classifier - SVM classifier - k-means clustering Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Twitter API?
Hi, Does anybody work with any Haskell Twitter API library? In particular supporting OAuth authentication? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Twitter API?
On Fri, Jul 1, 2011 at 6:59 PM, Michael Snoyman mich...@snoyman.com wrote: On Fri, Jul 1, 2011 at 5:56 PM, Dmitri O.Kondratiev doko...@gmail.com wrote: Hi, Does anybody work with any Haskell Twitter API library? In particular supporting OAuth authentication? Thanks! Hi, Horimi Ishii added support for OAuth/Twitter to the authenticate[1] package. Michael [1] http://hackage.haskell.org/package/authenticate Thanks! It would be nice to have end-to-end example of using some Twitter scenario. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
On Fri, Jul 1, 2011 at 9:34 PM, Rogan Creswick cresw...@gmail.com wrote: On Fri, Jul 1, 2011 at 3:31 AM, Dmitri O.Kondratiev doko...@gmail.com wrote: First of all I need: ... - tools to construct 'bag of words' (http://en.wikipedia.org/wiki/Bag_of_words_model), which is a list of words in the article. This is trivially implemented if you have a natural language tokenizer you're happy with. Toktok might be worth looking at: http://hackage.haskell.org/package/toktok but I *think* it takes a pretty simple view of tokens (assume it is the tokenizer I've been using within the GF). Unfortunately 'cabal install' fails with toktok: Building toktok-0.5... [1 of 7] Compiling Toktok.Stack ( Toktok/Stack.hs, dist/build/Toktok/Stack.o ) [2 of 7] Compiling Toktok.Sandhi( Toktok/Sandhi.hs, dist/build/Toktok/Sandhi.o ) [3 of 7] Compiling Toktok.Trie ( Toktok/Trie.hs, dist/build/Toktok/Trie.o ) [4 of 7] Compiling Toktok.Lattice ( Toktok/Lattice.hs, dist/build/Toktok/Lattice.o ) [5 of 7] Compiling Toktok.Transducer ( Toktok/Transducer.hs, dist/build/Toktok/Transducer.o ) [6 of 7] Compiling Toktok.Lexer ( Toktok/Lexer.hs, dist/build/Toktok/Lexer.o ) [7 of 7] Compiling Toktok ( Toktok.hs, dist/build/Toktok.o ) Registering toktok-0.5... [1 of 1] Compiling Main ( Main.hs, dist/build/toktok/toktok-tmp/Main.o ) Linking dist/build/toktok/toktok ... [1 of 1] Compiling Main ( tools/ExtractLexicon.hs, dist/build/gf-extract-lexicon/gf-ex\ tract-lexicon-tmp/Main.o ) tools/ExtractLexicon.hs:5:35: Module `PGF' does not export `getLexicon' cabal: Error: some packages failed to install: toktok-0.5 failed during the building phase. The exception was: ExitFailure 1 Any ideas how to solve this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
On Fri, Jul 1, 2011 at 11:58 PM, Rogan Creswick cresw...@gmail.com wrote: On Fri, Jul 1, 2011 at 12:38 PM, Dmitri O.Kondratiev doko...@gmail.com wrote: On Fri, Jul 1, 2011 at 9:34 PM, Rogan Creswick cresw...@gmail.com wrote: On Fri, Jul 1, 2011 at 3:31 AM, Dmitri O.Kondratiev doko...@gmail.com wrote: First of all I need: Unfortunately 'cabal install' fails with toktok: tools/ExtractLexicon.hs:5:35: Module `PGF' does not export `getLexicon' cabal: Error: some packages failed to install: toktok-0.5 failed during the building phase. The exception was: ExitFailure 1 Oh, right - I ran into this problem too, and forgot about it (I should have reported a bug...) I think this fails because of (relatively) recent changes in GF, which isn't constrained to specific versions in the toktok cabal file... --Rogan Any other then 'toktok' Haskell word tokenizer that compiles and works? I need something like: http://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize.regexp.WordPunctTokenizer-class.html Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Graph diagram tools?
Hi, I am looking for Haskell library to create graph diagrams in png or similar formats. Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Conditional IO ?
Hi, What is right way to do conditional IO? For example, I need to write to file errors only in case they exist, otherwise my function should do nothing: handleParseErrors errors | (not . null) errors = writeFile parse-errors.txt (show errors) | otherwise = ? What should be an 'otherwise' case ? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Conditional IO ?
Thanks! Everything works, and 'when' is really nice. ( I still have only basic monad knowledge, need more time to spend on existing libraries) On Mon, Jun 20, 2011 at 12:14 PM, Lyndon Maydwell maydw...@gmail.comwrote: Your errors branch has the type writeFile parse-errors.txt (show errors) :: IO () This means that your otherwise branch should have the same type. You can use the return function that has the type return :: Monad m = a - m a specialised to m = IO in conjunction with the value () :: () giving return () :: IO () There is also the when function that eliminates the else case for conditional IO: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:when On Mon, Jun 20, 2011 at 4:00 PM, Dmitri O.Kondratiev doko...@gmail.com wrote: Hi, What is right way to do conditional IO? For example, I need to write to file errors only in case they exist, otherwise my function should do nothing: handleParseErrors errors | (not . null) errors = writeFile parse-errors.txt (show errors) | otherwise = ? What should be an 'otherwise' case ? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Text.CSV questions
On Mon, Jun 20, 2011 at 7:30 PM, Alejandro Serrano Mena trup...@gmail.comwrote: Maybe you can directly distinguish if the parser returned an error (Left) or not (Right), instead of using lefts and rights: import Text.CSV import Data.Either import System import Data.List main = do [inpFileName] - getArgs putStrLn (Parsing ++inpFileName++...) result - parseCSVFromFile inpFileName case result of Left error - do print Parse error: print error Right csv - print csvL putStrLn All done. Yes, you right, this is better, then printing empty error list. 2011/6/17 Dmitri O.Kondratiev doko...@gmail.com On Fri, Jun 17, 2011 at 1:04 PM, Vincent Hanquez t...@snarc.org wrote: On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote: Hi, I try to parse csv file with Text.CSV, like this: import Text.CSV import System main = do [inpFileName] - getArgs putStrLn (Parsing ++inpFileName++...) let result = parseCSVFromFile inpFileName print result === As a result I get: No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) === Question: How to add a Show instance for (IO (Either Text.Parsec.Error.ParseError CSV))) ? Hi Dmitri, you don't add a show instance for IO, but you unwrap the IO Monad first and then show the result. let result = parseCSVFromFile inpFileName should be: result - parseCSVFromFile inpFileName -- Vincent Thanks everybody! This is how I solved it: import Text.CSV import Data.Either import System import Data.List main = do [inpFileName] - getArgs putStrLn (Parsing ++inpFileName++...) result - parseCSVFromFile inpFileName let errors = lefts [result] let csvL = rights [result] print CSV list print csvL print Errors print errors putStrLn All done. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Text report tools?
Hi, I am looking for an easy way to generate text reports. For starters I need a very simple report that may contain: - Some headers - Lists of text strings where each string can include instances of basic Haskell types. Each string should be printed on a separate line (terminated with LF). Do I understand this right that for such simple reports (as above) Text.Printf is the main tool? As a next step, a simple report engine controlled by templates or DSL would help. Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple CSV parser?
On Fri, Jun 17, 2011 at 2:37 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Thu, 16 Jun 2011, Felipe Almeida Lessa wrote: [1] http://hackage.haskell.org/**package/bytestring-csvhttp://hackage.haskell.org/package/bytestring-csv [2] http://hackage.haskell.org/**package/csv-enumeratorhttp://hackage.haskell.org/package/csv-enumerator [3] http://hackage.haskell.org/**package/spreadsheethttp://hackage.haskell.org/package/spreadsheet [4] http://hackage.haskell.org/**package/csvhttp://hackage.haskell.org/package/csv [5] http://hackage.haskell.org/**package/ssvhttp://hackage.haskell.org/package/ssv I have updated http://www.haskell.org/**haskellwiki/Spreadsheethttp://www.haskell.org/haskellwiki/Spreadsheet === I am trying Data.Spreadseet.fromStringSimple , which is: fromString :: Charhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-Char.html#t:Char- Charhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-Char.html#t:Char- Stringhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-Char.html#t:String- Exceptionalhttp://hackage.haskell.org/packages/archive/explicit-exception/0.1.6/doc/html/Control-Monad-Exception-Asynchronous.html#t:ExceptionalUserMessage Thttp://hackage.haskell.org/packages/archive/spreadsheet/0.1.1/doc/html/Data-Spreadsheet.html#t:T Sourcehttp://hackage.haskell.org/packages/archive/spreadsheet/0.1.1/doc/html/src/Data-Spreadsheet.html#fromString fromString qm sep text parses text into a spreadsheet, using the quotation character qm and the separator character sep. fromStringSimple :: Charhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-Char.html#t:Char- Charhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-Char.html#t:Char- Stringhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-Char.html#t:String- Thttp://hackage.haskell.org/packages/archive/spreadsheet/0.1.1/doc/html/Data-Spreadsheet.html#t:T === Here is my test where quotation mark is a quote () and separator is a comma (,): t1 = fromStringSimple '' ',' tMsg tMsg = REP-RPB1.domain1.systemhost.net,Microsoft.Windows.Computer: REP-RPB1.domain1.systemhost.net,- System Uptime 30 Days,UIGeneratedMonitor3a4ca3359ec34015bee55fd7942836d8,2,Custom,10/17/2009 8:48:38 AM === As a result I get: [[*** Exception: dequoteSimple: string does not end with a quotation mark === Question: In this particular line I have no quotation mark, but in other lines I may have quoted text fields, separated by commas (,) and also with commas *iside* quoted fields . What parameters should I pass to 'fromStringSimple' so it worked in both cases: 1) for lines with quotation marks and 2) for lines without quotation marks? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Text.CSV questions
Hi, I try to parse csv file with Text.CSV, like this: import Text.CSV import System main = do [inpFileName] - getArgs putStrLn (Parsing ++inpFileName++...) let result = parseCSVFromFile inpFileName print result === As a result I get: No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) === Question: How to add a Show instance for (IO (Either Text.Parsec.Error.ParseError CSV))) ? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Text.CSV questions
On Fri, Jun 17, 2011 at 1:04 PM, Vincent Hanquez t...@snarc.org wrote: On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote: Hi, I try to parse csv file with Text.CSV, like this: import Text.CSV import System main = do [inpFileName] - getArgs putStrLn (Parsing ++inpFileName++...) let result = parseCSVFromFile inpFileName print result === As a result I get: No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) === Question: How to add a Show instance for (IO (Either Text.Parsec.Error.ParseError CSV))) ? Hi Dmitri, you don't add a show instance for IO, but you unwrap the IO Monad first and then show the result. let result = parseCSVFromFile inpFileName should be: result - parseCSVFromFile inpFileName -- Vincent Thanks everybody! This is how I solved it: import Text.CSV import Data.Either import System import Data.List main = do [inpFileName] - getArgs putStrLn (Parsing ++inpFileName++...) result - parseCSVFromFile inpFileName let errors = lefts [result] let csvL = rights [result] print CSV list print csvL print Errors print errors putStrLn All done. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Win32: cabal install --prefix=$HOME --user ?
On win32 cabal install --prefix=$HOME --user fails: cabal install --prefix=$HOME --user Resolving dependencies... Configuring split-0.1.4... cabal: expected an absolute directory name for --prefix: $HOME cabal: Error: some packages failed to install: split-0.1.4 failed during the configure step. The exception was: ExitFailure 1 What is the right equivalent of cabal install --prefix=$HOME --user on Win32? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.Map: Values to keys and keys to values
Hi, Data.Map has many great functions, yet I could not find the one that allows from one map create another map where keys are values and values are keys of the first one. Something like: transMap:: (Ord k, Ord a) = Map k a - Map a k Does such function exist? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Map: Values to keys and keys to values
On Thu, Jun 16, 2011 at 5:38 PM, Johan Tibell johan.tib...@gmail.comwrote: On Thu, Jun 16, 2011 at 3:01 PM, Dmitri O.Kondratiev doko...@gmail.com wrote: Hi, Data.Map has many great functions, yet I could not find the one that allows from one map create another map where keys are values and values are keys of the first one. Something like: transMap:: (Ord k, Ord a) = Map k a - Map a k I don't think implementing this function in the library would add much as it cannot be implemented more efficiently with access to the internal representation than it can using the public API. Just write transMap = M.fromList . map swap . M.toList and stick it in some utility file. Johan Yes, this is a good one. Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Win32: cabal install --prefix=$HOME --user ?
On Thu, Jun 16, 2011 at 6:18 PM, Ryan Yates fryguy...@gmail.com wrote: There is a nice table in the cabal docs that explains how prefix gets used: http://www.haskell.org/ghc/docs/7.0.4/html/Cabal/builders.html#simple-paths For Vista and above C:\Documents and settings\myusername\ is C:\Users\myusername. The equivalent to $HOME on Windows would be $USERPROFILE but the syntax of expanding an environment variable is going to depend on the shell you are using: cmd window: cabal install --prefix=%USERPROFILE% --user PowerShell: cabal install --prefix=${env:USERPROFILE} --user msys window: cabal install --prefix=$USERPROFILE --user Note that msys does define $HOME and it is a different physical path than $USERPROFILE. Ryan, thanks! This win32 $HOME story is clear now. And why not just use: cabal install instead of: cabal install --prefix=%USERPROFILE% --user for win32 platform? Where in this case cabal install root will be? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Simple CSV parser?
Hi, This time I am looking for a simple CSV parser that supports commas and quotes. I have no time now to learn Parsec, so I hope to find something simple and easy to use. Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple CSV parser?
On Fri, Jun 17, 2011 at 1:27 AM, Felipe Almeida Lessa felipe.le...@gmail.com wrote: On Thu, Jun 16, 2011 at 6:21 PM, Dmitri O.Kondratiev doko...@gmail.com wrote: This time I am looking for a simple CSV parser that supports commas and quotes. I have no time now to learn Parsec, so I hope to find something simple and easy to use. 1. Go to http://hackage.haskell.org/packages/archive/pkg-list.html 2. Press Ctrl+F, look for CSV. 3. Find many packages [1,2,3,4,5] 4. See which one suits better your needs. [1] http://hackage.haskell.org/package/bytestring-csv [2] http://hackage.haskell.org/package/csv-enumerator [3] http://hackage.haskell.org/package/spreadsheet [4] http://hackage.haskell.org/package/csv [5] http://hackage.haskell.org/package/ssv -- Felipe. Now I know where and how to search, sorry for trivial questions ) Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple CSV parser?
On Fri, Jun 17, 2011 at 1:33 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: How could it miss my lovely package named spreadsheet? It provides a lazy parser. Installing spreadsheet: cabal install Resolving dependencies... cabal: cannot configure explicit-exception-0.1.6. It requires transformers ==0.2.* For the dependency on transformers ==0.2.* there are these packages: transformers-0.2.0.0, transformers-0.2.1.0 and transformers-0.2.2.0. However none of them are available. transformers-0.2.0.0 was excluded because spreadsheet-0.1 requires transformers ==0.0.* transformers-0.2.1.0 was excluded because spreadsheet-0.1 requires transformers ==0.0.* transformers-0.2.2.0 was excluded because spreadsheet-0.1 requires transformers ==0.0.* How to make cabal install all the dependencies? I couldn't find this in the docs at: http://www.haskell.org/haskellwiki/Cabal-Install ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple CSV parser?
On Fri, Jun 17, 2011 at 2:05 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Fri, 17 Jun 2011, Dmitri O.Kondratiev wrote: How to make cabal install all the dependencies? I couldn't find this in the docs at: http://www.haskell.org/haskellwiki/Cabal-Install Usually, 'cabal install' automatically installs all imported packages. But it will certainly not do, if a dependency problem cannot be solved by downloading packages. In your case it may be, that installed packages are compiled with respect to different versions of the same package, say 'transformers'. I found out, that you get more useful cabal messages if you force cabal-install to use a specific version of a package. Say, run $ ghc-pkg list transformers transformers-0.2.2.0 Then call $ cabal install spreadsheet --constraint=transformers==0.2.2.0 What does 'cabal' tell you? ghc-pkg list transformers /Library/Frameworks/GHC.framework/Versions/612/usr/lib/ghc-6.12.3/package.conf.d: /Users/user/.ghc/i386-darwin-6.12.3/package.conf.d: transformers-0.2.2.0 cabal install spreadsheet --constraint=transformers==0.2.2.0 Resolving dependencies... cabal: cannot configure spreadsheet-0.1. It requires transformers ==0.0.* For the dependency on transformers ==0.0.* there are these packages: transformers-0.0.0.0 and transformers-0.0.1.0. However none of them are available. transformers-0.0.0.0 was excluded because of the top level dependency transformers ==0.2.2.0 transformers-0.0.1.0 was excluded because of the top level dependency transformers ==0.2.2.0 Compilation exited abnormally with code 1 at Fri Jun 17 02:12:30 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple CSV parser?
On Fri, Jun 17, 2011 at 2:13 AM, Dmitri O.Kondratiev doko...@gmail.comwrote: On Fri, Jun 17, 2011 at 2:05 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Fri, 17 Jun 2011, Dmitri O.Kondratiev wrote: How to make cabal install all the dependencies? I couldn't find this in the docs at: http://www.haskell.org/haskellwiki/Cabal-Install Usually, 'cabal install' automatically installs all imported packages. But it will certainly not do, if a dependency problem cannot be solved by downloading packages. In your case it may be, that installed packages are compiled with respect to different versions of the same package, say 'transformers'. I found out, that you get more useful cabal messages if you force cabal-install to use a specific version of a package. Say, run $ ghc-pkg list transformers transformers-0.2.2.0 Then call $ cabal install spreadsheet --constraint=transformers==0.2.2.0 What does 'cabal' tell you? ghc-pkg list transformers /Library/Frameworks/GHC.framework/Versions/612/usr/lib/ghc-6.12.3/package.conf.d: /Users/user/.ghc/i386-darwin-6.12.3/package.conf.d: transformers-0.2.2.0 cabal install spreadsheet --constraint=transformers==0.2.2.0 Resolving dependencies... cabal: cannot configure spreadsheet-0.1. It requires transformers ==0.0.* For the dependency on transformers ==0.0.* there are these packages: transformers-0.0.0.0 and transformers-0.0.1.0. However none of them are available. transformers-0.0.0.0 was excluded because of the top level dependency transformers ==0.2.2.0 transformers-0.0.1.0 was excluded because of the top level dependency transformers ==0.2.2.0 Compilation exited abnormally with code 1 at Fri Jun 17 02:12:30 I really have no choice, but install Data.Spreadsheet, because this is the only library that allows split a _single_ CSV string into chunks (which is exactly what I need). All other libs work with CSV files or provide a DSL to do such a simple thing! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple CSV parser?
On Fri, Jun 17, 2011 at 2:27 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: I see. I had fixed the problem locally long time ago, but somehow missed upload to Hackage. Try the updated package, please. Ok great! Installed (with some warnings, see below), thank you! I'll try it tomorrow (now here is 2:34 am) on a file of about 4000 lines. Thanks! Compilation started at Fri Jun 17 02:29:59 cabal install Resolving dependencies... Downloading explicit-exception-0.1.6... Configuring explicit-exception-0.1.6... Preprocessing library explicit-exception-0.1.6... Preprocessing executables for explicit-exception-0.1.6... Building explicit-exception-0.1.6... [1 of 9] Compiling Control.Monad.Label ( src/Control/Monad/Label.hs, dist/build/Control/Monad/Label.o ) [2 of 9] Compiling Control.Monad.Exception.Synchronous ( src/Control/Monad/Exception/Synchronous.hs, dist/build/Control/Monad/Exception/Synchronous.o ) [3 of 9] Compiling Control.Monad.Exception.Warning ( src/Control/Monad/Exception/Warning.hs, dist/build/Control/Monad/Exception/Warning.o ) [4 of 9] Compiling Control.Monad.Exception.Label ( src/Control/Monad/Exception/Label.hs, dist/build/Control/Monad/Exception/Label.o ) [5 of 9] Compiling System.IO.Straight ( src/System/IO/Straight.hs, dist/build/System/IO/Straight.o ) src/System/IO/Straight.hs:61:9: Warning: orphan instance: instance (MonadSIO m, ContainsIOException e) = MonadIO (ExceptionalT e m) [6 of 9] Compiling System.IO.Exception.File ( src/System/IO/Exception/File.hs, dist/build/System/IO/Exception/File.o ) [7 of 9] Compiling System.IO.Exception.BinaryFile ( src/System/IO/Exception/BinaryFile.hs, dist/build/System/IO/Exception/BinaryFile.o ) [8 of 9] Compiling Control.Monad.Exception.Asynchronous ( src/Control/Monad/Exception/Asynchronous.hs, dist/build/Control/Monad/Exception/Asynchronous.o ) [9 of 9] Compiling System.IO.Exception.TextFile ( src/System/IO/Exception/TextFile.hs, dist/build/System/IO/Exception/TextFile.o ) src/System/IO/Exception/TextFile.hs:8:0: Warning: In the use of `Async.manySynchronousT' (imported from Control.Monad.Exception.Asynchronous): Deprecated: use manyMonoidT with appropriate Monad like LazyIO and result Monoid like Endo instead Registering explicit-exception-0.1.6... Installing library in /Users/user/.cabal/lib/explicit-exception-0.1.6/ghc-6.12.3 Registering explicit-exception-0.1.6... Configuring spreadsheet-0.1.1... Preprocessing library spreadsheet-0.1.1... Building spreadsheet-0.1.1... [1 of 3] Compiling Data.Spreadsheet.CharSource ( src/Data/Spreadsheet/CharSource.hs, dist/build/Data/Spreadsheet/CharSource.o ) [2 of 3] Compiling Data.Spreadsheet.Parser ( src/Data/Spreadsheet/Parser.hs, dist/build/Data/Spreadsheet/Parser.o ) [3 of 3] Compiling Data.Spreadsheet ( src/Data/Spreadsheet.hs, dist/build/Data/Spreadsheet.o ) Registering spreadsheet-0.1.1... Installing library in /Users/user/.cabal/lib/spreadsheet-0.1.1/ghc-6.12.3 Registering spreadsheet-0.1.1... Compilation finished at Fri Jun 17 02:30:05 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 7.0.3 / Win32: Data.Time library?
Hi, Yitz! Your example puts scattered around pieces in place, thanks a lot! On Wed, Jun 15, 2011 at 9:49 AM, Yitzchak Gale g...@sefer.org wrote: Dmitri O.Kondratiev wrote: It would also help to see a simple example of parsing 10/11/2009 7:04:28 PM to time and date objects. Let's assume that 10/11/2009 means October 11, as in the U.S. Then you can use: import System.Locale (defaultTimeLocale) import Data.Time thatMoment :: Maybe UTCTime thatMoment = parseTime defaultTimeLocale %m/%d/%Y %l:%M:%S %p 10/11/2009 7:04:28 PM Then use diffUTCTime to subtract two UTCTime and get the amount of time between them. The resulting object can then be used as if it is a regular floating point number in units of seconds, or you can use the functions in Data.Time that treat it specially as an amount of time. There are many options for the format string and locale that will affect how the date is parsed - the order of month and day, leading zeros or leading spaces, upper case or lower case AM or PM (or 24-hour clock), etc. You can also get different behavior on parsing failure by using readTime or readsTime instead of parseTime. For details, see: http://www.haskell.org/ghc/docs/7.0.3/html/libraries/time-1.2.0.3/Data-Time-Format.html http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/System-Locale.html#t:TimeLocale http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/src/System-Locale.html#TimeLocale As an example of modifying the locale, let's say you want to use a and p instead of AM and PM, as is customary in some parts of the world. Then you can say: myLocale = defaultTimeLocale {amPm = (a,p)} and then use myLocale instead of defaultTimeLocale. Hope this helps, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 7.0.3 / Win32: Data.Time library?
Still have trouble iterating days ( I have: ds1 = 10/11/2009 7:04:28 PM ds2 = 10/17/2009 8:48:29 AM t1 = readTime defaultTimeLocale %m/%d/%Y %l:%M:%S %p ds1 :: UTCTime t2 = readTime defaultTimeLocale %m/%d/%Y %l:%M:%S %p ds2 :: UTCTime dif = diffUTCTime t2 t1 I need to: 1) Find how many complete days elapsed between t1 and t2 2) Find UTCTime for a moment 6 days after t1, in other words time equal to t1 + 6 * 24 hours. Questions: 1) Is there any library function that will convert (diff = diffUTCTime t2 t1) to a data structure similar to a tuple (days, hours, mins, secs) where 'days' is a whole number of days in my 'diff'' interval, and similar for 'hours', 'mins' and 'secs' in the tuple above? 2) What is the 'right way' of adding days to UTCTime? Should I add just equivalent number of seconds or should I convert UTCTime to Data.Time.Calendar.Day type first and then use 'addDays' function? 3) How to convert UTCTime to Data.Time.Calendar.Day and back to UTCTime? Thanks! On Wed, Jun 15, 2011 at 12:55 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: Hi, Yitz! Your example puts scattered around pieces in place, thanks a lot! On Wed, Jun 15, 2011 at 9:49 AM, Yitzchak Gale g...@sefer.org wrote: Dmitri O.Kondratiev wrote: It would also help to see a simple example of parsing 10/11/2009 7:04:28 PM to time and date objects. Let's assume that 10/11/2009 means October 11, as in the U.S. Then you can use: import System.Locale (defaultTimeLocale) import Data.Time thatMoment :: Maybe UTCTime thatMoment = parseTime defaultTimeLocale %m/%d/%Y %l:%M:%S %p 10/11/2009 7:04:28 PM Then use diffUTCTime to subtract two UTCTime and get the amount of time between them. The resulting object can then be used as if it is a regular floating point number in units of seconds, or you can use the functions in Data.Time that treat it specially as an amount of time. There are many options for the format string and locale that will affect how the date is parsed - the order of month and day, leading zeros or leading spaces, upper case or lower case AM or PM (or 24-hour clock), etc. You can also get different behavior on parsing failure by using readTime or readsTime instead of parseTime. For details, see: http://www.haskell.org/ghc/docs/7.0.3/html/libraries/time-1.2.0.3/Data-Time-Format.html http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/System-Locale.html#t:TimeLocale http://www.haskell.org/ghc/docs/7.0.3/html/libraries/old-locale-1.0.0.2/src/System-Locale.html#TimeLocale As an example of modifying the locale, let's say you want to use a and p instead of AM and PM, as is customary in some parts of the world. Then you can say: myLocale = defaultTimeLocale {amPm = (a,p)} and then use myLocale instead of defaultTimeLocale. Hope this helps, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Best platform for development with GHC?
*Ketil Malde* ketil at malde.org haskell-cafe%40haskell.org?Subject=Re%3A%20%5BHaskell-cafe%5D%20Best%20platform%20for%20development%20with%20GHC%3FIn-Reply-To=%3C8739jb60hv.fsf%40malde.org%3E writes: I use Ubuntu. Most stuff is fairly up-to-date, but even with six-month releases, it's lagging the cutting edge, and GHC is still 6.12. Thus, I tend to install development stuff via Cabal these days, which at least partly evens out the playing ground between different distributions. I hope latest GHC (itself + standard libraries) can always be compiled from source on Ubuntu these days? Let me know if you would like opinions on Emacs vs vi! I know vi, but it is just that I got used to Emacs which is my main IDE for most PL that I work with and for many years already ) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Simple string tokenizer?
Sorry if this question was asked billions of times already, but I can not find a simple string tokenizer. All I need is to split a line in chunks at specified delimiter such as (,), nothing more. Don't want to write it myself for two reasons: 1) have to write lots of other code in very short time 2) don't want undermine idea of code reuse ) Where to get latest Data.String.Utils library that I saw somewhere on the web and that has a nice and simple 'split' function? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simple string tokenizer?
On Wed, Jun 15, 2011 at 8:25 PM, Daniel Patterson lists.hask...@dbp.mm.stwrote: Would this work? http://hackage.haskell.org/packages/archive/split/0.1.4/doc/html/Data-List-Split.html Yes, I think it will. Interface looks just great, thanks a lot! http://hackage.haskell.org/packages/archive/split/0.1.4/doc/html/Data-List-Split.html On Jun 15, 2011, at 12:21 PM, Dmitri O.Kondratiev wrote: Sorry if this question was asked billions of times already, but I can not find a simple string tokenizer. All I need is to split a line in chunks at specified delimiter such as (,), nothing more. Don't want to write it myself for two reasons: 1) have to write lots of other code in very short time 2) don't want undermine idea of code reuse ) Where to get latest Data.String.Utils library that I saw somewhere on the web and that has a nice and simple 'split' function? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC 7.0.3 / Win32: Data.Time library?
It looks like GHC, 7.0.3 Haskell Hierarchical Libraries documentation generated for Win32, that goes with Haskell Platform installation package, does not have a section on Data.Time module. How can that be? I need to convert a string of the form ,10/11/2009 7:04:28 PM to Haskell type that can be used for comparing and abstracting dates. What is the simplest way to day that? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 7.0.3 / Win32: Data.Time library?
Sorry for typo - I need subtract dates (no 'abstracting') : On Tue, Jun 14, 2011 at 3:49 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: It looks like GHC, 7.0.3 Haskell Hierarchical Libraries documentation generated for Win32, that goes with Haskell Platform installation package, does not have a section on Data.Time module. How can that be? I need to convert a string of the form ,10/11/2009 7:04:28 PM to Haskell type that can be used for comparing and abstracting dates. What is the simplest way to day that? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 7.0.3 / Win32: Data.Time library?
Yes, thanks. I just wonder why documentation for this particular module (Data.Time) is missing from GHC, 7.0.3 Haskell Hierarchical Libraries documentation generated for Win32. Really strange ... On Tue, Jun 14, 2011 at 4:10 PM, Dmitry Olshansky olshansk...@gmail.comwrote: Could you look at http://hackage.haskell.org/packages/archive/time/1.2.0.5/doc/html/Data-Time-Format.html ? Is it enough? 2011/6/14 Dmitri O.Kondratiev doko...@gmail.com Sorry for typo - I need subtract dates (no 'abstracting') : On Tue, Jun 14, 2011 at 3:49 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: It looks like GHC, 7.0.3 Haskell Hierarchical Libraries documentation generated for Win32, that goes with Haskell Platform installation package, does not have a section on Data.Time module. How can that be? I need to convert a string of the form ,10/11/2009 7:04:28 PM to Haskell type that can be used for comparing and abstracting dates. What is the simplest way to day that? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 7.0.3 / Win32: Data.Time library?
It would also help to see a simple example of parsing 10/11/2009 7:04:28 PM to time and date objects. On Tue, Jun 14, 2011 at 4:41 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: Yes, thanks. I just wonder why documentation for this particular module (Data.Time) is missing from GHC, 7.0.3 Haskell Hierarchical Libraries documentation generated for Win32. Really strange ... On Tue, Jun 14, 2011 at 4:10 PM, Dmitry Olshansky olshansk...@gmail.comwrote: Could you look at http://hackage.haskell.org/packages/archive/time/1.2.0.5/doc/html/Data-Time-Format.html ? Is it enough? 2011/6/14 Dmitri O.Kondratiev doko...@gmail.com Sorry for typo - I need subtract dates (no 'abstracting') : On Tue, Jun 14, 2011 at 3:49 PM, Dmitri O.Kondratiev doko...@gmail.comwrote: It looks like GHC, 7.0.3 Haskell Hierarchical Libraries documentation generated for Win32, that goes with Haskell Platform installation package, does not have a section on Data.Time module. How can that be? I need to convert a string of the form ,10/11/2009 7:04:28 PM to Haskell type that can be used for comparing and abstracting dates. What is the simplest way to day that? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Please help : Data.Time.Format parseTime
I am trying to convert data string to time: import Data.Time import Data.Time.Format import Locale ds = 10/11/2009 7:04:28 PM t = parseTime defaultTimeLocale %D %H:%M:%S %p ds :: Maybe UTCTime and get Nothing. What is wrong? Thanks ! Dmitri. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Please help : Data.Time.Format parseTime
Magnifique, ca marche! Grand merci, Vincent! On Wed, Jun 15, 2011 at 1:16 AM, Vincent Gerard vinc...@xenbox.fr wrote: Hello Dmitri, It seems that your format pattern does not match exactly the format of the input, thus the parser returns Nothing. Try the following format string which seems to work with your date: parseTime defaultTimeLocale %m/%d/%Y %l:%M:%S %p ds :: Maybe UTCTime returns : Just 2009-10-11 19:04:28 UTC The parsings errors in your format could come from . %D expects a 2 char year . %H expects a 0 padded hour (like 07, not 7) Regards, Vincent Gerard On Wed, 15 Jun 2011 00:33:56 +0400 Dmitri O.Kondratiev doko...@gmail.com wrote: I am trying to convert data string to time: import Data.Time import Data.Time.Format import Locale ds = 10/11/2009 7:04:28 PM t = parseTime defaultTimeLocale %D %H:%M:%S %p ds :: Maybe UTCTime and get Nothing. What is wrong? Thanks ! Dmitri. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Best platform for development with GHC?
Which platform - Mac OS X, Linux or Win32 is best for development with GHC today? How are things with Ubuntu? It was quite a while already that I used Haskell on Linux. Today I have to code on Win32 and Mac OS X. Installing extra libraries caused most of the pains for me on Win32 - for example GTK and Gnuplot is not easy to install on Win32. Installing GTK on Max OSX is also a hard work, but no problems with Gnuplot at all. Haskell mode for Emacs works fine on Mac OS X, but only to some extent on Win32. I have not managed to start GHCi in Emacs buffer on Win32. Haskell Win32 Platform also has a weird bug of missing documentation on some widely used modules from Haskell Hierarchical Library. I understand that Linux should be a much better environment for integrating with external libraries (just because most of them were originally developed for Linux). I don't want to start religious wars, yet I wonder on what platform Haskell run-time works best and development has minimum obstacles? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Best platform for development with GHC?
On Wed, Jun 15, 2011 at 2:34 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Wed, 15 Jun 2011, Dmitri O.Kondratiev wrote: Which platform - Mac OS X, Linux or Win32 is best for development with GHC today? How are things with Ubuntu? It was quite a while already that I used Haskell on Linux. Today I have to code on Win32 and Mac OS X. Installing extra libraries caused most of the pains for me on Win32 - for example GTK and Gnuplot is not easy to install on Win32. Installing GTK on Max OSX is also a hard work, but no problems with Gnuplot at all. Haskell mode for Emacs works fine on Mac OS X, but only to some extent on Win32. I have not managed to start GHCi in Emacs buffer on Win32. Since I maintain the gnuplot binding for Haskell - what are the particular problems with that package on Windows? As I understand for Gnuplot to work on Win32 you need to compile its C source. Compared to Linux GCC, neither Cygwin nor Mingw are fun to use on Win32. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.List / Map: simple serialization?
On Thu, Jun 9, 2011 at 11:31 AM, Max Bolingbroke batterseapo...@hotmail.com wrote: If you want plain text serialization, writeFile output.txt . show and fmap read (readFile output.txt) should suffice... Max This code works: main = do let xss = [[1,2,3],[4,5,6],[7,8],[9]] writeFile output.txt (show xss) line - readFile output.txt let xss2 = read line :: [[Int]] print xss2 As soon as complete file is returned as a single line, using 'fmap' does not make sense here: line - readFile output.txt let xss2 = fmap read line When to use 'fmap'? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.List / Map: simple serialization?
On Fri, Jun 10, 2011 at 4:13 PM, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Friday 10 June 2011, 13:49:23, Dmitri O.Kondratiev wrote: On Thu, Jun 9, 2011 at 11:31 AM, Max Bolingbroke batterseapo...@hotmail.com wrote: If you want plain text serialization, writeFile output.txt . show and fmap read (readFile output.txt) should suffice... Max This code works: main = do let xss = [[1,2,3],[4,5,6],[7,8],[9]] writeFile output.txt (show xss) line - readFile output.txt let xss2 = read line :: [[Int]] print xss2 As soon as complete file is returned as a single line, using 'fmap' does not make sense here: line - readFile output.txt let xss2 = fmap read line When to use 'fmap'? xss2 - fmap read (readFile output.txt) or xss2 - read `fmap` readFile output.txt But it might be necessary to tell the compiler which type xss2 ought to have, so it knows which `read' to invoke, if it can't infer that from later use. Two questions: 1) Why to use 'fmap' at all if a complete file is read in a single line of text? 2) Trying to use 'fmap' illustrates 1) producing an error (see below): main = do let xss = [[1,2,3],[4,5,6],[7,8],[9]] writeFile output.txt (show xss) xss2 - fmap read (readFile output.txt) :: [[Int]] print xss2 == Error: Couldn't match expected type `[String]' with actual type `IO String' In the return type of a call of `readFile' In the second argument of `fmap', namely `(readFile output.txt)' In a stmt of a 'do' expression: xss2 - fmap read (readFile output.txt) :: [[Int]] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.List / Map: simple serialization?
Thanks for the excellent explanation! : On Fri, Jun 10, 2011 at 4:49 PM, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Friday 10 June 2011, 14:25:59, Dmitri O.Kondratiev wrote: Two questions: 1) Why to use 'fmap' at all if a complete file is read in a single line of text? Well, it's a matter of taste whether to write foo - fmap read (readFile bar) stuffWithFoo or text - readFile bar let foo = read text stuffWithFoo The former saves one line of code (big deal). 2) Trying to use 'fmap' illustrates 1) producing an error (see below): main = do let xss = [[1,2,3],[4,5,6],[7,8],[9]] writeFile output.txt (show xss) xss2 - fmap read (readFile output.txt) :: [[Int]] That type signature doesn't refer to xss2, but to the action to the right of the -, `fmap read (readFile output.txt)' readFile output.txt :: IO String so fmap foo (readFile output.txt) :: IO bar supposing foo :: String - bar You want read at the type `String - [[Int]]', so the signature has to be xss2 - fmap read (readFile output.txt) :: IO [[Int]] print xss2 == Error: Couldn't match expected type `[String]' with actual type `IO String' In the return type of a call of `readFile' In the second argument of `fmap', namely `(readFile output.txt)' In a stmt of a 'do' expression: xss2 - fmap read (readFile output.txt) :: [[Int]] Looking at the line xss2 - fmap read someStuff :: [[Int]] the compiler sees that fmap read someStuff should have type [[Int]] Now, fmap :: Functor f = (a - b) - f a - f b and [] is a Functor, so the fmap here is map, hence map read someStuff :: [[Int]] means someStuff :: [String] That's the expected type of (readFile output.txt), but the actual type is of course IO String, which is the reported error. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Installing Gtk2Hs on Win32
Please help to find pre-compiled binary libraries of Gtk+ for Win32. Gtk2Hs insatll instructions at: http://code.haskell.org/gtk2hs/INSTALL tells us: [quote] Building on Windows Installation on Windows is nearly as easy as on Unix platforms. However, you need to download the pre-compiled binary libraries of Gtk+ and all it's dependent libraries. Point your browser to http://www.gtk.org/download-windows.html and download one of the All-in-one bundles. Note that you do *not* need to install MinGW nor MSys (but it does not hurt if they are installed on your system). Install the binaries by unpacking them into a directory without spaces. [/quote] This link (http://www.gtk.org/download-windows.html) is dead. Where to get pre-compiled binary libraries of Gtk+ ? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Errors installing 'Haskell Charts'
I am trying to install HaskellCharts at: http://dockerz.net/twd/HaskellCharts Running: cabal update cabal install gtk2hs-buildtools cabal install gtk cabal install chart goes well untill 'cabal install chart' which results in: C:\wks\RCAcabal install chart Resolving dependencies... C:\Users\DKONDR~1\AppData\Local\Temp\cairo-0.12.03136\cairo-0.12.0\Gtk2HsSetup.h s:25:2: warning: #warning Setup.hs is guessing the version of Cabal. If compilat ion of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when b uilding (prefixed by --ghc-option= when using the 'cabal' command) [1 of 2] Compiling Gtk2HsSetup ( C:\Users\DKONDR~1\AppData\Local\Temp\cairo -0.12.03136\cairo-0.12.0\Gtk2HsSetup.hs, C:\Users\DKONDR~1\AppData\Local\Temp\ca iro-0.12.03136\cairo-0.12.0\dist\setup\Gtk2HsSetup.o ) [2 of 2] Compiling Main ( C:\Users\DKONDR~1\AppData\Local\Temp\cairo -0.12.03136\cairo-0.12.0\Setup.hs, C:\Users\DKONDR~1\AppData\Local\Temp\cairo-0. 12.03136\cairo-0.12.0\dist\setup\Main.o ) Linking C:\Users\DKONDR~1\AppData\Local\Temp\cairo-0.12.03136\cairo-0.12.0\dist\ setup\setup.exe ... Configuring cairo-0.12.0... setup.exe: The program pkg-config version =0.9.0 is required but it could not be found. C:\Users\DKONDR~1\AppData\Local\Temp\glib-0.12.03136\glib-0.12.0\Gtk2HsSetup.hs: 25:2: warning: #warning Setup.hs is guessing the version of Cabal. If compilatio n of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when bui lding (prefixed by --ghc-option= when using the 'cabal' command) [1 of 2] Compiling Gtk2HsSetup ( C:\Users\DKONDR~1\AppData\Local\Temp\glib- 0.12.03136\glib-0.12.0\Gtk2HsSetup.hs, C:\Users\DKONDR~1\AppData\Local\Temp\glib -0.12.03136\glib-0.12.0\dist\setup\Gtk2HsSetup.o ) [2 of 2] Compiling Main ( C:\Users\DKONDR~1\AppData\Local\Temp\glib- 0.12.03136\glib-0.12.0\Setup.hs, C:\Users\DKONDR~1\AppData\Local\Temp\glib-0.12. 03136\glib-0.12.0\dist\setup\Main.o ) Linking C:\Users\DKONDR~1\AppData\Local\Temp\glib-0.12.03136\glib-0.12.0\dist\se tup\setup.exe ... Configuring glib-0.12.0... setup.exe: The program pkg-config version =0.9.0 is required but it could not be found. cabal: Error: some packages failed to install: Chart-0.14 depends on glib-0.12.0 which failed to install. cairo-0.12.0 failed during the configure step. The exception was: ExitFailure 1 gio-0.12.0 depends on glib-0.12.0 which failed to install. glib-0.12.0 failed during the configure step. The exception was: ExitFailure 1 gtk-0.12.0 depends on glib-0.12.0 which failed to install. pango-0.12.0 depends on glib-0.12.0 which failed to install. Where to get glib-0.12.0 ? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Errors installing 'Haskell Charts'
Trying to install the same stuff on Mac OS X 10.6.7 I get problems both with gtk2hs-buildtools and pkg-config, (see below). Any ideas where to get pre-built glib and pkg-config both for Win32 and Mac OS X? == Problems on Mac OS X with gtk2hs-buildtools : cabal install gtk Resolving dependencies... /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04207/cairo-0.12.0/Gtk2HsSetup.hs:25:0: warning: #warning Setup.hs is guessing the version of Cabal. If compilation of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when building (prefixed by --ghc-option= when using the 'cabal' command) [1 of 2] Compiling Gtk2HsSetup ( /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04207/cairo-0.12.0/Gtk2HsSetup.hs, /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04207/cairo-0.12.0/dist/setup/Gtk2HsSetup.o ) /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04207/cairo-0.12.0/Gtk2HsSetup.hs:201:69: Couldn't match expected type `PackageDBStack' against inferred type `PackageDB' In the sixth argument of `registerPackage', namely `packageDb' In the expression: registerPackage verbosity installedPkgInfo pkg lbi inplace packageDb In a case alternative: _ | modeGenerateRegFile - die Generate Reg File not supported | modeGenerateRegScript - die Generate Reg Script not supported | otherwise - registerPackage verbosity installedPkgInfo pkg lbi inplace packageDb /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04207/glib-0.12.0/Gtk2HsSetup.hs:25:0: warning: #warning Setup.hs is guessing the version of Cabal. If compilation of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when building (prefixed by --ghc-option= when using the 'cabal' command) [1 of 2] Compiling Gtk2HsSetup ( /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04207/glib-0.12.0/Gtk2HsSetup.hs, /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04207/glib-0.12.0/dist/setup/Gtk2HsSetup.o ) /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04207/glib-0.12.0/Gtk2HsSetup.hs:201:69: Couldn't match expected type `PackageDBStack' against inferred type `PackageDB' In the sixth argument of `registerPackage', namely `packageDb' In the expression: registerPackage verbosity installedPkgInfo pkg lbi inplace packageDb In a case alternative: _ | modeGenerateRegFile - die Generate Reg File not supported | modeGenerateRegScript - die Generate Reg Script not supported | otherwise - registerPackage verbosity installedPkgInfo pkg lbi inplace packageDb cabal: Error: some packages failed to install: cairo-0.12.0 failed during the configure step. The exception was: ExitFailure 1 gio-0.12.0 depends on glib-0.12.0 which failed to install. glib-0.12.0 failed during the configure step. The exception was: ExitFailure 1 gtk-0.12.0 depends on glib-0.12.0 which failed to install. pango-0.12.0 depends on glib-0.12.0 which failed to install. Resolving dependencies... /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04224/cairo-0.12.0/Gtk2HsSetup.hs:25:0: warning: #warning Setup.hs is guessing the version of Cabal. If compilation of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when building (prefixed by --ghc-option= when using the 'cabal' command) [1 of 2] Compiling Gtk2HsSetup ( /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04224/cairo-0.12.0/Gtk2HsSetup.hs, /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04224/cairo-0.12.0/dist/setup/Gtk2HsSetup.o ) /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/cairo-0.12.04224/cairo-0.12.0/Gtk2HsSetup.hs:201:69: Couldn't match expected type `PackageDBStack' against inferred type `PackageDB' In the sixth argument of `registerPackage', namely `packageDb' In the expression: registerPackage verbosity installedPkgInfo pkg lbi inplace packageDb In a case alternative: _ | modeGenerateRegFile - die Generate Reg File not supported | modeGenerateRegScript - die Generate Reg Script not supported | otherwise - registerPackage verbosity installedPkgInfo pkg lbi inplace packageDb /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04224/glib-0.12.0/Gtk2HsSetup.hs:25:0: warning: #warning Setup.hs is guessing the version of Cabal. If compilation of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when building (prefixed by --ghc-option= when using the 'cabal' command) [1 of 2] Compiling Gtk2HsSetup ( /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04224/glib-0.12.0/Gtk2HsSetup.hs, /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/glib-0.12.04224/glib-0.12.0/dist/setup/Gtk2HsSetup.o )
Re: [Haskell-cafe] Matplotlib analog for Haskell?
On Sat, Jun 4, 2011 at 1:56 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: On 4 June 2011 07:11, Dmitri O.Kondratiev doko...@gmail.com wrote: So, if I got this right, I should run: 'cabal install -fbuildExamples gnuplot' from gnuplot source root folder? You can either get the gnuplot tarball from Hackage, unpack it, and then within the directory do cabal install -fbuildExamples (assuming you want the examples). Or else you can just do cabal install -fbuildExamples gnuplot from anywhere and cabal-install will download it, unpack it, build it, install it and then remove the unpacked tarball. I got the gnuplot tarball from Hackage, unpacked it, and then within the directory do cabal install -fbuildExamples. That's what I get (see below). What else should I do to install gnuplot? Thanks! ~/wks/haskell-wks/gnuplot/gnuplot-0.4.2/srcghc -v Demo.hs Glasgow Haskell Compiler, Version 6.12.3, for Haskell 98, stage 2 booted by GHC version 6.12.2 Using binary package database: /Library/Frameworks/GHC.framework/Versions/612/usr/lib/ghc-6.12.3/package.conf.d/package.cache Using binary package database: /Users/user/.ghc/i386-darwin-6.12.3/package.conf.d/package.cache hiding package Cabal-1.8.0.6 to avoid conflict with later version Cabal-1.10.1.0 hiding package base-3.0.3.2 to avoid conflict with later version base-4.2.0.2 wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-9df3bd825ad17ca739e158c880a25b11 wired-in package integer-gmp mapped to integer-gmp-0.2.0.1-72436e28c79d056c87cc0d2d2f9f3773 wired-in package base mapped to base-4.2.0.2-99442781c4fd10a8c30c35c9ce5fac5c wired-in package rts mapped to builtin_rts wired-in package haskell98 mapped to haskell98-1.0.1.1-4d2891ad99eae334ff8234bcfbddce06 wired-in package template-haskell mapped to template-haskell-2.4.0.1-7f84d967c8ff6750b3d865aff2a093e1 wired-in package dph-seq mapped to dph-seq-0.4.0-1df951f78b4efbc84e2534bab253505d wired-in package dph-par mapped to dph-par-0.4.0-436308af1d9725eae22b56265f6035ec Hsc static flags: -static Created temporary directory: /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/ghc5925_0 *** Checking old interface for main:Main: *** Parser: *** Renamer/typechecker: Demo.hs:25:0: Failed to load interface for `Paths_gnuplot': locations searched: Paths_gnuplot.hi Paths_gnuplot.hi-boot *** Deleting temp files: Deleting: /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/ghc5925_0/ghc5925_0.s Warning: deleting non-existent /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/ghc5925_0/ghc5925_0.s *** Deleting temp dirs: Deleting: /var/folders/Bo/BobN2Ap5GZW51e9o-n2Ack+++TI/-Tmp-/ghc5925_0 ~/wks/haskell-wks/gnuplot/gnuplot-0.4.2/src ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Matplotlib analog for Haskell?
On Sat, Jun 11, 2011 at 12:54 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Sat, 11 Jun 2011, Dmitri O.Kondratiev wrote: That's what I get (see below). What else should I do to install gnuplot? ~/wks/haskell-wks/gnuplot/gnuplot-0.4.2/srcghc -v Demo.hs Do you really want to compile the Demo (with ghc)? It is already compiled if 'cabal install -fbuildExamples' was successful. Maybe you want to run 'ghci' for interactive tests. But you need to tell 'ghci' the path to the Paths module. 'make ghci-demo' should call GHCi with the right options on Linux: $ ghci -Wall -i:src:dist/build/autogen:execute/tmp src/Demo.hs Did I already advertise the gnuplot mailing list? http://projects.haskell.org/cgi-bin/mailman/listinfo/gnuplot/ Yes, you did, thanks. Yet, please allow me to ask a few more questions here, before I subscribe to gnuplot list. I am really short on time - must have some plots for demo next Monday ( 1) Can current version of gnuplot draw histograms? I need these first of all. 2) It seems that $ ghci -Wall -i:src:dist/build/autogen:execute/tmp src/Demo.hs works on Mac OSX, yet I can't make it produce any output directly on screen. How to generate output and display it immediately in an output window? This is what I get: ~/wks/haskell-wks/gnuplot/gnuplot-0.4.2ghci -Wall -i:src:dist/build/autogen:execute/tmp src/Demo.hs GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. [ 1 of 33] Compiling Paths_gnuplot( dist/build/autogen/Paths_gnuplot.hs, interpreted ) [ 2 of 33] Compiling Graphics.Gnuplot.Terminal ( src/Graphics/Gnuplot/Terminal.hs, interpreted ) [ 3 of 33] Compiling Graphics.Gnuplot.Execute ( execute/tmp/Graphics/Gnuplot/Execute.hs, interpreted ) [ 4 of 33] Compiling Graphics.Gnuplot.Utility ( src/Graphics/Gnuplot/Utility.hs, interpreted ) [ 5 of 33] Compiling Graphics.Gnuplot.Private.FrameOption ( src/Graphics/Gnuplot/Private/FrameOption.hs, interpreted ) [ 6 of 33] Compiling Graphics.Gnuplot.Private.FrameOptionSet ( src/Graphics/Gnuplot/Private/FrameOptionSet.hs, interpreted ) [ 7 of 33] Compiling Graphics.Gnuplot.Private.Graph ( src/Graphics/Gnuplot/Private/Graph.hs, interpreted ) [ 8 of 33] Compiling Graphics.Gnuplot.Private.GraphEmpty ( src/Graphics/Gnuplot/Private/GraphEmpty.hs, interpreted ) [ 9 of 33] Compiling Graphics.Gnuplot.Display ( src/Graphics/Gnuplot/Display.hs, interpreted ) [10 of 33] Compiling Graphics.Gnuplot.Private.Plot ( src/Graphics/Gnuplot/Private/Plot.hs, interpreted ) [11 of 33] Compiling Graphics.Gnuplot.Private.Frame ( src/Graphics/Gnuplot/Private/Frame.hs, interpreted ) [12 of 33] Compiling Graphics.Gnuplot.Private.ColorSpecification ( src/Graphics/Gnuplot/Private/ColorSpecification.hs, interpreted ) [13 of 33] Compiling Graphics.Gnuplot.Private.LineSpecification ( src/Graphics/Gnuplot/Private/LineSpecification.hs, interpreted ) [14 of 33] Compiling Graphics.Gnuplot.Value.Tuple ( src/Graphics/Gnuplot/Value/Tuple.hs, interpreted ) [15 of 33] Compiling Graphics.Gnuplot.Value.Atom ( src/Graphics/Gnuplot/Value/Atom.hs, interpreted ) [16 of 33] Compiling Graphics.Gnuplot.Value.ColumnSet ( src/Graphics/Gnuplot/Value/ColumnSet.hs, interpreted ) [17 of 33] Compiling Graphics.Gnuplot.Private.Graph2DType ( src/Graphics/Gnuplot/Private/Graph2DType.hs, interpreted ) [18 of 33] Compiling Graphics.Gnuplot.Private.Graph2D ( src/Graphics/Gnuplot/Private/Graph2D.hs, interpreted ) [19 of 33] Compiling Graphics.Gnuplot.Private.Graph3DType ( src/Graphics/Gnuplot/Private/Graph3DType.hs, interpreted ) [20 of 33] Compiling Graphics.Gnuplot.Private.Graph3D ( src/Graphics/Gnuplot/Private/Graph3D.hs, interpreted ) [21 of 33] Compiling Graphics.Gnuplot.MultiPlot ( src/Graphics/Gnuplot/MultiPlot.hs, interpreted ) [22 of 33] Compiling Graphics.Gnuplot.LineSpecification ( src/Graphics/Gnuplot/LineSpecification.hs, interpreted ) [23 of 33] Compiling Graphics.Gnuplot.Graph.ThreeDimensional ( src/Graphics/Gnuplot/Graph/ThreeDimensional.hs, interpreted ) [24 of 33] Compiling Graphics.Gnuplot.Graph.TwoDimensional ( src/Graphics/Gnuplot/Graph/TwoDimensional.hs, interpreted ) [25 of 33] Compiling Graphics.Gnuplot.Graph ( src/Graphics/Gnuplot/Graph.hs, interpreted ) [26 of 33] Compiling Graphics.Gnuplot.Plot.ThreeDimensional ( src/Graphics/Gnuplot/Plot/ThreeDimensional.hs, interpreted ) [27 of 33] Compiling Graphics.Gnuplot.Plot.TwoDimensional ( src/Graphics/Gnuplot/Plot/TwoDimensional.hs, interpreted ) [28 of 33] Compiling Graphics.Gnuplot.Frame.OptionSet ( src/Graphics/Gnuplot/Frame/OptionSet.hs, interpreted ) [29 of 33] Compiling Graphics.Gnuplot.Frame.Option ( src/Graphics/Gnuplot/Frame/Option.hs, interpreted ) [30 of 33] Compiling Graphics.Gnuplot.Frame ( src/Graphics/Gnuplot/Frame.hs, interpreted ) [31 of 33] Compiling Graphics.Gnuplot.Terminal.X11 ( src
[Haskell-cafe] Generating simple histograms in png format?
I am looking for platform-independent library to generate simple histograms in png format. Does such thing exist? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.List / Map: simple serialization?
Hello, Please advise on existing serialization libraries. I need a simple way to serialize Data.List and Data.Map to plain text files. Thanks, Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.List / Map: simple serialization?
On Thu, Jun 9, 2011 at 11:31 AM, Max Bolingbroke batterseapo...@hotmail.com wrote: If you want plain text serialization, writeFile output.txt . show and fmap read (readFile output.txt) should suffice... Max This is really a simple way that I like, thanks. Do I understand this right, that in this case Haskell run-time will do all the necessary data buffering as needed? I am trying to solve the following task: 1) Parse a log of 30 000 lines where each line is about 200 chars. Parsing includes splitting out of every line two text fields and converting them to GUID. Then build from this log a list of GUIDs and save it for future use in text file. As a result list will have 30 000 integer elements. 2) Read GUID list and traverse it several times from E(s) to E(N), where E(s) - start and E(N) - end elements of traverse, and 's' = [1.. N-1], so I have the following traversals: 1 ...N 2 .. N 3 .. N ... N-1 .. N 3) As a result of this traversal I build a Data.Map holding various pairs of list elements (key) and number of times pair occurs in the list (value). I need to save this map in text file for future use. 4) Read from a text file this map back into Data.Map and build from it another list, save it to text file, etc. I wonder how Haskell will distribute memory between the buffer for sequential element access (list elements, map tree nodes) and memory for computation while reading in list, Data.Map from file? On 9 June 2011 08:23, Dmitri O.Kondratiev doko...@gmail.com wrote: Hello, Please advise on existing serialization libraries. I need a simple way to serialize Data.List and Data.Map to plain text files. Thanks, Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.List / Map: simple serialization?
On Thu, Jun 9, 2011 at 7:23 PM, Max Bolingbroke batterseapo...@hotmail.comwrote: Hi Dmitri, On 9 June 2011 09:13, Dmitri O.Kondratiev doko...@gmail.com wrote: I wonder how Haskell will distribute memory between the buffer for sequential element access (list elements, map tree nodes) and memory for computation while reading in list, Data.Map from file? Your list only has 30,000 elements. From the description of the problem, you traverse the list several times, so GHC will create an in-memory link list that persists for the duration of all the traversals. This is OK, because the number of elements in the list is small. For the construction of the Map, it sounds like in the worst case you will have 30,000*30,000 = 900,000,000 elements in the Map, which you may not want to keep in memory. Assuming show, read and list creation are lazy enough, and as long as you use the Map linearly GHC should be able to GC parts of it to keep the working set small. You should experiment and see what happens. My advice is just write the program the simple way (with show and read, and not worrying about memory) and see what happens. If it turns out that it uses too much memory you can come back to the list with your problematic program and ask for advice. Max Yes, that's what I will try first - simple serialization with show and read, not worrying about memory. Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Matplotlib analog for Haskell?
Hello, Please advise on Haskell 2D plotting libraries to generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc, similar to what Matplotlib does: http://matplotlib.sourceforge.net/ Thanks! Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Matplotlib analog for Haskell?
On Fri, Jun 3, 2011 at 3:44 PM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: On 3 June 2011 21:39, Dmitri O.Kondratiev doko...@gmail.com wrote: Hello, Please advise on Haskell 2D plotting libraries to generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc, similar to what Matplotlib does: http://matplotlib.sourceforge.net/ I was going to list the possible packages but found too many... so search for chart and plot on Hackage: http://hackage.haskell.org/package/ In particular, the Chart, plot and gnuplot libraries probably do what you want (or at least a subset). -- Thanks! I tried gnuplot: GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude import Graphics.Gnuplot.Simple Prelude Graphics.Gnuplot.Simple :l Demo.hs Demo.hs:25:18: Could not find module `Paths_gnuplot': Use -v to see a list of the files searched for. Failed, modules loaded: none. Prelude Graphics.Gnuplot.Simple Where to get `Paths_gnuplot': module? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Matplotlib analog for Haskell?
On Sat, Jun 4, 2011 at 12:55 AM, Henning Thielemann schlepp...@henning-thielemann.de wrote: Malcolm Wallace schrieb: I tried gnuplot: Demo.hs:25:18: Could not find module `Paths_gnuplot': Use -v to see a list of the files searched for. Failed, modules loaded: none. Prelude Graphics.Gnuplot.Simple Where to get `Paths_gnuplot': module? $ cd gnuplot-0.4.2 $ cabal install # this generates the Paths_gnuplot module $ ghci Yes, you must install the package before loading Demo into GHCi, since the package contains a data file that the Demo wants to load. Currently I am trying to interface to gnuplot's histogram feature. You may also to subscribe to http://projects.haskell.org/cgi-bin/mailman/listinfo/gnuplot Thanks! So, if I got this right, I should run: 'cabal install -fbuildExamples gnuplot' from gnuplot source root folder? Yet first I need to build gnupolt for MacOSX and Win32 that I both use. Ok, I'll give it a try... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Please help with double recursion
On Mon, May 30, 2011 at 11:26 AM, Richard O'Keefe o...@cs.otago.ac.nz wrote: On 28/05/2011, at 11:47 PM, Dmitri O.Kondratiev wrote: Hello, I am trying to solve a simple task, but got stuck with double recursion - for some reason not all list elements get processed. Please advice on a simple solution, using plane old recursion :) *** Task: From a sequence of chars build all possible chains where each chain consists of chars that can be accessed from one to another. For example, given the sequence: abcde In table below chars in a left column can access a list of chars in the right column: a | b c d e b | c d e c | d e d | e You have a set S of characters and a binary relation R ⊆ S × S and a chain is a sequence [x0,x1,...] such that x[0] ∈ S and for all i 0, x[i-1] R x[i] Can a chain be empty? What constraints on R do you have that lead you to think that each chain is finite, or are you expecting infinite chains as well? (S = {a}, R = {(a,a)} admits chains of any length, including ones that do not terminate.) Sorry, I missed to specify that char sequences and chains are finite. Every chain is built from chars that can be accessed from one to another. Chars are examined proceeding from the beginning of the sequence to its end, and never in the opposite direction. Going always in one direction and being bound with sequence end, makes chains finite. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Detecting overlay-ed signal patterns
Hello, I am trying to detect signal patterns in a system with numerous signals overlaying each other in time. I am aware that there is a whole class of problem solving methods for this task, yet trying my own algorithm, that may be wrong of course :) Next I use a simple example to describe the problem and my algorithm. Maybe someone will find this problem interesting enough to comment. Thanks in advance! In the following example signals from varying sources are represented by chars - unique signal = unique char. Examples of signal patterns (Pk) to detect: P1 = abcd P2 = 12345 Examples of a mixture of signals (pattern signals are underscored): M1 = s s n a_b_c_d_ r t 6 1_ 2_ 3_ 4_ 5_ 8 7 k l t M2 = g h a_ r 1_ w e 2_ j k b_ c_ l m p 3_ d_ 4_ e r 5_ v x M3 = ... MN = ... In the above examples two patterns P1 and P2 are interleaved with each other and other patterns. All mixtures are recorded for 24 hours for 12 month. One mixture corresponds to one 24 period (day). To find signal patterns in all these mixtures (M1, M2) my algorithm goes through these steps: 1) For every day: For every signal 'Y' create a list of 'weight pairs' such as: (Y, X1, 1), (Y, X2, 1), .. (Y, XN, 1) where X1, X2, ... XN are signals 'accessible from' (or following) signal 'Y' during this day So, for example, given the sequence: abcde, chars in a left column of a table can access a list of chars in the right column: a | b c d e b | c d e c | d e d | e 2) For every signal sum all its 'weight pairs' for all days of the year: W(Y) = Sum((Y, Xk, 1), j=1... 364) For the above example, M1+ M2 will double the value of weight pairs in patterns: P1 = abcd P2 = 12345 such as: (a,b,2) (a,c,2) (a,d,2) (b,c,2) (b,d,2) (b,e,2) (c,d,2) (c,e,2) (d,e,2) and also: (1,2,2) (1,3,2) (1,4,2), (1,5,2) (2,3,2) (2,4,2) (2,5,2) etc... On the other hand, after summation M1+M2, weight pairs for other char sequences, that do not form patterns of often repeated signals, will not increase much. To demonstrate: M_1 and M_2 are sequences with repeating patterns being removed: M_1 = s s n r t 6 8 7 k l t M_2 = g h r w e j k l m p e r v x Here most pair weights will be small, same as before addition: (s,s,2) (g,h,1), (w,e, 1) ... 3) Compute weight of all possible chains in this year. Each chain consists of chars that can be accessed from one to another. Chars are examined, proceeding from the beginning of the sequence to its end, and never in the opposite direction. Going always in one direction and being bound with sequence end, makes chains finite. Chains for 'abcde' example will be: abcde, acde, ade, ae, bcde, bde, be, cde, cd, ce, de Weight of the chain is computed as a sum of its pairs: W(Ci) = Sum(Pj, j=1,..R) where R is a number of pairs that this chain is built from. For example for chain a 'acde' the weight will be: W('acde') = W(a,c)+ W(a,d) + W(a,e) 4) Split chains in groups by its length 5) For each group select chains with maximum weight. With pattern P1 = 'abcd' spread over some signal mixture, my algorithm will find (I hope) the following 4 classes of chains with maximum weight: 1) abcde, acde, ade, ae, 2) bcde, bde, be, 3) cde, cd, ce, 4) de In the same way, chains for pattern P2 = 12345 should be found. Thus, grounding on the idea of 'signal precedence' found in repeating pattern of several signals, and using pair 'weights' to mark signal chains - patterns are detected. Summation of pair weights allows to stress out, or highlight the repeating patterns. Inserting other signals inside a 'pattern pair' does not obscure it because in a long run (after many summations) its weight will make such pair stand out of the crowd. I have not yet fully developed this algorithm and have not tested it on big enough training sets. I hope it will work on training sets exhibiting some regularities - which in this case means repeating patterns. Of course it will not work on randomly generated data, where all pairs have approximately the same weight. Working with pairs and chains will allow for natural parallelism in processing huge sequences of events, I hope. It would be nice to use some analog of Hadoop map-reduce for this task. Any experience with Haskell analog of Apache Hadoop cluster (http://hadoop.apache.org/mapreduce/)? Does such thing exist in Haskell world at all? I would be happy to get criticism of my algorithm and comments on 'route-cause analysis' algorithms in general, thanks! Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Please help with double recursion
Hello, I am trying to solve a simple task, but got stuck with double recursion - for some reason not all list elements get processed. Please advice on a simple solution, using plane old recursion :) *** Task: From a sequence of chars build all possible chains where each chain consists of chars that can be accessed from one to another. For example, given the sequence: abcde In table below chars in a left column can access a list of chars in the right column: a | b c d e b | c d e c | d e d | e Then chains for this example will be: abcde, acde, ade, ae, bcde, bde, be, cde, cd, ce, de *** My incomplete result, which I get running my program (see at the end of this message): ('a','b'),('b','c'),('c','d'),('d','e'), -- abcde, ('c','e'), -- ce, ('b','d'),('d','e'), -- bde, ('b','e') -- be, ('a','c'),('c','d'),('d','e'), -- acde ('c','e'), ('a','d'),('d','e'), -- ade, ('a','e') -- ae Sequence 'abcde' contains 'bcde', 'cde', 'cd', 'de'. How to add all these sub-sequences as a separate sequences in my output? And I have 'ce' sequence duplicated, which I don't need. Also, how to output chains as a list of lists? Such as: [[abcde, acde, ade, ae,] [bcde, bde, be,] [cde, cd, ce,] de]] *** my code test = chains testPairs 'a' [] testPairs = pairs testSeq testSeq = abcde -- From a list of '((from,to),1)' pairs build char chains -- Char chain is a list of chars: [from1, to1 = from2, to2 = from3, to3 = from4, ...] -- 'pairList' - a list of pairs chains pairList from chainList = chainWrk (nextTo pairList from) from chainList where chainWrk [] from chainList = chainList chainWrk (to:tos) from chainList = chainWrk tos from (chains pairList to (chainList ++ [(from,to)])) -- Find direct neighbors for 'from' nextTo pairList from = toList (findPairs pairList from) [] -- From a list of '((from,to),1)' pairs build a list of 'to'-s toList [] tos = tos toList (((from,to),len):ps) tos = toList ps (tos ++ [to]) -- From 'pairList' find elements with 'from' equal to 'start' -- 'pairList' is a list of '((from,to),1)' pairs findPairs pairList search = filter (flt search) pairList where flt search ((from, to), len) = search == from -- From a sequence of chars buid a list of '((from,to),1)' pairs pairs [] = [] pairs (x:xs) = pairWrk x xs [] ++ pairs xs pairWrk hd [] pairLst = pairLst pairWrk hd (x:xs) pairLst = pairWrk hd xs (pairLst ++ [((hd,x),1)]) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Fwd: Please help with double recursion
For some reason, my previous message got truncated, so I repeat it in hope that it will come complete this time: -- Forwarded message -- From: Dmitri O.Kondratiev doko...@gmail.com Date: Sat, May 28, 2011 at 3:47 PM Subject: Please help with double recursion To: haskell-cafe@haskell.org Hello, I am trying to solve a simple task, but got stuck with double recursion - for some reason not all list elements get processed. Please advice on a simple solution, using plane old recursion :) *** Task: From a sequence of chars build all possible chains where each chain consists of chars that can be accessed from one to another. For example, given the sequence: abcde In table below chars in a left column can access a list of chars in the right column: a | b c d e b | c d e c | d e d | e Then chains for this example will be: abcde, acde, ade, ae, bcde, bde, be, cde, cd, ce, de *** My incomplete result, which I get running my program (see at the end of this message): ('a','b'),('b','c'),('c','d'),('d','e'), -- abcde, ('c','e'), -- ce, ('b','d'),('d','e'), -- bde, ('b','e') -- be, ('a','c'),('c','d'),('d','e'), -- acde ('c','e'), ('a','d'),('d','e'), -- ade, ('a','e') -- ae Sequence 'abcde' contains 'bcde', 'cde', 'cd', 'de'. How to add all these sub-sequences as a separate sequences in my output? And I have 'ce' sequence duplicated, which I don't need. Also, how to output chains as a list of lists? Such as: [[abcde, acde, ade, ae,] [bcde, bde, be,] [cde, cd, ce,] de]] *** my code test = chains testPairs 'a' [] testPairs = pairs testSeq testSeq = abcde -- From a list of '((from,to),1)' pairs build char chains -- Char chain is a list of chars: [from1, to1 = from2, to2 = from3, to3 = from4, ...] -- 'pairList' - a list of pairs chains pairList from chainList = chainWrk (nextTo pairList from) from chainList where chainWrk [] from chainList = chainList chainWrk (to:tos) from chainList = chainWrk tos from (chains pairList to (chainList ++ [(from,to)])) -- Find direct neighbors for 'from' nextTo pairList from = toList (findPairs pairList from) [] -- From a list of '((from,to),1)' pairs build a list of 'to'-s toList [] tos = tos toList (((from,to),len):ps) tos = toList ps (tos ++ [to]) -- From 'pairList' find elements with 'from' equal to 'start' -- 'pairList' is a list of '((from,to),1)' pairs findPairs pairList search = filter (flt search) pairList where flt search ((from, to), len) = search == from -- From a sequence of chars buid a list of '((from,to),1)' pairs pairs [] = [] pairs (x:xs) = pairWrk x xs [] ++ pairs xs pairWrk hd [] pairLst = pairLst pairWrk hd (x:xs) pairLst = pairWrk hd xs (pairLst ++ [((hd,x),1)]) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Please help with double recursion
On Sat, May 28, 2011 at 3:57 PM, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Saturday 28 May 2011 13:47:10, Dmitri O.Kondratiev wrote: Hello, I am trying to solve a simple task, but got stuck with double recursion - for some reason not all list elements get processed. Please advice on a simple solution, using plane old recursion :) *** Task: From a sequence of chars build all possible chains where each chain consists of chars that can be accessed from one to another. For example, given the sequence: abcde In table below chars in a left column can access a list of chars in the right column: a | b c d e b | c d e c | d e d | e Then chains for this example will be: abcde, acde, ade, ae, bcde, bde, be, cde, cd, ce, de I think import Data.List -- pair the first element with all later elements pairsFrom :: [a] - [(a,a)] pairsFrom (x:xs) = [(x,y) | y - xs] pairsFrom [] = [] -- pair each element with all later ones allPairs :: [a] - [(a,a)] allPairs xs = tails xs = pairsFrom -- alternative implementation with exlicit recursion: allPairs (x:xs) = pairsFrom (x:xs) ++ allPairs xs allPairs [] = [] Prelude Data.List allPairs abcde [('a','b'),('a','c'),('a','d'),('a','e'),('b','c'),('b','d'),('b','e'), ('c','d'),('c','e'),('d','e')] does what you want Thanks for simple and beautiful code to get all pairs. Yet, I need to get to the next step - from all pairs to build all chains, to get as a result a list of lists: [[abcde, acde, ade, ae,] [bcde, bde, be,] [cde, cd, ce,] de]] This is where I got stuck. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?
Hello, I am looking for a site providing on-line automatic judge for Programming Challenges that can be coded in Haskell. For example this site: http://www.programming-challenges.com provides lots of interesting programming provlems: http://www.programming-challenges.com/pg.php?page=index Yet, unfortunately only C, C++ and Java code can be submitted, judge on that site can't compile and run Haskell code. Is there any similar online judge for Haskell? Thanks, Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Programming Chalenges: The 3n+1 problem
3n+1 is the first, warm-up problem at Programming Chalenges site: http://www.programming-challenges.com/pg.php?page=downloadproblemprobid=110101format=html (This problem illustrates Collatz conjecture: http://en.wikipedia.org/wiki/3n_%2B_1#Program_to_calculate_Collatz_sequences ) As long as the judge on this site takes only C and Java solutions, I submitted in Java some add-hock code (see at the end of this message) where I used recursion and a cache of computed cycles. Judge accepted my code and measured 0.292 sec with best overall submissions of 0.008 sec to solve the problem. *** Question: I wonder how to implement cache for this problem in Haskell? At the moment, I am not so much interested in the speed of the code, as in nice implementation. To illustrate my question I add the problem description and my Java solution at the end of this message. Thanks! *** Problem Consider the following algorithm to generate a sequence of numbers. Start with an integer *n*. If *n* is even, divide by 2. If *n* is odd, multiply by 3 and add 1. Repeat this process with the new value of *n*, terminating when *n* = 1. For example, the following sequence of numbers will be generated for *n* = 22: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is *conjectured* (but not yet proven) that this algorithm will terminate at *n* = 1 for every integer *n*. Still, the conjecture holds for all integers up to at least 1, 000, 000. For an input *n*, the *cycle-length* of *n* is the number of numbers generated up to and *including* the 1. In the example above, the cycle length of 22 is 16. Given any two numbers *i* and *j*, you are to determine the maximum cycle length over all numbers between *i* and *j*, *including* both endpoints. InputThe input will consist of a series of pairs of integers *i* and *j*, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0. OutputFor each pair of input integers *i* and *j*, output *i*, *j* in the same order in which they appeared in the input and then the maximum cycle length for integers between and including *i* and *j*. These three numbers should be separated by one space, with all three numbers on one line and with one line of output for each line of input. Sample Input 1 10 100 200 201 210 900 1000 Sample Output 1 10 20 100 200 125 201 210 89 900 1000 174 *** my Java solution import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { final static BufferedReader reader_ = new BufferedReader(new InputStreamReader(System.in)); /** * @param args */ public static void main(String[] args) { new Problem().run(); } static String[] ReadLn() { String[] tokens = null; try { String line = reader_.readLine(); String REGEX_WHITESPACE = \\s+; String cleanLine = line.trim().replaceAll(REGEX_WHITESPACE, ); tokens = cleanLine.split(REGEX_WHITESPACE); } catch (Exception e) {} return tokens; } } class Problem implements Runnable { long CACHE_SIZE = 65536; private final long[] cache_ = new long[(int) CACHE_SIZE]; /** * Compute cycle length for a single number * * @param n number for which we find cycle length * @return cycle length */ long cycleLen(long n) { long len = 1; if (n != 1) { len = getFromCache(n); if (len == 0) { //not yet in cache // Recursively compute and store all intermediate values of cycle length if ((n 1) == 0) { len = 1 + cycleLen(n 1); } else { len = 1 + cycleLen(n * 3 + 1); } putInCache(n, len); } } return len; } void putInCache(long n, long len) { if(n CACHE_SIZE) { cache_[(int)n] = len; } } long getFromCache(long n) { long result = 0; if(n CACHE_SIZE) { result = cache_[(int)n]; } return result; } /** * Find max cycle on interval * * @param from interval start * @param to interval end * @return max cycle */ Long maxCycle(Long from, Long to) { Long result = 0L; Long cycle = 0L; // Get all values of cycle length on the interval and put these values into a sorted set
[Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?
Angel de Vicente wrote: On 14/04/11 10:29, Dmitri O.Kondratiev wrote: * I am looking for a site providing on-line automatic judge for ** Programming Challenges that can be coded in Haskell. ** For example this site: ** http://www.programming-challenges.com ** provides lots of interesting programming provlems: ** http://www.programming-challenges.com/pg.php?page=index * * Yet, unfortunately only C, C++ and Java code can be submitted, judge on ** that site can't compile and run Haskell code. ** Is there any similar online judge for Haskell? * You can try http://www.spoj.pl/ Cheers, Ángel Angel, thanks! This site looks good. Do you know if spoj.pl has a search utility for problems? It would be great if they have 3n+1 problem I wrote about in a separate thread here. -- All the best, Dmitri O. Kondratiev This is what keeps me going: discovery doko...@gmail.com http://sites.google.com/site/dokondr/welcome ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem
Thanks, Felipe! Sure I will try to code solution myself. Doing it all by yourself is the main fun of everything, isn't it? I was just asking about the *idea* of implementing cache in Haskell, in general, not just in this case only. On Thu, Apr 14, 2011 at 3:11 PM, Felipe Almeida Lessa felipe.le...@gmail.com wrote: This is very similar to the Problem 14 on Project Euler [1]. Should you really want a nice solution in Haskell, and noting that this is a big spoiler, there are some on the wiki [2]. But I highly recommend you to try coding your own solutions before looking at the site =). Cheers! [1] http://projecteuler.net/index.php?section=problemsid=14 [2] http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14 -- Felipe. -- All the best, Dmitri O. Kondratiev This is what keeps me going: discovery doko...@gmail.com http://sites.google.com/site/dokondr/welcome ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem
Thanks, everybody! Your feedback is a great food for my mind (as Lewis Carroll once wrote :) When asking how to implement cache in Haskell I was hopping that there exists some solution without using Data.Array, more functional approach, if I may say so ... I must be wrong, though (need more time to fully comprehend solution that Steven described in this thread ). On Thu, Apr 14, 2011 at 3:22 PM, Ryan Ingram ryani.s...@gmail.com wrote: So if we were to emulate your Java solution, we'd do import Data.Array cacheSize :: Int cacheSize = 65536 table :: Array Int Integer table = listArray (1,cacheSize) (1 : map go [2..cacheSize]) where go n | even n = 1 + lookup (n `div` 2) | otherwise = 1 + lookup (3 * n + 1) lookup :: Integer - Integer lookup n | n cacheSize = table ! (fromInteger n) | even n = 1 + lookup (n `div` 2) | otherwise = 1 + lookup (3 * n + 1) The rest of the code is just some simple i/o. The table is filled up lazily as you request values from it. -- All the best, Dmitri O. Kondratiev This is what keeps me going: discovery doko...@gmail.com http://sites.google.com/site/dokondr/welcome ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Tools to make tidy HTML
Hello! Please advise haskell libraries similar to convert real-world HTML to well-formed XML. I need something similat to HTML Tidy library: http://tidy.sourceforge.net/ Thanks! Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
Daniel, thanks! I used your advice, it works, yet some more questions, if you don't mind :) So: {-- Why showList returns a function of type: type ShowS = String - String In fact showList returns a function which already contains all values from list converted to a single string. Why return function instead of a ready to use string? --} data ShipInfo = Ship { name :: String, kind :: String, cannons :: Int } s1 = Ship {name =HMS Fly, kind = sloop, cannons=16} s2 = Ship {name =HMS Surprise, kind = frigate, cannons=42} fleet = [s1,s2] instance Show ShipInfo where show x = Ship ++ show (name x) ++ is a ++ show(kind x) ++ with ++ show (cannons x) ++ cannons showList xs = showString (foldr (\x y - x ++ * ++y) [] (map show xs)) {-- Now when I type 'fleet' I get: *ShowFleet fleet Ship HMS Fly is a sloop with 16 cannons * Ship HMS Surprise is a frigate with 42 cannons * *ShowFleet On the other hand evaluating t2 : --} t2 xs = foldr (\x y - x ++ * ++y) [] (map show xs) {-- provides: *ShowFleet t2 fleet Ship \HMS Fly\ is a \sloop\ with 16 cannons * Ship \HMS Surprise\ is a \frigate\ with 42 cannons * *ShowFleet More questions: 1)Where characters \ come from in this case? 2)How showList function 'removes' characters \ from the output? What magic goes behind the scenes here? --} Thanks! Dmitri On 12/6/08, Daniel Fischer [EMAIL PROTECTED] wrote: Am Samstag, 6. Dezember 2008 00:13 schrieb Dmitri O.Kondratiev: Thanks everybody for your help! I tried to implement showList, but get the same error: {-- -- from Prelude: type *ShowS* = Stringfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3ASt ring- Stringfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3ASt ring *showList* :: [a] - ShowSfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3ASho wS --} myShows::ShowS myShows s = s ++ \n data ShipInfo = Ship { name :: String, kind :: String, canons :: Int } deriving Show No, if you derive the Show instance for ShipInfo, it automatically implements the standard showList, too. You have to do it yourself: data ShipInfo = Ship { name :: String, kind :: String, canons :: Int } instance Show ShipInfo where showsPrec p (Ship name kind canons) = ... showList xs = showString (unlines $ map show xs) or whatever you want for showList. However, somebody said it before, the Show instance should not be used for pretty-printing. -- I get this error again: instance (Show [ShipInfo]) where showList [] = myShows [] showList (x:xs) = myShows x ++ showList xs Illegal instance declaration for `Show [ShipInfo]' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `Show [ShipInfo]' Failed, modules loaded: none. -- What am I doing wrong? Thanks! -- Haste makes waste - Lose not a moment! Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
On Fri, Dec 5, 2008 at 1:29 AM, Martijn van Steenbergen [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev wrote: -- How to define Show [MyType] ? Define instance Show MyType and implement not only show (for 1 value of MyType) but also showList, which Show provides as well. You can do all the magic in there. HTH, Martijn. Thanks everybody for your help! I tried to implement showList, but get the same error: {-- -- from Prelude: type *ShowS* = Stringfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3AString- Stringfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3AString *showList* :: [a] - ShowSfile:///C:/usr/ghc-6.6.1/doc/html/libraries/base/Prelude.html#t%3AShowS --} myShows::ShowS myShows s = s ++ \n data ShipInfo = Ship { name :: String, kind :: String, canons :: Int } deriving Show -- I get this error again: instance (Show [ShipInfo]) where showList [] = myShows [] showList (x:xs) = myShows x ++ showList xs Illegal instance declaration for `Show [ShipInfo]' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `Show [ShipInfo]' Failed, modules loaded: none. -- What am I doing wrong? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to define Show [MyType] ?
I am trying to define instance Show[MyType] so show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by \n. This would allow pretty printing of MyType list in several lines instead of one, as default Show does for lists. For example: data ShipInfo = Ship { name :: String, kind :: String, canons :: Int } deriving Show s1 = Ship {name =HMS Fly, kind = sloop, canons=16} s2 = Ship {name =HMS Surprise, kind = frigate, canons=42} -- Yet when I try to define: instance (Show ShipInfo) = Show [ShipInfo] where show (x:xs) = ++ show x ++ ++ show xs -- I get this error: Illegal instance declaration for `Show [ShipInfo]' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `Show [ShipInfo]' Failed, modules loaded: none. -- On the other hand this definition: instance (Show a) = Show [a] where show (x:xs) = ++ show x ++ ++ show xs -- Gives a different error: Duplicate instance declarations: instance (Show a) = Show [a] -- Defined at C:/wks/haskell-wks/ShowMatrix.hs:37:0 instance (Show a) = Show [a] -- Defined in GHC.Show Failed, modules loaded: none. -- Note the last error implicitly tells us that defining Show [a] is possible in principle! -- In fact it already defined in GHC.Show !!! -- How to define Show [MyType] ? Thanks! Dmitri ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] SOEGraphics in GHC?
Please help, to locate in GHC distribution SOEGraphics library from Paul Hudak, book The Haskell School of Expression (http://www.haskell.org/soe/ ) Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to use Unicode strings?
Please advise how to write Unicode string, so this example would work: main = do putStrLn Les signes orthographiques inclus les accents (aigus, grâve, circonflexe), le tréma, l'apostrophe, la cédille, le trait d'union et la majuscule. I get the following error: hello.hs:4:68: lexical error in string/character literal (UTF-8 decoding error) Failed, modules loaded: none. Prelude Also, how to read Unicode characters from standard input? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: Replacing substring?
Ronald, Your algoritm is more simple and so it is better, I agree. My algorithm is different and consists of two steps: 1) Split source string into a list of chunks not containing substring to be replaced. 2) Concatenate chunks inserting new substring in between chuncks. With this approach I get a 'bonus' function of spliting string into chunks :) * Tue Jul 22 16:38:53 EDT 2008 **Ronald Guida* oddron at gmail.comhaskell-cafe%40haskell.org?Subject=%5BHaskell-cafe%5D%20Newbie%3A%20Replacing%20substring%3FIn-Reply-To=53396d9e0807220921o74630a51ub435420f37f21bf9%40mail.gmail.comwrote: * * If I want to replace a substring in a string, then I would search my string left to right, looking for any occurrence of the substring. If I find such an occurrence, I would replace it and continue searching from immediately after the replacement. This algorithm can be directly expressed in Haskell. More efficient algorithms do exist. replaceStr :: String - String - String - String replaceStr [] old new = [] replaceStr str old new = loop str where loop [] = [] loop str = let (prefix, rest) = splitAt n str in if old == prefix-- found an occurrence? then new ++ loop rest -- yes: replace it else head str : loop (tail str) -- no: keep looking n = length old On Tue, Jul 22, 2008 at 8:21 PM, Dmitri O.Kondratiev [EMAIL PROTECTED] wrote: Roberto thanks! Shame on me, to post code without enough testing :( Yet, thanks to your comments *I think* I have found the bugs you wrote about and now my code works, please see corrected version below. Extra substring at the end was a result of using foldr with initial element of []. I fixed this with foldl and first chunk as its initial element. Incomplete substitution in case of duplicate elements in the pattern was a bug in my 'takeOut' function that I have also fixed. Stiil the problem that I have not yet designed solution for is when a substring to replace extends from the end of a string to the next string. In other words - first part of substring ends the first string and second part of substring starts the second string. My algorithm currently does not account for such a case. On the side: The more I use Haskell - the more I like it ! It helps me think about the problem I solve much more clearly then when I use imperative language. Corrected code: -- replace all occurances of 123 with 58 in a string: test = replStr abc123def123gh123ikl 123 58 {-- In a string replace all occurances of an 'old' substring with a 'new' substring --} replStr str old new = foldl ((\newSub before after - before ++ newSub ++ after) new) firstChunk otherChunks where chunks = splitStr str old firstChunk = head chunks otherChunks = tail chunks {-- Split string into a list of chunks. Chunks are substrings located in a string between 'sub' substrings --} splitStr str sub = mkChunkLst str sub [] where -- mkChunkLst 'src string' 'substr-to-extract' 'list of chunks' -- makes list of chunks located between 'substr-to-extract' pieces in src string mkChunkLst [] _ chunkLst = chunkLst mkChunkLst str sub chunkLst = mkChunkLst after sub (chunkLst ++ [chunk]) where (chunk, _, after) = takeOut str sub [] [] {-- Take out substring from a string. String is divided into: before substr ++ match ++ after substr where 'match' is substring to split out --} takeOut after [] before match = (before, match, after) takeOut [] _ before match = (before, match, []) takeOut (x:xs) (y:ys) before match | x == y = takeOut xs ys before (match ++ [x]) | otherwise = takeOut xs (y:ys) (before ++ [x]) [] On Tue, Jul 22, 2008 at 7:39 PM, Roberto Zunino [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev wrote: I wrote my own version, please criticize: -- replace all occurances of 123 with 58 in a string: test = replStr abc123def123gh123ikl 123 58 This is a tricky problem: first of all, you fail your own test! ;-) *Main test abc58def58gh58ikl58 (Note the extra 58 at the end.) Other common pitfalls: *Main replStr abc1123def 123 58 abc1158def58 (extra 1 ?) *Main replStr abc12123def 123 58 abc121258def58 (extra 12 ?) A useful function from Data.List: stripPrefix (Of course, there are more efficient string match algorithms) Regards, Zun. -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Newbie: Replacing substring?
A few simple questions: What standard library function can be used to replace substring in a string (or sub-list in a list) ? I wrote my own version, please criticize: -- replace all occurances of 123 with 58 in a string: test = replStr abc123def123gh123ikl 123 58 {-- In a string replace all occurances of an 'old' substring with a 'new' substring --} replStr str old new = foldr ((\newSub before after - before ++ newSub ++ after) new) [] chunks where chunks = splitStr str old {-- Split string into a list of chunks. Chunks are substrings located in a string between 'sub' substrings --} splitStr str sub = mkChunkLst str sub [] where -- mkChunkLst 'src string' 'substr-to-extract' 'list of chunks' -- makes list of chunks located between 'substr-to-extract' pieces in src string mkChunkLst [] _ chunkLst = chunkLst mkChunkLst str sub chunkLst = mkChunkLst after sub (chunkLst ++ [chunk]) where (chunk, _, after) = takeOut str sub [] [] {-- Take out substring from a string. String is divided into: before substr ++ match ++ after substr where 'match' is substring to split out --} takeOut after [] before match = (before, match, after) takeOut [] _ before match = (before, match, []) takeOut (x:xs) (y:ys) before match | x == y = takeOut xs ys before (match ++ [x]) | otherwise = takeOut xs (y:ys) (before ++ match ++ [x]) [] -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: Replacing substring?
Roberto thanks! Shame on me, to post code without enough testing :( Yet, thanks to your comments *I think* I have found the bugs you wrote about and now my code works, please see corrected version below. Extra substring at the end was a result of using foldr with initial element of []. I fixed this with foldl and first chunk as its initial element. Incomplete substitution in case of duplicate elements in the pattern was a bug in my 'takeOut' function that I have also fixed. Stiil the problem that I have not yet designed solution for is when a substring to replace extends from the end of a string to the next string. In other words - first part of substring ends the first string and second part of substring starts the second string. My algorithm currently does not account for such a case. On the side: The more I use Haskell - the more I like it ! It helps me think about the problem I solve much more clearly then when I use imperative language. Corrected code: -- replace all occurances of 123 with 58 in a string: test = replStr abc123def123gh123ikl 123 58 {-- In a string replace all occurances of an 'old' substring with a 'new' substring --} replStr str old new = foldl ((\newSub before after - before ++ newSub ++ after) new) firstChunk otherChunks where chunks = splitStr str old firstChunk = head chunks otherChunks = tail chunks {-- Split string into a list of chunks. Chunks are substrings located in a string between 'sub' substrings --} splitStr str sub = mkChunkLst str sub [] where -- mkChunkLst 'src string' 'substr-to-extract' 'list of chunks' -- makes list of chunks located between 'substr-to-extract' pieces in src string mkChunkLst [] _ chunkLst = chunkLst mkChunkLst str sub chunkLst = mkChunkLst after sub (chunkLst ++ [chunk]) where (chunk, _, after) = takeOut str sub [] [] {-- Take out substring from a string. String is divided into: before substr ++ match ++ after substr where 'match' is substring to split out --} takeOut after [] before match = (before, match, after) takeOut [] _ before match = (before, match, []) takeOut (x:xs) (y:ys) before match | x == y = takeOut xs ys before (match ++ [x]) | otherwise = takeOut xs (y:ys) (before ++ [x]) [] On Tue, Jul 22, 2008 at 7:39 PM, Roberto Zunino [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev wrote: I wrote my own version, please criticize: -- replace all occurances of 123 with 58 in a string: test = replStr abc123def123gh123ikl 123 58 This is a tricky problem: first of all, you fail your own test! ;-) *Main test abc58def58gh58ikl58 (Note the extra 58 at the end.) Other common pitfalls: *Main replStr abc1123def 123 58 abc1158def58 (extra 1 ?) *Main replStr abc12123def 123 58 abc121258def58 (extra 12 ?) A useful function from Data.List: stripPrefix (Of course, there are more efficient string match algorithms) Regards, Zun. -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] win32: haddock: internal Haddock or GHC error?
Using GHC 6.8.2 and haddock 2.0.0.0. in WinXP (SP3) I am trying to follow instructions from How to write a Haskell programhttp://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program#Build_some_haddock_documentation . Everything goes well, until I try to generate html documentation for the project. Then I get the following errors: C:\wks\haqrunhaskell Setup.lhs haddock --executables Preprocessing executables for haq-0.0... Running Haddock for haq-0.0... Preprocessing executables for haq-0.0... Warning: Cannot read C:/usr/ghc-6.8.2/doc/libraries/base\base.haddock: Magic number mismatch: couldn't load interface file: C:/usr/ghc-6.8.2/doc/li braries/base\\base.haddock Skipping this interface. Warning: main:Main: could not find link destinations for: GHC.IOBase.IO haddock: internal Haddock or GHC error: c:/builds/haddock-2/install\haddock-2.0. 0.0/html/haddock.css: openFile: does not exist (No such file or directory) Any ideas how to solve this? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] win32: haddock: internal Haddock or GHC error?
Neil, Thanks for the quick response! I got haddock from its site ( http://haskell.org/haddock/#Download )using the link that says: Windows: a binary distribution http://haskell.org/haddock/dist/haddock-2.0.0.0-Win32.zip is available, just unzip and go. My configuration: C:\wks\haqrunhaskell Setup.lhs configure -v Configuring haq-0.0... Dependency base-any: using base-3.0.1.0 Using compiler: ghc-6.8.2 Using install prefix: C:\Program Files\Haskell Binaries installed in: C:\Program Files\Haskell\bin Libraries installed in: C:\Program Files\Haskell\haq-0.0\ghc-6.8.2 Private binaries installed in: C:\Program Files\Haskell\haq-0.0 Data files installed in: C:\Program Files\Haskell\haq-0.0 Documentation installed in: C:\Program Files\Haskell\doc\haq-0.0 No alex found Using ar found on system at: C:\usr\ghc-6.8.2\bin\ar.exe No c2hs found No cpphs found No ffihugs found Using ghc version 6.8.2 found on system at: C:\usr\ghc-6.8.2\bin\ghc.exe Using ghc-pkg version 6.8.2 found on system at: C:\usr\ghc-6.8.2\bin\ghc-pkg.exe No greencard found Using haddock version 2.0.0.0 found on system at: C:\usr\haddock\haddock.exe No happy found No hmake found Using hsc2hs version 0.66-ghc found on system at: C:\usr\ghc-6.8.2\bin\hsc2hs.ex e No hscolour found No hugs found No jhc found Using ld found on system at: C:\usr\ghc-6.8.2\gcc-lib\ld.exe No nhc98 found No pfesetup found No pkg-config found No ranlib found No tar found On Wed, Jul 16, 2008 at 4:45 PM, Neil Mitchell [EMAIL PROTECTED] wrote: Hi Dmitri, How did you obtain Haddock 2.0? Did you download it off hackage and install it, using the standard cabal bits? Can you also do runhaskell Setup configure -v, so we can see which Haddock Cabal is attempting to use. Thanks Neil C:\wks\haqrunhaskell Setup.lhs haddock --executables Preprocessing executables for haq-0.0... Running Haddock for haq-0.0... Preprocessing executables for haq-0.0... Warning: Cannot read C:/usr/ghc-6.8.2/doc/libraries/base\base.haddock: Magic number mismatch: couldn't load interface file: C:/usr/ghc-6.8.2/doc/li braries/base\\base.haddock Skipping this interface. Warning: main:Main: could not find link destinations for: GHC.IOBase.IO haddock: internal Haddock or GHC error: c:/builds/haddock-2/install\haddock-2.0. 0.0/html/haddock.css: openFile: does not exist (No such file or directory) Any ideas how to solve this? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: Appending arrays?
I don't quite understand how Data.Array.Diff work. I tried this: let arr = listArray (1,3) [1..3] :: DiffArray Int Int then: replaceDiffArray arr [(1, 777)] array (1,3) [(1,1),(2,777),(3,3)] Why when replacing first element the second one changes? and also trying to add 4-th element results in: Prelude Data.Array.Diff replaceDiffArray arr [(4, 444)] array (1,3) [(1,1),(2,2),(3,3)] It looks like replaceDiffArray can not be used to add new element to the end of array? Thanks, Dima On Thu, Jul 10, 2008 at 10:59 PM, Jefferson Heard [EMAIL PROTECTED] wrote: Two questions. How often does the array change, and how big does it get? It may well be that you just copy it and take the hit, as that'll be cheaper (even in C, incidentally) than any other solution, if it's a short array or if the updates happen rarely. If not, try using Data.Array.Diff and replaceDiffArray. This is usually fairly efficient for most applications. By the way, depending on the type of the data you're putting into these arrays, Data.ByteString might be a good choice as well. On Thu, Jul 10, 2008 at 12:12 PM, Felipe Lessa [EMAIL PROTECTED] wrote: 2008/7/10 Dmitri O.Kondratiev [EMAIL PROTECTED]: allows construct an array of a fixed size. How to add more elements to the array later? I can't really answer your question, however I bet that it would require allocating another, bigger array and copying the old elements over, at least from time to time. So you may want to take a look at Data.Sequence[1], supporting O(1) append on both sides and (sort of) O(log i) for accessing the i-th element. [1] http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Sequence.html HTH, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- I try to take things like a crow; war and chaos don't always ruin a picnic, they just mean you have to be careful what you swallow. -- Jessica Edwards ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: Appending arrays?
How does Data.Sequence http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Sequence.html compares with ArrayRef for appending and accessing arrays efficiently ? On Fri, Jul 11, 2008 at 4:58 PM, Chaddaï Fouché [EMAIL PROTECTED] wrote: 2008/7/11 Dmitri O.Kondratiev [EMAIL PROTECTED]: I don't quite understand how Data.Array.Diff work. I tried this: let arr = listArray (1,3) [1..3] :: DiffArray Int Int then: replaceDiffArray arr [(1, 777)] array (1,3) [(1,1),(2,777),(3,3)] Why when replacing first element the second one changes? replaceDiffArray is low-level, nobody should use it, use the normal IArray interface instead. (To answer your question, replaceDiffArray works with low level index, not the Ix class, all array are indexed by 0, 1, .. for it, so 1 is the index of the second element of the array) and also trying to add 4-th element results in: Prelude Data.Array.Diff replaceDiffArray arr [(4, 444)] array (1,3) [(1,1),(2,2),(3,3)] It looks like replaceDiffArray can not be used to add new element to the end of array? No, the size of a DiffArray can't be changed : DiffArray are just an IArray instance with better performances for update than the classic IArray instance (which copy the entire content on every update...). There are some libraries that allows you to change the size of your array, be aware though that this operation is very costly (in every language). http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ArrayRef -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: Appending arrays?
I need extendable array to store and count unique vectors. I have a file containing vectors presented as strings like: 10, 6, 80, 25, 6, 7 1, 2, 15, 17, 33, 22 21, 34, 56, 78, 91, 2 ... (BTW, what is the best library function to use to convert string of digits into a list or array?) There are two arrays: 1) Array of unique vectors. The first vector red from file starts this array. Next vectors are added to this array if they are sufficiently dissimilar from the already existing in the array. Similarity is computed as euclidean distance between two vectors. 2) Array of counts. Length of this array is equal to the length of array with unique vectors. Thus every vector has a corresponding count. If new vector is similar to some vector already existing in the first array then corresponding count is incremented. For example, array of unique vectors: [[10, 6, 80, 25, 6, 7], [1, 2, 15, 17, 33, 22], [21, 34, 56, 78, 91, 2]] may have a corresponding counts array: [5,1,3] where: 5 tells that my file has 5 vectors similar to vector [10, 6, 80, 25, 6, 7], Only 1 vector [1, 2, 15, 17, 33, 22], and 3 vectors similar to [21, 34, 56, 78, 91, 2] As long as I don't know a priory how many unique vectors my file has, as well as how many similar to these unique others exists - I need to start both arrays with size 0. Next when I find a similar vector I need to increment count at corresponding index in 'counts' array. I will also need to access vectors at different index in unique array later. That's why I need a collection both indexed and able to extend also. I think that Data.Sequence will do for the task, don't you think? On Fri, Jul 11, 2008 at 7:23 PM, Chaddaï Fouché [EMAIL PROTECTED] wrote: 2008/7/11 Dmitri O.Kondratiev [EMAIL PROTECTED]: How does Data.Sequence http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Sequence.html compares with ArrayRef for appending and accessing arrays efficiently ? It doesn't since Data.Sequence doesn't use arrays, it uses a custom data structure that allows to do plenty of operations with pretty good asymptotic complexity. Be aware though that the constants aren't that good and that depending on your usage, lists, array or another specialized data structure could be much more efficient. By comparisons, extending an array is very likely to be much more expensive from time to time than adding some elements to your Data.Sequence. On the other hand the random access would be much faster in an array and even the amortized cost of extending the array may not be much worse than the amortized cost on the Data.Sequence in some cases. What exactly are you trying to do ? -- Jedaï -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: Appending arrays?
Thanks for your help, guys! I like simple solutions most of all :) On Fri, Jul 11, 2008 at 9:44 PM, Reid Barton [EMAIL PROTECTED] wrote: This doesn't require any fancy data structures. Instead store this as a list of pairs [([10,6,80,25,6,7], 5), ...] and it'll be easy to write a recursive function that accepts a new vector and either increments the appropriate count or adds the new vector at the end with count 1. On Fri, Jul 11, 2008 at 11:32 PM, Dan Weston [EMAIL PROTECTED] wrote: If you don't need to do error checking on the input syntax, the easiest (and arguably fastest) method is just read: Prelude let x = 10, 6, 80, 25, 6, 7 Prelude read ([ ++ x ++ ]) :: [Int] [10,6,80,25,6,7] For error checking, you can use reads. -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Newbie: Appending arrays?
What is the best way to extend array? I would use a list instead of array as it is easy to append, but need to have random access to its elements later. So in fact I need to start with an integer array of size 1. Next I may need to add new elements to this array or modify values of the existing ones. Function: array :: (Ix a) = (a,a) - [(a,b)] - Array a b allows construct an array of a fixed size. How to add more elements to the array later? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Newbie Q: Overloading and type classes
{-- I try to define class Store that will group types implmenting different storage mechanisms . All types should support two functions: 1) put (key, value) pair into storage 2) get value from storage corresponding to the given key As an example I start with the following storage types: --} -- simple memory cell data OneCell k v = Cell(k, v) -- list of cells data CellList k v = CLst [(k, v)] {-- First, without grouping these types into any class, just to illustrate what these types should do, I define the following functions: --} {-- put::(k, v) - OneCell k v - OneCell k v put (k1, v1) (Cell(k, v)) = Cell(k1, v1) get :: Eq k = k - OneCell k v - Maybe v get k (Cell (_, v)) = Just v c1 ::OneCell String Int c1 = Cell(one, 1) putLst :: (k,v) - CellList k v - CellList k v putLst (k,v) (CLst xs) = CLst ((k,v) : xs) getLst :: Eq k = k - CellList k v - Maybe v getLst k (CLst xs) = lookup k xs cl1 = CLst [(one,1),(two,2),(three,3)] --} {-- These work as expected. Now I try to define Store class that should allow me to overload put get functions: --} class Store s where put :: Eq k = (k, v) - s - s get :: k s - Maybe v {-- instance Store OneCell where put (k1, v1) (Cell(k, v)) = Cell(k1, v1) get k (Cell (_, v)) = Just v --} {-- I get the following error: `OneCell' is not applied to enough type arguments Expected kind `*', but `OneCell' has kind `* - * - *' In the instance declaration for `Store OneCell' --} instance Store CellList where put (k,v) (CLst xs) = CLst ((k,v) : xs) get k (CLst xs) = lookup k xs {-- I get the following error: `CellList' is not applied to enough type arguments Expected kind `*', but `CellList' has kind `* - * - *' In the instance declaration for `Store CellList' --} What should I do to create Store class? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Q: Overloading and type classes
{-- Thanks! Yes, you got it right - I want to make explicit the fact that the type s depends on k and v. So I followed your advice and used the most simple way to do what I need: --} class Store s where put :: Eq k = (k, v) - s k v - s k v get :: Eq k = k - s k v - Maybe v instance Store OneCell where put (k1, v1) (Cell(k, v)) = Cell(k1, v1) get k (Cell (_, v)) = Just v instance Store CellList where put (k,v) (CLst xs) = CLst ((k,v) : xs) get k (CLst xs) = lookup k xs storePut :: (Store s, Eq k) = s k v - k - v - s k v storePut store key value = put (key, value) store storeGet :: (Store s, Eq k) = k - s k v - Maybe v storeGet key store = get key store aCell :: OneCell String Int aCell = Cell(one, 1) lst :: CellList Int String lst = CLst [(1, one),(2, two),(3, three)] st1 = storePut aCell two 2 st2 = storePut lst 4 four -- v1 = storeGet one st2 -- error v2 = storeGet one st1 -- ok {-- And what does the word newbie imply to you when answering my question? In what case using 'fundeps' and 'associated types' will make sence for this example? --} Thanks again for your great help! Dima On Sat, Jun 7, 2008 at 11:11 PM, Luke Palmer [EMAIL PROTECTED] wrote: Oops. Should be: get :: k - s k v - Maybe v And correspondingly for the later examples. After actually using my brain thinking about your problem, and reading the word Newbie, I would absolutely stay away from the fundeps/associated types business. :-) Try to get this working with Cell and CellList first :-) Luke If instead you have cell types which are restricted in what they can store in different ways, you might explore fundeps or associated types: -- fundeps class Store s k v | s - k v where put :: (k,v) - s - s get :: s - Maybe v -- associated types class Store s where type Key s :: * type Value s :: * put :: (Key s, Value s) - s - s get :: s - Maybe (Value s) But if you can get away with the former, I would recommend that before looking into these advanced extensions. Luke -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: State monad example questions
Thanks everybody for your help! Oliver, you provided an excellent write-up on State monad without going into 'scary' :) details, great work indeed! Alas, in this case I need the details, and in particular the most scary ones! So let's start with fundamental and most intriguing (to me) things: getAny :: (Random a) = State StdGen a getAny = do g - get -- magically get the current StdGen First line above declares a data type: State StdGen a which is constructed with the function: State {runState :: (StdGen - (a, StdGen))} Q1: Where in the example ( http://www.haskell.org/all_about_monads/examples/example15.hs) data of this type *actually gets constructed* ? Looking at example15.hs code we see the following sequence: 1) makeRandomValue g -- where g is a StdGen instance, ok 2) makeRandomValue g ~ expands into ~ ~ (runState (do { ...; b - getAny;...})) g This last expression puzzles me. I can understand, for example, this: State StdGen a :: aState StdGen:: g1 (v, g2) = (runStae aState) g1 -- this returns a state function which is then passed a generator g1, and as result returns pair (value, new generaor) But '(runState (do ...)) g' implies that expression (do ...) must be somehow of type 'State StdGen a' ? Yet, when we call 'makeRandomValue g' we just pass to this function g::StgGen So, my next question: Q2: How (do {...;b - getAny;...}) becomes an *instance* of type 'State StdGen a' ? On Tue, May 20, 2008 at 7:01 PM, Olivier Boudry [EMAIL PROTECTED] wrote: 2008/5/19 Dmitri O.Kondratiev [EMAIL PROTECTED]: I am trying to understand State monad example15 at: http://www.haskell.org/all_about_monads/html/statemonad.html Hi Dmitri, I'm not sure you need to understand everything about Monad and do-notation to use the State Monad. So I will try to explain its use without talking about those scary topics. ;-) In Haskell you use the state monad when you want to hide state passing between function calls. As Haskell is pure you cannot change state. You can just create a new state and return it along with the value. In haskell you would do this by returning the value and new state in a tuple. State passing functions usually have the type `s - (a, s)` where a is the type of the return value and s is the type of the State. This is exactly what the `random` function does. It gets a state and returns a tuple made of a value and a new state (StdGen: is a new seed for the random generator) to be used on the next `random` function call . Without the state monad you have to explicitely pass the new seed between calls to `random` as using the same seed for all function calls would always give you the same not so random number. Explicit state passing would look like this. get3RandomInts :: StdGen - (Int, Int, Int) get3RandomInts g1 = let (r1, g2) = random g1 (r2, g3) = random g2 (r3, _) = random g3 in (r1, r2, r3) It's tedious, unreadable and error prone as it's easy to mess up the numbering (based on my experience). The State Monad allow you to hide the state passing. You don't have to give the state as an argument and your function won't return a changed state along with the data. Code running in the State Monad will look like this: getAny :: (Random a) = State StdGen a getAny = do g - get -- magically get the current StdGen let (x, g') = random g put g' -- magically save the new StdGen for later return x get3RandomIntsWithState :: State StdGen (Int, Int, Int) get3RandomIntsWithState = do r1 - getAny -- you don't care about stdgen passing r2 - getAny r3 - getAny return (r1, r2, r3) To use your get3RandomIntsWithState function you need to run it using one of runState (returns the (value, state)) or evalState (returns the value). main :: IO () main = do g - getStdGen let t = evalState get3RandomsWithState g print t The interesting bits are in the getAny function. The State Monad provides you with 2 new function, get and set. If you look at this function as blackboxes; `get` will retrieve the current State and `put` will save a new State. You don't need to worry about how the State is passed from one getAny function call to another as long as they're run in the same `evalState` call. Now getAny can be simplified. If you look at the random function and at the State newtype declaration you will see that a State is a `s - (a, s)` function hidden in the State constructor. newtype State s a = State {runState :: s - (a, s)} random is also of the type `s - (a, s)` even if variables are labelled `g` and `a` random :: (RandomGen g, Random a) = g - (a, g) So wrapping the random function into the State constructor will just give you a getAny function for free. getAny :: (Random a) = State StdGen a getAny = State random I put a copy of the code in http://hpaste.org/7768 In short to use the State monad, you just need to care about
Re: [Haskell-cafe] Newbie: State monad example questions
State is a data type. As any other data type it can be instantiated. State instance is a structure of one record that contains (\s -(a,s)) lambda function. This function can be parametrized by types of its arguments 's' and 'a'. I don't see magic here :) Ok, then from declaration: getAny :: (Random a) = State StdGen a getAny = do g - get we can say that looking at type 'State StdGen a' compiler concludes that later on in the 'do' block statements like: g - get will resolve into bind function (=) *as bind is defined for State monad*. Fine, I assume compiler is capable of such reasoning. Then g - get may be written as: get = \g - ... To understand how State monad work, I wrote MyState data type that emulates State and (=) 'bind' function that emulates 'real' bind (=) implementation for State monad: (=) :: MyState StdGen Int - (Int - MyState StdGen Int) - MyState StdGen Int (MyState ms) = fn = MyState(\seed - let(v1, newSeed) = ms seed ms2 = fn v1 in (runState ms2) newSeed) Inserting 'get' into = (or = in my code) will in fact result in thinking about State instance that 'get' returns as denoted by 'ms' in this code of mine. From 'get' definition follows that function hiding behind 'ms' State instance is: \s - (s,s) So when later we will feed generator 'g1' into this function will get: (g1,g1) And we also will get: v1 = g1 newSeed = g1 ms2 = fn g1 and finally 'g' in expression 'g - get' will be equal to 'g1' that will be later fed in through the function call: 'makeRandomValueST g1' But how will 'g1' actually get delivered from 'makeRandomValueST g1' to invocation of 'getAny' I don't yet understand! On Wed, May 21, 2008 at 5:55 PM, Olivier Boudry [EMAIL PROTECTED] wrote: On Wed, May 21, 2008 at 8:42 AM, Dmitri O.Kondratiev [EMAIL PROTECTED] wrote: So let's start with fundamental and most intriguing (to me) things: getAny :: (Random a) = State StdGen a getAny = do g - get -- magically get the current StdGen First line above declares a data type: State StdGen a which is constructed with the function: State {runState :: (StdGen - (a, StdGen))} Q1: Where in the example ( http://www.haskell.org/all_about_monads/examples/example15.hs) data of this type *actually gets constructed* ? In getAny and getOne. Their signature has type `State StdGen a`. The use of the do notation to chain the actions and the use of get and put from the State Monad make this function a `State StdGen a`. Looking at example15.hs code we see the following sequence: 1) makeRandomValue g -- where g is a StdGen instance, ok 2) makeRandomValue g ~ expands into ~ ~ (runState (do { ...; b - getAny;...})) g This last expression puzzles me. I can understand, for example, this: State StdGen a :: aState StdGen:: g1 (v, g2) = (runStae aState) g1 -- this returns a state function which is then passed a generator g1, and as result returns pair (value, new generaor) But '(runState (do ...)) g' implies that expression (do ...) must be somehow of type 'State StdGen a' ? Yet, when we call 'makeRandomValue g' we just pass to this function g::StgGen So, my next question: Q2: How (do {...;b - getAny;...}) becomes an *instance* of type 'State StdGen a' ? In 2) I suppose you're talking of `makeRandomValueST` as `makeRandomValue` is the function that runs without the State Monad. makeRandomValueST does not build a `State StdGen a` it uses `runState` to run the (do block) which has type `State StdGen a`. Using `runState` will run an action which has `State s a` type on an initial state `s` and return a `(a, s)` tuple. `makeRandomValueST` does just the same using its parameter `g :: StdGen` as initial state and returning a tuple of type `(MyType, StdGen)`. Now what makes the do-block used in `runState` an instance of type `State StdGen a` is type inference. `runState` expects a `State s a` as first argument and `s` as second argument. The function signature, the use of `=` and `return` (desugared do-block) to combine actions and the use of actions already having that type like `getAny` and `getOne` will make your do block a `State StdGen a`. I'm not sure we can talk of building an instance of `State s a`. It's a parameterized variant of `State s a` which itself is an instance of the Monad class. We're just assigning types to the `s` and `a` type variables in `State s a`. In short `runState` takes the value (s - (a, s)) out of the State monad. In the case of the State Monad that value is a function and it is run on the initial state. Its usually what runX functions do. They have type `(Monad m) = m a - a`. Actions in the State Monad have type `State (s - (a, s))`. The value stored in the State constructor is a function. Combining two actions using the `=` and `` functions (hidden or not in a do-block) just create a bigger `s - (a, s)` function. The function is hidden
Re: [Haskell-cafe] Newbie: State monad example questions
Jules, Stupid question, please bear with me: x :: Int -- x declared, but not constructed x = 1 -- x constructed s1 :: State StdGen a -- s1 declared, yes, but why s1 is *also already constructed* ? On Wed, May 21, 2008 at 6:54 PM, Jules Bean [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev wrote: Thanks everybody for your help! Oliver, you provided an excellent write-up on State monad without going into 'scary' :) details, great work indeed! Alas, in this case I need the details, and in particular the most scary ones! So let's start with fundamental and most intriguing (to me) things: getAny :: (Random a) = State StdGen a getAny = do g - get -- magically get the current StdGen First line above declares a data type: State StdGen a which is constructed with the function: State {runState :: (StdGen - (a, StdGen))} Q1: Where in the example ( http://www.haskell.org/all_about_monads/examples/example15.hs) data of this type *actually gets constructed* ? Actually get constructed? It gets constructed by = and return, both of which construct state objects: instance Monad (State s) where return a = State $ \s - (a, s) m = k = State $ \s - let (a, s') = runState m s in runState (k a) s' How do = and return get called? Well you can see explicit calls to return. The = is implicit in the way do-notation is desugared. getAny = do g - get let (x,g') = random g put g' return x rewrites to getAny = get = \g - ( let (x,g') = random g in (put g' return x) ) where I have added some not strictly necessary ()s and taken the liberty of changing the confusing a - return x idiom to let a = x. So the *actually gets constructed* part is that use of = . HTH, Jules -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie: State monad example questions
-- Jules, Oliver, thanks! Things are getting clarified, I hope. -- Let me summarize how I now understand getAny operation, please correct me if I am wrong. getAny :: (Random a) = State StdGen a getAny = do g - get (x,g') - return $ random g put g' return x {-- getAny operation may be abbreviated as: do { -- 1) x calculation, equivalent to (x,g2) = random g1 -- 2) return x ~ State $ \s - (x,s) -- puts x into State container Thus getAny returns a State instantiated with a function which is a composition of several binds = from the above 'do' block and which calculates 'x' --} -- Then we can use this State object (returned by getAny) in a function generating random values such as: makeRnd :: StdGen - (Int, StdGen) makeRnd = runState (do y - getAny return y) {-- where: y - getAny return y passes a first value from the tuple generated by getAny State function into 'y' and puts 'y' into a new State object. After that 'runState' in makeRnd extracts from this new State a function parametrized by 'y' value. As a result we get curried 'makeRnd' which we can call with some generator instance and get a random value. --} On Wed, May 21, 2008 at 10:31 PM, Olivier Boudry [EMAIL PROTECTED] wrote: On Wed, May 21, 2008 at 11:10 AM, Dmitri O.Kondratiev [EMAIL PROTECTED] wrote: But how will 'g1' actually get delivered from 'makeRandomValueST g1' to invocation of 'getAny' I don't yet understand! It may be easier to understand the state passing if you remove the do notation and replace get, put and return with their definition in the instance declarations (Monad and MonadState). getAny :: (Random a) = State StdGen a getAny = do g - get (x,g') - return $ random g put g' return x get = State $ \s - (s, s) -- copy the state as a return value and pass state put s = State $ \_ - ((), s) -- return unit, ignore the passed state and replace it with the state given as parameter. return a = State $ \s - (a, s) -- return given value and pass state. getAnyNoSugar :: (Random a) = State StdGen a getAnyNoSugar = (State $ \s - (s, s)) = \g - (State $ \s - (random g, s)) = \(x,g') - (State $ \_ - ((), g')) (State $ \s - (x, s)) The function is still useable this way and the state transformations should be a bit more visible. The first element of the tuple is the value that will be used to call the next function (of type Monad m = a - m b). The second element of the tuple is the state and the (=) operator will handle passing it between actions. Desugaring the (=) and () operators would give you something like this (I replaced `s` with `y` in the `put` and `return` desugaring and simplified it): State $ \s = let (g, s') = (\y - (y,y)) s ((x,g'), s'') = (\y - (random g, y)) s' (_, s''') = (\_ - ((), g')) s'' in (x, s''') Which is explict state passing between function calls. Extract the State using `runState`, run it with an initial state and it should give you the expected result. Regards, Olivier. -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ 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 ?
Thanks! I just tried a new pre-built version (http://haskell.org/gtk2hs /gtk2hs-0.9.11.3.exe) and at least this simple prog. works in GHCi: module GWindow where import Graphics.SOE.Gtk main() = runGraphics ( do w - openWindow Graphics Test (300, 300) drawInWindow w (text (100, 200) Hello Graphics World) k - getKey w closeWindow w ) (With gtk2hs-0.9.11.exe in GHCi this trivial program hangs.) I am happy now and hope that more complex programs will work in new version as well :) Thanks again! Dima On 7/23/07, Duncan Coutts [EMAIL PROTECTED] wrote: On Fri, 2007-07-20 at 13:47 +0400, Dmitri O.Kondratiev wrote: Oliver, thanks! I tried that, yet have some problems. Questions: 1) Should I ignore autoreconf errors? I've never managed to get autoconf working on windows. I always generate a tarball under linux and build that on Windows. 2) I thought that building Gtk2hs is done with GHC only. Is it right that build requires C compiler? Yes, it does need a C compiler, but mingw has one so that's ok. 3) Any other ideas what is wrong with this build? Almost certainly the autoconf problem messed things up. It's sadly not all that easy to build from source on Windows, much easier to use a pre-built version: http://haskell.org/gtk2hs/gtk2hs-0.9.11.3.exe The final 0.9.12 will be announced soon and of course that final version will be announced and linked from the Gtk2Hs website. If you really want to build from source on Windows I can give you more detailed instructions, and I should probably update the FAQ on this issue too: http://haskell.org/gtk2hs/archives/2005/06/24/building-from-source-on-windows/ I've also got some semi-automated win32 build scripts: http://darcs.haskell.org/gtk2hs/tools/win32/ and also Gtk+ SDK bundles: http://haskell.org/gtk2hs/win32/ Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC 6.6.1: Where is Graphics.SOE ?
Olivier Boudry [EMAIL PROTECTED] wrote: (Wed Jul 18 11:56:56 EDT 2007) Hi Dmitri, I built gtk2hs on Windows with GHC 6.6.1 and gtk2hs-0.9.11. Here's are the steps that worked for me: (not sure I didn't missed some) First you need to install a GTK+ development package for windows. I think mine comes from http://gladewin32.sourceforge.net/modules/wfdownloads/ Then you must have MSYS and MinGW installed on your computer. You'll find information on how to install this here: http://hackage.haskell.org/trac/ghc/wiki/Building/Windows. Once you've installed that stuff you can start a MSYS shell. You'll need to set some environment variables for GTK (adapt to your path): export GTK_BASEPATH=/c/GTK_2.0 export GTK_CONFIG_PATH=/c/GTK_2.0/lib/pkgconfig Cd to the gtk2hs source directory and type: ./configure --prefix=/c/Progra~1/Haskell make make install Hope this helps. Good luck, Olivier. Oliver, thanks! I tried that, yet have some problems. I use: GHC 6.6.1, current development version of Gtk2hs (not sure what version), Gtk+ 2.10.11 (Win32) and latest available from MinGW distributions: MSYS-1.0.10.exe msysDTK-1.0.1.exe msys-autoconf-2.59.tar.bz2 msys-automake-1.8.2.tar.bz2 msys-libtool-1.5.tar.bz2 Problem 1. Gtk2hs build requires to run autoreconf. So in MSYS I have: $ autoreconf /usr/share/aclocal/autoopts.m4:22: warning: underquoted definition of AG_PATH_AUTOOPTS run info '(automake)Extending aclocal' or see http://sources.redhat.com/automake/automake.html#Extending%20aclocal configure.ac:101: error: possibly undefined macro: AC_MSG_ERROR If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. autoreconf: /usr/bin/autoconf failed with exit status: 1 Notwithstanding this error autoreconf creates configure script. When I run it I get: Problem 2. $ ./configure --with-hc=/c/usr/ghc-6.6.1 --prefix=/c/usr/ghc-6.6.1 checking for a BSD-compatible install... /bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking build system type... i686-pc-mingw32 checking host system type... i686-pc-mingw32 checking for style of include used by make... GNU checking for gcc... no checking for cc... no checking for cc... no checking for cl... no configure: error: no acceptable C compiler found in $PATH Questions: 1) Should I ignore autoreconf errors? 2) I thought that building Gtk2hs is done with GHC only. Is it right that build requires C compiler? 3) Any other ideas what is wrong with this build? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC 6.6.1: Where is Graphics.SOE ?
*Andrea Rossato* wrote: haskell-cafe%40haskell.org?Subject=%5BHaskell-cafe%5D%20GHC%206.6.1%3A%20Where%20is%20Graphics.SOE%20%3FIn-Reply-To=53396d9e0707170752q6769729es68d214639b69a789%40mail.gmail.com 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 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? Thanks, Dmitri -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ 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 7/17/07, Malte Milatz [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev: 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? You may try Gtk2Hs, which includes an implementation of SOE, called Graphics.SOE.Gtk. (It works independently of the actual Gtk API.) Use then the darcs version, because I remember an SOE bug fixed since the last release. Malte Malte, Thanks. The problem is that I need to run SOE on Win32. When I try to run a simple SOE app. in GHCi with Gtk2Hs Win32 release, this code: module GWindow where import Graphics.SOE.Gtk main() = runGraphics ( do w - openWindow Graphics Test (300, 300) drawInWindow w (text (100, 200) Hello Graphics World) k - getKey w closeWindow w ) displays a window and hangs. I can get development release of Gtk2Hs with darcs, but how can I build it on Win32? Dima -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC 6.6.1: Where is Graphics.SOE ?
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? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Newbie Q: Monad 'fail' and 'error'
Monad class contains declaration *fail* :: String - m a and provides default implementation for 'fail' as: fail s = error s On the other hand Prelude defines: * error* :: String - a which stops execution and displays an error message. Questions: 1) What value and type 'error' actually returns in: error some message ? 2) How declaration String - m a matches with String - a ? 3) In Maybe monad: fail = Nothing When and how 'fail' is used in Maybe monad? Thanks! -- Dmitri O. Kondratiev [EMAIL PROTECTED] http://www.geocities.com/dkondr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Newbie Q: Monad 'fail' and 'error'
Thanks for excellent explanation! Examples really help. So, in general 'fail' behavior will differ from monad to monad. In this example: divBy :: Monad m = Int - Int - m Int divBy a 0 = fail div by zero divBy a b = return (a `div` b) Default 'fail' implementation in Monad class will be: *DivBy divBy 5 0 Loading package haskell98-1.0 ... linking ... done. *** Exception: user error (div by zero) And when explicitly defining monad as Maybe it will be different: *DivBy divBy 5 0::Maybe Int Nothing I am curious if it is possible to 'cast' divBy to List, Identity, other monads? How? On 6/6/07, Tillmann Rendel [EMAIL PROTECTED] wrote: Dmitri O.Kondratiev wrote: Monad class contains declaration *fail* :: String - m a and provides default implementation for 'fail' as: fail s = error s On the other hand Prelude defines: * error* :: String - a which stops execution and displays an error message. Questions: 1) What value and type 'error' actually returns in: error some message ? For practical purposes: typechecking: every type the context asks for. execution: no value, because execution stops. For theoretical purposes, error could be implemented by error :: String - a error msg = error msg with the extra-semantical magical side effect of printing msg and aborting execution. 2) How declaration String - m a matches with String - a ? Alpha renaming to fresh variables yields String - b c String - d wich unifies by taking d := b c. 3) In Maybe monad: fail = Nothing When and how 'fail' is used in Maybe monad? The default fail implementation is not very clever. If something fails, execution is aborted and the user is confronted with some error message. Some monads support richer error handling schemes. The maybe monad encodes a succeeding computation with Just it's result, and a failed computation with Nothing. An example: -- divBy is a possible failing computation in some monad divBy :: Monad m = Int - Int - m Int divBy a 0 = fail div by zero divBy a b = return (a `div` b) -- div by three succeeds 15 `divBy` 3 :: Maybe Int ~~ Just 5 -- div by zero fails 15 `divBy` 0 :: Maybe Int ~~ Nothing -- divByAll is a shortcut for a list of divBy's divByAll :: Monad m = Int - [Int] - [m Int] divByAll a bs = map (divBy a) bs -- div by all returns a list of computations 15 `divByAll` [3, 0] :: [Maybe Int] ~~ [Just 5, Nothing] -- sequence succeeds if all computations in a list succeeds sequence (15 `divByAll` [3, 0]) :: Maybe [Int] ~~ Nothing sequence (15 `divByAll` [3, 5]) :: Maybe [Int] ~~ Just [5, 3] divBy, divByAll, sequence do not know anything about Maybe, they work for all monads, because they only use =, fail and return. The idea is that Monad defines some general interface for computations, and the various Monad instances define the exact behaviour. Maybe's behaviour is: if a subcomputation fails, the whole computation fails. There are other monads. consider the list monad, and it's behaviour: if a subcomputation fails, backtrack and try some other alternative. Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe