Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-28 Thread dokondr
On Fri, Oct 26, 2012 at 2:34 AM, Jake McArthur jake.mcart...@gmail.comwrote:

 I golfed a bit. :)

 sequence = filterM (const [False ..])


What is golfed and  = ? Please, explain.

Thanks,
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread dokondr
Hi all,
I am looking for the algorithm and code better then the one I wrote (please
see below) to solve the problem given in the subject.
Unfortunately I finally need to implement this algorithm in Java. That's
why I am not only interested in beautiful Haskell algorithms, but also in
the one that I can without much pain implement in procedural PL like Java
:(

{--
Build all possible element combinations from N lists.
Valid combination consists of k = N elements.
Where each element of a single combination is taken from one of the N
lists.
When building combination any list can give only one element for this
combination.
In other words you can not take more then one element from one and the same
list when building current combination. Thus combinations between elements
from the same input list are not allowed.
Yet when building next combination you can use any of the lists again.
Order of elements in combinaton does not matter.

For example:
input = [
  [[a],[b]],
  [[1],[2]],
  [[],[]]
  ]

output =
[

[a],[b],[1],[2],
[a,1],[a,2],[b,1],[b,2],
[],[],
[a,],[a,],[b,],[b,],
[1,],[1,],[2,],[2,],
[a,1,],[a,1,],[a,2,],[a,2,],
[b,1,],[b,1,],[b,2,],[b,2,]
]

(see bigger example at the end of the code)

Current implementation is based on the idea of using combinations
accumulator.
After first run accumulator contains:
1) All elements from the first two lists. These two lists are taken from
the input list of lists.
The elements of these first two lists are put in accumulator as is.
For example: [a],[b],[1],[2]
2) All combinations of these elements:
[a,1],[a,2],[b,1],[b,2]
Note: Combinations between elements from the same input list are not allowed

Next, on each run we add combinations built from accumulator elements
together with next list taken from the input list of list.
--}


input = [
  [[a],[b]],
  [[1],[2]],
  [[],[]],
  [[X],[Y]]
  ]


addAll :: [[[a]]] - [[a]]
addAll [] = []
addAll (x:[]) = x
addAll (x:y:[]) = accum x [y]
addAll inp = accum (initLst inp) (restLst inp)

initLst inp = fstLst ++ sndLst ++ (addLst fstLst sndLst) where
  fstLst = inp !! 0
  sndLst = inp !! 1

restLst inp = (tail . tail) inp

accum :: [[a]] - [[[a]]] - [[a]]
accum xs (r:rs) =  accum (xs ++ r ++ addLst xs r) rs
accum xs _ = xs

addLst :: [[a]] - [[a]] - [[a]]
addLst (x:xs) ys = addOne x ys ++ addLst xs ys
addLst _ [] = []
addLst [] _ = []

addOne :: [a] - [[a]] - [[a]]
addOne x (y:ys) = [x ++ y] ++ addOne x ys
addOne x [] = []

{--
For example:

input = [
  [[a],[b]],
  [[1],[2]],
  [[],[]],
  [[X],[Y]]
  ]

output =
[
[],[],
[a],[b],[1],[2],
[a,1],[a,2],[b,1],[b,2],
[a,],[a,],[b,],[b,],
[1,],[1,],[2,],[2,],
[a,1,],[a,1,],[a,2,],[a,2,],
[b,1,],[b,1,],[b,2,],[b,2,],
[X],[Y],
[a,X],[a,Y],[b,X],[b,Y],
[1,X],[1,Y],[2,X],[2,Y],
[a,1,X],[a,1,Y],[a,2,X],[a,2,Y],
[b,1,X],[b,1,Y],[b,2,X],[b,2,Y],
[,X],[,Y],[,X],[,Y],
[a,,X],[a,,Y],[a,,X],[a,,Y],
[b,,X],[b,,Y],[b,,X],[b,,Y],
[1,,X],[1,,Y],[1,,X],[1,,Y],
[2,,X],[2,,Y],[2,,X],[2,,Y],
[a,1,,X],[a,1,,Y],[a,1,,X],[a,1,,Y],
[a,2,,X],[a,2,,Y],[a,2,,X],[a,2,,Y],
[b,1,,X],[b,1,,Y],[b,1,,X],[b,1,,Y],
[b,2,,X],[b,2,,Y],[b,2,,X],[b,2,,Y]
]

--}
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Building all possible element combinations from N lists.

2012-10-25 Thread dokondr
On Fri, Oct 26, 2012 Alex Stangl wrote:

* *
 combos [] = [[]]
 combos ([]:ls) = combos ls
 combos ((h:t):ls) = map (h:) (combos ls) ++ combos (t:ls)


Excellent, thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Debian 6.0.5: 'cabal install curl' problem

2012-08-14 Thread dokondr
Please help to solve a problem installing curl package (
http://hackage.haskell.org/package/curl/) on Debian 6.0.5.
I am running the most recent Debian Haskell platform with GHC 6.12.1.
I did:
- cabal update
- cabal install cabal-install

It is interesting that in case you do again 'cabal update you again get a
suggestion from cabal to upgrade cabal-install, and this process never ends:

- cabal update
Downloading the latest package list from hackage.haskell.org
Note: there is a new version of cabal-install available.
To upgrade, run: cabal install cabal-install

Anyway, then I did:
- apt-get install curl
- cabal install curl
Cabal fails to install 'curl' because it can not find curl library. Please
see detailed cabal output at the end of this message.
So my questions:
1) What is missing to install curl package?
2) Should I upgrade Debian GHC 6.12.1 to the latest GHC 7.4.2? Maybe this
should solve the problem with 'cabal install'?

Thanks!
-- cabal install output --
- cabal install curl
Resolving dependencies...
Configuring curl-1.3.7...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
configure: error: curl libraries not found, so curl package cannot be built
See `config.log' for more details.
cabal: Error: some packages failed to install:
curl-1.3.7 failed during the configure step. The exception was:
ExitFailure 1
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Debian 6.0.5: 'cabal install curl' problem

2012-08-14 Thread dokondr
Marcot,
Thanks for the detailed info!
Looks like aptitude install libcurl4-gnutls-dev solved the problem.

cheers,
Dmitri

On Tue, Aug 14, 2012 at 6:29 PM, Marco Túlio Pimenta Gontijo 
marcotmar...@gmail.com wrote:

 Hi dokondr.

 On Tue, Aug 14, 2012 at 11:23 AM, dokondr doko...@gmail.com wrote:
 (...)
  Cabal fails to install 'curl' because it can not find curl library.
 Please
  see detailed cabal output at the end of this message.

 Cabal means the curl C library, which must be installed by either the
 packages
 libcurl4-openssl-dev or libcurl4-gnutls-dev.  If a situation like this
 happens
 again, you can search for candidate packages with:

 $ apt-cache search lib curl dev
 collectd-core - statistics collection and monitoring daemon (core system)
 libcurl4-gnutls-dev - Development files and documentation for libcurl
 (GnuTLS)
 libcurl4-openssl-dev - Development files and documentation for libcurl
 (OpenSSL)
 devscripts - scripts to make the life of a Debian Package maintainer easier
 libflickcurl-dev - C library for accessing the Flickr API - development
 files
 libghc6-curl-dev - GHC 6 libraries for the libcurl Haskell bindings
 liblua5.1-curl-dev - libcURL development files for the Lua language
 version 5.1
 liblua5.1-curl0 - libcURL bindings for the Lua language version 5.1
 libwww-curl-perl - Perl bindings to libcurl
 libcurl-ocaml-dev - OCaml libcurl bindings (Development package)
 python-pycurl-dbg - Python bindings to libcurl (debug extension)
 python-pycurl - Python bindings to libcurl
 tclcurl - Tcl bindings to libcurl
 php5-curl - CURL module for php5

 Or, even better, use the aptitude interface and search (with /) for lib
 curl
 dev, which will lead you directly to the right package in this case.

 Greetings.
 (...)
 --
 marcot
 http://marcot.eti.br/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Simple GUI library to view JSON?

2012-02-20 Thread dokondr
Please advise on a simple GUI library to display JSON data. A library that
is easy to build both on Win, Linux and OsX. I need a scrollable view to
show a list of JSON objects. Every object may contain other objects
(recursively). List may have thousands of objects. Fields may have very
long text values, so the view must also be scrollable in horizontal
dimension.
JSON object view should be click-able and look like on this example:
{
hey: guy,
anumber: 243,
- anobject: {
whoa: nuts,
- anarray: [
1,
2,
thrh1ee
],
more: stuff
},
awesome: true,
bogus: false,
meaning: null,
link: http://jsonview.com;,
}

Where '-' before the field object indicates that object was expanded and
'+' means collapsed object.
Clicking on expanded fields should collapse them and vice verse. So for
this example, clicking on 'anobject' should result in:
{
hey: guy,
anumber: 243,
anobject: {... }
awesome: true,
bogus: false,
meaning: null,
link: http://jsonview.com;,
}

In short I need a view similar to the one provided by JSONView plugin for
Firefox:
https://addons.mozilla.org/en-US/firefox/addon/jsonview/

Thanks a lot for any info, comments and ideas about this project!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple GUI library to view JSON?

2012-02-20 Thread dokondr
Thanks, it is a good idea to use JSONView. Yet I also want to reuse this
code to view lists of objects in MongoDB collection. MongoDB objects are in
fact JSON, so the same code should work. I am not sure though that saving
MongoDB objects in intermediate JSON and then displaying them in JSONView
would be the best way to go.

On Mon, Feb 20, 2012 at 10:24 PM, Clark Gaebel
cgae...@csclub.uwaterloo.cawrote:

 You could set up a simple web server (with, for example, Yesod [1])
 serving up your JSON data, and then just connect to it with Firefox and use
 JSONView.

 [1] http://www.yesodweb.com/

 On Mon, Feb 20, 2012 at 2:01 PM, dokondr doko...@gmail.com wrote:

 Please advise on a simple GUI library to display JSON data. A library
 that is easy to build both on Win, Linux and OsX. I need a scrollable view
 to show a list of JSON objects. Every object may contain other objects
 (recursively). List may have thousands of objects. Fields may have very
 long text values, so the view must also be scrollable in horizontal
 dimension.
 JSON object view should be click-able and look like on this example:
 {
 hey: guy,
 anumber: 243,
 - anobject: {
 whoa: nuts,
 - anarray: [
 1,
 2,
 thrh1ee
 ],
 more: stuff
 },
 awesome: true,
 bogus: false,
 meaning: null,
 link: http://jsonview.com;,
 }

 Where '-' before the field object indicates that object was expanded and
 '+' means collapsed object.
 Clicking on expanded fields should collapse them and vice verse. So for
 this example, clicking on 'anobject' should result in:
 {
 hey: guy,
 anumber: 243,
 anobject: {... }
 awesome: true,
 bogus: false,
 meaning: null,
 link: http://jsonview.com;,
 }

 In short I need a view similar to the one provided by JSONView plugin for
 Firefox:
 https://addons.mozilla.org/en-US/firefox/addon/jsonview/

 Thanks a lot for any info, comments and ideas about this project!


 ___
 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] ANN: NubFinder : Mining Opinions on the Web

2012-02-01 Thread dokondr
Hello,
I am pleased to announce NubFinder research project.
Goal: develop technology to search and analyze user opinions on the Web.
NubFinder and NubTrend are research prototypes trying first to accomplish a
more 'simple' task  - classification of emotions in Twitter messages, and
then approach opinion mining.

NubFinder project site:
https://sites.google.com/site/nubfinder
NubFinder discussion group:
http://groups.google.com/group/nubfinder

Thanks for your interest in NubFinder Research!

-- 
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] ANN: NubFinder : Mining Opinions on the Web

2012-02-01 Thread dokondr
On Thu, Feb 2, 2012 at 5:24 AM, Edward Amsden eca7...@cs.rit.edu wrote:

 Since this is an announcement on the Haskell mailing list, could you
 clarify the relevance to Haskell? It's not immediately obvious.


Very true, sorry for missing this out.
 All server-side code including Twitter crawler and Sparse Vector Space
Model classifier is written in Haskell http://www.haskell.org/ and
compiled with The Glasgow Haskell Compiler http://www.haskell.org/ghc/.
In case of interest in NubFinder project I will refactor the Haskell source
into reusable library ready for Hackage.



 --
 Edward Amsden

 On Wed, Feb 1, 2012 at 5:04 PM, dokondr doko...@gmail.com wrote:
  Hello,
  I am pleased to announce NubFinder research project.
  Goal: develop technology to search and analyze user opinions on the Web.
  NubFinder and NubTrend are research prototypes trying first to
 accomplish a
  more 'simple' task  - classification of emotions in Twitter messages, and
  then approach opinion mining.
 
  NubFinder project site:
  https://sites.google.com/site/nubfinder
  NubFinder discussion group:
  http://groups.google.com/group/nubfinder
 
  Thanks for your interest in NubFinder Research!
 
  --
  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] Need advice: Haskell in Web Client

2012-01-30 Thread dokondr
**Bardur Arantsson wrote:
On 01/26/2012 11:16 AM, dokondr wrote:
 Ideally, I would be happy to be able to write in Haskell a complete
 front-end / GUI, so it could be compiled to different back-ends:
Javascript
 to run in the Browser and also a standalone app.
 In Python world this is already done with Pyjamas (http://pyjs.org/) -
a
 Rich Internet Application (RIA) Development Platform for both Web
and
 Desktop.
 Also from Pyjamas site:
 Pyjamas ... contains a Python-to-Javascript compiler, an AJAX
framework
 and a Widget Set
API.

 Pyjamas Desktop is the Desktop version of
Pyjamas
 Pyjamas Desktop allows the exact same python web application source code
to
 be executed as a standalone desktop application (running under
Python)
 instead of being stuck in a Web browser.

 Architecture diagram
 http://pyjs.org/wiki/pyjamasandpyjamasdesktop/

 I wonder if somebody works on similar Haskell Rich Internet
Application
 (RIA) Development Platform ?
 Any ideas, comments on implementation of such system in Haskell? What
 existing Haskell GUI libraries can be used for a desktop GUI, etc.?


Well, it's basically just proof-of-concept at the moment, and it's not
really usable for real applications at the moment, but there is

http://hackage.haskell.org/package/dingo-core-0.1.0
http://hackage.haskell.org/package/dingo-widgets-0.1.0
http://hackage.haskell.org/package/dingo-example-0.1.0

The basic client-server communication, server-side state handling,
etc. is there, but it's missing a couple of things before it could be
used for real apps: There's no real security, and there are *very* few
widgets. The few widgets that exist at the moment are also probably
lacking a few operations. On the plus side, it's should be pretty easy
to create new widgets.

You can get a feel for how the thing looks from an application
programmer's perspective by looking at the source for the example.

Looks neat, thanks!
If I got this write, in dingo all web page content is created by running
Haskell on the server side in run-time and then sending generated html + js
to the client (browser).
I am looking for the opposite - when client does more work running
Javascript generated by Haskell in advance, the approach that Pyjamas use (
http://pyjs.org/) with Python to Javascript compilation.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need advice: Haskell in Web Client

2012-01-26 Thread dokondr
On Thu, Jan 19, 2012 at 1:37 AM, Dag Odenhall dag.odenh...@gmail.comwrote:


 On Tue, 2012-01-17 at 22:05 +0300, dokondr wrote:
 
  I prefer using Turing complete PL to program web client, like the one
 used
  in GWT (Java) or Cappuccino  (Objective-J). http://cappuccino.org/learn/
  In this case you /almost/ don't need to know  HTML, CSS, DOM, Ajax, etc.
 to
  develop WebUI and good PL lets you concentrate on problem domain instead
 of
  bothering about browser support.
  It is a real pity that Haskell still has no such tools to generate Web
 GUI
  in Javascript. (((

 Have you seen Chris Done's posts on the subject?

 http://chrisdone.com/tags/javascript.html


Thanks for the link! (Never seen this before)
Ideally, I would be happy to be able to write in Haskell a complete
front-end / GUI, so it could be compiled to different back-ends: Javascript
to run in the Browser and also a standalone app.
In Python world this is already done with Pyjamas (http://pyjs.org/) - a
Rich Internet Application (RIA) Development Platform for both Web and
Desktop.
Also from Pyjamas site:
Pyjamas ... contains a Python-to-Javascript compiler, an AJAX framework
and a Widget Set API.
Pyjamas Desktop is the Desktop version of Pyjamas
Pyjamas Desktop allows the exact same python web application source code to
be executed as a standalone desktop application (running under Python)
instead of being stuck in a Web browser.

Architecture diagram
http://pyjs.org/wiki/pyjamasandpyjamasdesktop/

I wonder if somebody works on similar Haskell Rich Internet Application
(RIA) Development Platform ?
Any ideas, comments on implementation of such system in Haskell? What
existing Haskell GUI libraries can be used for a desktop GUI, etc.?

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need advice: Haskell in Web Client

2012-01-18 Thread dokondr
On Wed, Jan 18, 2012 at 10:47 AM, John Lenz l...@math.uic.edu wrote:



 I don't see a great need of developing something like GWT for haskell,
 since we already have good support for all sorts of existing tools that
 span more than just haskell, like extjs, yui, and jqueryui.


Haskell makes my work doable in many areas where other PLs will take
enormous efforts and time to  achieve the same result.
It would be great if I could write Web client code in pure Haskell (no
HTML, no DOM, no Ajax, ..) compile it to Javascript and just run it in the
browser and do all GUI and backend communication work. Simple as that.

Regards,
Dmitri.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Need advice: Haskell in Web Client

2012-01-17 Thread dokondr
Hi all,
I hope to use Haskell for graphics (charts) programming in Web client.

My current implementation in brief:
Server side, Haskell modules:
1) collecting various statistics from Twitter
2) generating text data for Gnuplot (http://www.gnuplot.info/)
3) Gnuplot creates png files with charts

Web client:
GWT (Google Web Toolkit) web UI that allows user to enter queries and see
resulting charts  in Web browser. Charts are png files generated by Gnuplot
on the server side.

Ideally, on the server side  instead of using Gnuplot I would like Haskell
to generate Javascript to be downloaded to Web client and draw charts in
the browser. Something, very approximately, similar to what GWT does :)
This code will be specific of course to plotting Javascript framework, no
problem.
Looking at Haskell in web browser - HaskellWiki:
http://www.haskell.org/haskellwiki/Haskell_in_web_browser#Haskell_web_toolkit
I feel a little confused about current state of the available Haskell tools
for this task.
Any ideas?

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need advice: Haskell in Web Client

2012-01-17 Thread dokondr
On Tue, Jan 17, 2012 at 6:42 PM, John Lenz l...@math.uic.edu wrote:


 HTML5 Canvas is great for charts.  If you go this route you might as well
 use a library which draws charts for you instead of writing all this code
 yourself.

 Personally, I use extjs version 4 which has some amazing charts, but there
 are other libraries out there.

 http://www.sencha.com/**products/extjs/examples/#**sample-3http://www.sencha.com/products/extjs/examples/#sample-3

 Essentially the server provides the data in JSON or XML some other format,
 and the extjs code draws the charts on the client side.

 If you go with extjs, then the server side I would suggest a small, simple
 yesod or snap server.   You could probably get the server under a hundred
 lines of code with yesod; see some of the examples in the yesod book.
  yesod or snap would serve JSON of the statistics on request, and also
 serve the javascript files which draw the charts.


Yes, I was thinking about using Haskell to generate everything that
specific Javascript library needs to display charts in browser. Naturally
charts are to be displayed by this library itself. I also would like to
have Haskell tools to generate Web GUI in Javascript.
As for yesod, I am not sure that I like approach which mixes HTML with
code, or even worse - creates a new weird HTML-like language like  'whamlet
quasi-quotation', for example:

!-- a href=@{Page1R}Go to page 1! --

I prefer using Turing complete PL to program web client, like the one used
in GWT (Java) or Cappuccino  (Objective-J). http://cappuccino.org/learn/
In this case you /almost/ don't need to know  HTML, CSS, DOM, Ajax, etc. to
develop WebUI and good PL lets you concentrate on problem domain instead of
bothering about browser support.
It is a real pity that Haskell still has no such tools to generate Web GUI
in Javascript. (((
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Tracing Prelude.read exceptions

2011-12-11 Thread dokondr
Hi,
I got quite used to a sequence providing simple data persistence :
1) Store my data to a file:
writeFile fileName (show someData)

2) Some time later read this data back:
line - readFile fileName
let someData = read line :: SomeDataType

Having this done hundreds of times I now got stuck with step 2)  trying to
read moderately complex structure back. I get read exception in run-time:
fromList *** Exception: Prelude.read: no parse

I have checked and rechecked my types, data files, etc. - and still no idea.

So my question:
Is there any way to trace Prelude.read exceptions to see exactly on what
data element read fails in run-time?

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] No instance for (Read POSIXTime)

2011-12-11 Thread dokondr
Yitz, thanks for the detailed answer!
May be I should have formulated my question differently. All I actually
need is some way to get *seconds* since epoch from the  system, so I could
manipulate them as integers.
Correct me if I am wrong, but UTCTime does not help here.
The only way I found to get seconds form epoch using existing today GHC
libraries is that:

utcStr = Wed, 07 Dec 2011 10:10:05 +
posixSecondsIntg = read posixSecondsStr :: Integer
posixSecondsStr =  init $ show (cvtUTCtoSec  utcStr) -- throw away 's' from
posix seconds string, s\
uch as 1235657s

cvtUTCtoSec utcTimeStr = utcTimeToPOSIXSeconds utcTime where
utcTime = fromJust $ tryParseTime utcTimeStr

timeFormat1 = %a, %d %b %Y %T %z
timeFormat2 = %m/%e/%Y %l:%M:%S %p

tryParseTime :: String - Maybe UTCTime
tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale timeFormat1
timeStr :: Maybe UTCTime)
   where
 tryFormat time
| time == Nothing = parseTime defaultTimeLocale timeFormat2 timeStr
:: Maybe UTCTime
| otherwise = time


Not a very easy way, isn't it?

On Sun, Dec 11, 2011 at 9:22 PM, Yitzchak Gale g...@sefer.org wrote:

 dokondr wrote:
  When I try to read POSIXTime...
  No instance for (Read POSIXTime)...
  What should I do to provide Read instance for POSIXTime?

 Short answer: if you are thinking about this as a moment
 in time that could be parsed from the usual kind of
 string representation for that, you probably want to
 use UTCTime in your data type, not POSIXTime.

 If you really, really want to represent it internally
 as POSIXTime, then you should read those strings
 as UTCTime and then convert them to POSIXTime
 to store in your data type. I.e., in that case don't
 make your data type an instance of Read.

 POSIXTime is just a type alias for NominalDiffTime,
 i.e., a quantity of time between two moments.

 This is what the Show instance looks like:

 Prelude Data.Time realToFrac 100 :: NominalDiffTime
 100s

 By convention, the Read instance would expect a
 string in that format. Generally people aren't interested
 in that, so there is no Read instance.
 Even if you did want to parse that, you would just
 parse it as a number and then use realToFrac, as I
 did above.

 The rule of thumb is: always represent moments in
 time as a UTCTime.

 Regards,
 Yitz

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] No instance for (Read POSIXTime)

2011-12-09 Thread dokondr
Hi,
I need to read / write epoch seconds  from / to plain text files.
When I try to read POSIXTime that I use in my own data type:

data TimedClassRecT = TCR {timeStamp :: POSIXTime, classCosMap :: Map.Map
String Float}
  deriving (Eq, Read, Show)

I get the following error:

No instance for (Read POSIXTime)
  arising from the 'deriving' clause of a data type declaration
Possible fix:
  add an instance declaration for (Read POSIXTime)
  or use a standalone 'deriving instance' declaration,
   so you can specify the instance context yourself
When deriving the instance for (Read TimedClassRecT)

What should I do to provide Read instance for POSIXTime? I would rather not
implement it myself.

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Converting string to System.Time.ClockTime

2011-12-08 Thread dokondr
Hi,
What would be the simplest way to convert strings like Wed, 07 Dec 2011
10:09:21 + to System.Time.ClockTime ?

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Converting string to System.Time.ClockTime

2011-12-08 Thread dokondr
I need to parse time strings like Wed, 07 Dec 2011 10:09:21 + to a
type that:
1) implements Eq, Ord
2) is numerical, so I could subtract one value from another to find the
difference or interval length

To answer 1) requirement I wrote the following snippet. Yet I could not
subtract  UTCTime values. How can I convert them to milliseconds?

import Data.Time.Format
import Data.Time.Clock
import Locale
import Data.Maybe

s1 = Wed, 07 Dec 2011 10:09:21 +
s2 = Wed, 07 Dec 2011 10:11:00 +
t1 = fromJust $ tryParseTime s1
t2 = fromJust $ tryParseTime s2

t = compare t1 t2

tryParseTime :: String - Maybe UTCTime
tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale timeFormat1
timeStr :: Maybe UTCTime)
   where
 tryFormat time
| time == Nothing = parseTime defaultTimeLocale timeFormat2 timeStr
:: Maybe UTCTime
| otherwise = time

 timeFormat1 = %a, %d %b %Y %T %z
 timeFormat2 = %m/%e/%Y %l:%M:%S %p



On Thu, Dec 8, 2011 at 6:12 PM, Erik Hesselink hessel...@gmail.com wrote:

 I'm not sure if you really need ClockTime (from old-time), but if you
 don't, the types from the 'time' package are all parseable with
 `parseTime` [1].

 Erik

[1]
 http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:parseTime

 On Thu, Dec 8, 2011 at 14:16, dokondr doko...@gmail.com wrote:
  Hi,
  What would be the simplest way to convert strings like Wed, 07 Dec 2011
  10:09:21 + to System.Time.ClockTime ?
 
  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] Converting string to System.Time.ClockTime

2011-12-08 Thread dokondr
Now, when I have managed to convert UTCTime to seconds (see code below) I
got stuck trying to convert from UTCTime to CalendarTime, how to do this?

import Data.Time.Format
import Data.Time.Clock
import Locale
import Data.Maybe
import Data.Time.Clock.POSIX

s1 = Wed, 07 Dec 2011 10:09:21 +
s2 = Wed, 07 Dec 2011 10:11:00 +
t1 = fromJust $ tryParseTime s1
t2 = fromJust $ tryParseTime s2
pt1 = utcTimeToPOSIXSeconds t1  -- :: UTCTime - POSIXTime
pt2 = utcTimeToPOSIXSeconds t2
pt3 = pt1 + (pt2 - pt1) / 2
t3 = posixSecondsToUTCTime pt3

t = compare t1 t2

tryParseTime :: String - Maybe UTCTime
tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale timeFormat1
timeStr :: Maybe UTCTime)
   where
 tryFormat time
| time == Nothing = parseTime defaultTimeLocale timeFormat2 timeStr
:: Maybe UTCTime
| otherwise = time

 timeFormat1 = %a, %d %b %Y %T %z
 timeFormat2 = %m/%e/%Y %l:%M:%S %p
-- timeFormat1 = %m/%d/%Y %l:%M:%S %p


On Thu, Dec 8, 2011 at 6:30 PM, dokondr doko...@gmail.com wrote:

 I need to parse time strings like Wed, 07 Dec 2011 10:09:21 + to a
 type that:
 1) implements Eq, Ord
 2) is numerical, so I could subtract one value from another to find the
 difference or interval length

 To answer 1) requirement I wrote the following snippet. Yet I could not
 subtract  UTCTime values. How can I convert them to milliseconds?

 import Data.Time.Format
 import Data.Time.Clock
 import Locale
 import Data.Maybe

 s1 = Wed, 07 Dec 2011 10:09:21 +
 s2 = Wed, 07 Dec 2011 10:11:00 +
 t1 = fromJust $ tryParseTime s1
 t2 = fromJust $ tryParseTime s2

 t = compare t1 t2

 tryParseTime :: String - Maybe UTCTime
 tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale timeFormat1
 timeStr :: Maybe UTCTime)
where
  tryFormat time
 | time == Nothing = parseTime defaultTimeLocale timeFormat2
 timeStr :: Maybe UTCTime
 | otherwise = time

  timeFormat1 = %a, %d %b %Y %T %z
  timeFormat2 = %m/%e/%Y %l:%M:%S %p




 On Thu, Dec 8, 2011 at 6:12 PM, Erik Hesselink hessel...@gmail.comwrote:

 I'm not sure if you really need ClockTime (from old-time), but if you
 don't, the types from the 'time' package are all parseable with
 `parseTime` [1].

 Erik

 [1]
 http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:parseTime

 On Thu, Dec 8, 2011 at 14:16, dokondr doko...@gmail.com wrote:
  Hi,
  What would be the simplest way to convert strings like Wed, 07 Dec 2011
  10:09:21 + to System.Time.ClockTime ?
 
  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] Converting string to System.Time.ClockTime

2011-12-08 Thread dokondr
Ok, maybe you could advise what packages to use for this simple scenario:

I have two text strings with dates:
s1 = Wed, 07 Dec 2011 10:09:21 +
s2 = Wed, 07 Dec 2011 10:11:00 +

I need:
1) Find how many seconds are between  these dates
2) Calculate the date in the middle between these dates
3) Print out all three dates in the different format, like these:
 2011,  7 Dec, Wed, 10:11:00

What functions should I use to implement this?

On Thu, Dec 8, 2011 at 7:13 PM, Antoine Latter aslat...@gmail.com wrote:

 On Thu, Dec 8, 2011 at 9:01 AM, dokondr doko...@gmail.com wrote:
  Now, when I have managed to convert UTCTime to seconds (see code below) I
  got stuck trying to convert from UTCTime to CalendarTime, how to do this?
 
 

 It might be easier to use 'diffUTCTime' and 'addUTCTime' instead of
 converting to and from POSIX seconds.

 What do you need the 'CalendarTime' for? I recommend not mixing the
 'time' and 'old-time' packages if you can avoid it.

 If you really need to for inter-operating with some other library, it
 looks like you can use the 'datetime' package to convert from a
 UTCTime to a ClockTime, and then you can use the 'old-time' package to
 convert from a 'ClockTime' to a 'CalendarTime'.

 Antoine

  import Data.Time.Format
  import Data.Time.Clock
  import Locale
  import Data.Maybe
  import Data.Time.Clock.POSIX
 
 
  s1 = Wed, 07 Dec 2011 10:09:21 +
  s2 = Wed, 07 Dec 2011 10:11:00 +
  t1 = fromJust $ tryParseTime s1
  t2 = fromJust $ tryParseTime s2
  pt1 = utcTimeToPOSIXSeconds t1  -- :: UTCTime - POSIXTime
  pt2 = utcTimeToPOSIXSeconds t2
  pt3 = pt1 + (pt2 - pt1) / 2
  t3 = posixSecondsToUTCTime pt3
 
 
  t = compare t1 t2
 
  tryParseTime :: String - Maybe UTCTime
  tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale timeFormat1
  timeStr :: Maybe UTCTime)
 where
   tryFormat time
  | time == Nothing = parseTime defaultTimeLocale timeFormat2
 timeStr
  :: Maybe UTCTime
  | otherwise = time
 
   timeFormat1 = %a, %d %b %Y %T %z
   timeFormat2 = %m/%e/%Y %l:%M:%S %p
  -- timeFormat1 = %m/%d/%Y %l:%M:%S %p
 
 
 
  On Thu, Dec 8, 2011 at 6:30 PM, dokondr doko...@gmail.com wrote:
 
  I need to parse time strings like Wed, 07 Dec 2011 10:09:21 + to a
  type that:
  1) implements Eq, Ord
  2) is numerical, so I could subtract one value from another to find the
  difference or interval length
 
  To answer 1) requirement I wrote the following snippet. Yet I could not
  subtract  UTCTime values. How can I convert them to milliseconds?
 
  import Data.Time.Format
  import Data.Time.Clock
  import Locale
  import Data.Maybe
 
  s1 = Wed, 07 Dec 2011 10:09:21 +
  s2 = Wed, 07 Dec 2011 10:11:00 +
  t1 = fromJust $ tryParseTime s1
  t2 = fromJust $ tryParseTime s2
 
  t = compare t1 t2
 
  tryParseTime :: String - Maybe UTCTime
  tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale
 timeFormat1
  timeStr :: Maybe UTCTime)
 where
   tryFormat time
  | time == Nothing = parseTime defaultTimeLocale timeFormat2
  timeStr :: Maybe UTCTime
  | otherwise = time
 
   timeFormat1 = %a, %d %b %Y %T %z
   timeFormat2 = %m/%e/%Y %l:%M:%S %p
 
 
 
 
  On Thu, Dec 8, 2011 at 6:12 PM, Erik Hesselink hessel...@gmail.com
  wrote:
 
  I'm not sure if you really need ClockTime (from old-time), but if you
  don't, the types from the 'time' package are all parseable with
  `parseTime` [1].
 
  Erik
 
  [1]
 
 http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:parseTime
 
  On Thu, Dec 8, 2011 at 14:16, dokondr doko...@gmail.com wrote:
   Hi,
   What would be the simplest way to convert strings like Wed, 07 Dec
   2011
   10:09:21 + to System.Time.ClockTime ?
  
   Thanks!
  
  
  

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Converting string to System.Time.ClockTime

2011-12-08 Thread dokondr
On Thu, Dec 8, 2011 at 7:39 PM, Antoine Latter aslat...@gmail.com wrote:

 On Thu, Dec 8, 2011 at 9:30 AM, dokondr doko...@gmail.com wrote:
  Ok, maybe you could advise what packages to use for this simple scenario:
 
  I have two text strings with dates:
 
  s1 = Wed, 07 Dec 2011 10:09:21 +
  s2 = Wed, 07 Dec 2011 10:11:00 +
 
  I need:
  1) Find how many seconds are between  these dates
  2) Calculate the date in the middle between these dates

 It looks like you already have 1) and 2) finished, using the 'time'
 package.

  3) Print out all three dates in the different format, like these:
   2011,  7 Dec, Wed, 10:11:00

 If you need to convert into a specific time-zone you can use the
 'utcToLocalTime' function in the 'time' package, which takes a UTCTime
 and a TimeZone to create a 'LocalTime'. I'm just guessing that you
 might want this, as your output format doesn't include time-zone
 information.

 Then for formatting, the 'Data.Time.Format' module in the 'time'
 package has the function 'formatTime', which uses the same sort of
 format string used by 'parseTime'.

 I hope that helps! It took me a while to find my way around the 'time'
 package properly.

 Antoine



Thanks so much for your help! I think I finally :) solved this problem:

import Data.Time.Format
import Data.Time.Clock
import Locale
import Data.Maybe
import Data.Time.Clock.POSIX

timeFormat1 = %a, %d %b %Y %T %z
timeFormat2 = %m/%e/%Y %l:%M:%S %p

s1 = Wed, 07 Dec 2011 10:09:21 +
s2 = Wed, 07 Dec 2011 10:11:00 +
t1 = fromJust $ tryParseTime s1 -- :: UTCTime
t2 = fromJust $ tryParseTime s2
pt1 = utcTimeToPOSIXSeconds t1  -- :: POSIXTime
pt2 = utcTimeToPOSIXSeconds t2
pt3 = pt1 + (pt2 - pt1) / 2
t3 = posixSecondsToUTCTime pt3  -- :: UTCTime

-- formatTime :: FormatTime t = TimeLocale - String - t - String
s3 = formatTime defaultTimeLocale timeFormat2 t3

test = (compare t1 t2) == (compare pt1 pt2)

tryParseTime :: String - Maybe UTCTime
tryParseTime timeStr = tryFormat (parseTime defaultTimeLocale timeFormat1
timeStr :: Maybe UTCTime)
   where
 tryFormat time
| time == Nothing = parseTime defaultTimeLocale timeFormat2 timeStr
:: Maybe UTCTime
| otherwise = time
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Where threadSleep is defined?

2011-12-06 Thread dokondr
Hi,
I need to make the current process (executing thread) go to sleep for a
given amount of time.  Can't find where threadSleep is defined.

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Where threadSleep is defined?

2011-12-06 Thread dokondr
I was trying to google haskell process sleep without much success. It
really needs some experience to construct hoogle queries correctly :)
Thanks everybody for your help!

On Tue, Dec 6, 2011 at 8:07 PM, Paul R paul.r...@gmail.com wrote:

 dokondr Hi, I need to make the current process (executing thread) go to
 dokondr sleep for a given amount of time.  Can't find where threadSleep
 dokondr is defined.

 Maybe because there is no such threadSleep function in base packages,
 what do you think ?

 Ok, let's see if we can find what you are looking for ... You want
 a function that will pause your thread for an amout of time then pass.
 In other word, it would take an Int and do nothing else than wait as
 a side effect, right ? Something typed Int - IO () should do that,
 right ?

  http://www.haskell.org/hoogle/?hoogle=Int+-%3E+IO+%28%29

  = threadDelay :: Int - IO ()
 Suspends the current thread for a given number of microseconds ...

 And if you don't want to use the amazing power of hoogle, maybe you can
 simply go to your favorite search engine and type haskell pause thread
 in it. In mine, the first result is the doc of the Control.Concurrent
 module that has a Waiting section (linked in the toc) that has ...
 3 functions, amongst wich threadDelay :: Int - IO ().

 Wasn't hard, was it ?

 --
  Paul

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to get a file path to the program invoked?

2011-12-05 Thread dokondr
This is how I finally solved this problem for POSIX complaint system:

--
-- TestRun
--
module Main where
import System.Cmd (rawSystem)
import System.Directory (getCurrentDirectory)
import System.Environment.Executable (ScriptPath(..), getScriptPath)
import System.FilePath.Posix (splitFileName)

main = do

  path - getMyPath
  putStrLn $ myPath =  ++ path
  let cmdLine = path ++ args.sh
  rawSystem cmdLine  [iphone, test-twitts.txt]

{--
data ScriptPath Source

Constructors:
Executable FilePathit was (probably) a proper compiled executable
RunGHC FilePathit was a script run by runghc/runhaskell
Interactive we are in GHCi
--}

getMyPath = do
  curDir - getCurrentDirectory -- from System.Directory
  scriptPath  - getScriptPath -- from System.Environment.Executable
  let path = getMyPath' scriptPath curDir
  return path

getMyPath' (Executable path) _ = fst (splitFileName path)
getMyPath' (RunGHC path) _  = fst (splitFileName path)
getMyPath' Interactive curDir = curDir++/


-- 
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] writeFile: commitBuffer: invalid argument (Illegal byte sequence)

2011-12-05 Thread dokondr
I don't actually need UTF-16 code in these strings. I would rather filter
them out before writing such strings to a file.
What would be a simple filter to do this?

*Albert Y. C. Lai* trebla at vex.net
haskell-cafe%40haskell.org?Subject=Re%3A%20%5BHaskell-cafe%5D%20writeFile%3A%20commitBuffer%3A%20invalid%20argument%0A%20%28Illegal%20byte%20sequence%29In-Reply-To=%3C4EDBBEB6.3050201%40vex.net%3E
wrote:

On 11-12-04 07:08 AM, dokondr wrote: * In GHC 7.0.3 / Mac OS X when trying
to: ** ** writeFile someFile (Hoping You Have A iPhone When I Do This)
Lol ** Sleep Is When You Close These ---gt; \55357\56384 ** ** I get: *
* commitBuffer: invalid argument (Illegal byte sequence) ** ** The
string I am trying to write can also be seen here: **
http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
** 
http://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
*

\55357 and \56384 would be surrogates D83D and DC40 for use in UTF-16 only.
Haskell's Char is not a UTF-16 code unit (unlike early versions of Java and
probably current ones). GHC is correct in rejecting them. Haskell's Char is
a Unicode character directly. If you want the character U+1F440 EYES,
write \128064 directly (or \x1f440, or \x1F440). Use
http://www.unicode.org/charts/ to find out what you are getting into. You
can enter a hexadecimal number or choose a category.

On Sun, Dec 4, 2011 at 11:43 PM, Erik Hesselink hessel...@gmail.com wrote:

 Yes, you can set the text encoding on the handle you're reading this
 text from [1]. The default text encoding is determined by the
 environment, which is why I asked about LANG.

 If you're entering literal strings, see Albert Lai's answer.

 Erik

 [1]
 http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-IO.html#g:23

 On Sun, Dec 4, 2011 at 19:13, dokondr doko...@gmail.com wrote:
  Is there any other way to solve this problem without changing LANG
  environment variable?
 
 
  On Sun, Dec 4, 2011 at 8:27 PM, Erik Hesselink hessel...@gmail.com
 wrote:
 
  What is the value of your LANG environment variable? Does it still
  give the error if you set it to e.g. en_US.UTF-8?
 
  Erik
 
  On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote:
   Correct url of a bad string:
  
  
 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
  
  
   On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote:
  
   Hi,
   In  GHC 7.0.3 / Mac OS X when trying to:
  
   writeFile  someFile (Hoping You Have A iPhone When I Do This) Lol
   Sleep
   Is When You Close These ---gt; \55357\56384
  
   I get:
   commitBuffer: invalid argument (Illegal byte sequence)
  
   The string I am trying to write can also be seen here:
  
  
  
 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
  
   It looks like 'writeFile' can not write unicode characters.
   Any workarounds?
  
   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] How to get a file path to the program invoked?

2011-12-05 Thread dokondr
Balazs, thanks for your comments!
The first comment works just fine.
With / operator I get this:

Main System.Environment.Executable System.FilePath /abc / /
/

Instead of getting /abc/ I get /. What am I doing wrong?

On Mon, Dec 5, 2011 at 6:03 PM, Balazs Komuves bkomu...@gmail.com wrote:


 Two small comments:

 1) This should work on Windows too, if you just leave out the word Posix
 from the source:
 import System.FilePath (splitFileName)

 2) In general when dealing with paths, use the / operator (from
 System.FilePath)
 instead of ++ / ++

 Balazs


 On Mon, Dec 5, 2011 at 1:44 PM, dokondr doko...@gmail.com wrote:

 This is how I finally solved this problem for POSIX complaint system:

 --
 -- TestRun
 --
 module Main where
 import System.Cmd (rawSystem)
 import System.Directory (getCurrentDirectory)
 import System.Environment.Executable (ScriptPath(..), getScriptPath)
 import System.FilePath.Posix (splitFileName)

 main = do

   path - getMyPath
   putStrLn $ myPath =  ++ path
   let cmdLine = path ++ args.sh
   rawSystem cmdLine  [iphone, test-twitts.txt]

 {--
 data ScriptPath Source

 Constructors:
 Executable FilePathit was (probably) a proper compiled executable
 RunGHC FilePathit was a script run by runghc/runhaskell
 Interactive we are in GHCi
 --}

 getMyPath = do
   curDir - getCurrentDirectory -- from System.Directory
   scriptPath  - getScriptPath -- from System.Environment.Executable
   let path = getMyPath' scriptPath curDir
   return path

 getMyPath' (Executable path) _ = fst (splitFileName path)
 getMyPath' (RunGHC path) _  = fst (splitFileName path)
 getMyPath' Interactive curDir = curDir++/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to get a file path to the program invoked?

2011-12-05 Thread dokondr
Thanks,
'addTrailingPathSeparator' works just fine !

On Mon, Dec 5, 2011 at 7:52 PM, Erik Hesselink hessel...@gmail.com wrote:

 The operator / is an alias for `combine`, which the documentation says:

  Combine two paths, if the second path isAbsolute, then it returns the
 second.

 In this case, / is absolute, so it is returned.

 If you wish to add a trailing path separator, use
 `addTrailingPathSeparator`.

 Erik

 On Mon, Dec 5, 2011 at 15:53, dokondr doko...@gmail.com wrote:
  Balazs, thanks for your comments!
  The first comment works just fine.
  With / operator I get this:
 
  Main System.Environment.Executable System.FilePath /abc / /
  /
 
  Instead of getting /abc/ I get /. What am I doing wrong?
 
  On Mon, Dec 5, 2011 at 6:03 PM, Balazs Komuves bkomu...@gmail.com
 wrote:
 
 
  Two small comments:
 
  1) This should work on Windows too, if you just leave out the word
 Posix
  from the source:
  import System.FilePath (splitFileName)
 
  2) In general when dealing with paths, use the / operator (from
  System.FilePath)
  instead of ++ / ++
 
  Balazs
 
 
  On Mon, Dec 5, 2011 at 1:44 PM, dokondr doko...@gmail.com wrote:
 
  This is how I finally solved this problem for POSIX complaint system:
 
  --
  -- TestRun
  --
  module Main where
  import System.Cmd (rawSystem)
  import System.Directory (getCurrentDirectory)
  import System.Environment.Executable (ScriptPath(..), getScriptPath)
  import System.FilePath.Posix (splitFileName)
 
  main = do
 
path - getMyPath
putStrLn $ myPath =  ++ path
let cmdLine = path ++ args.sh
rawSystem cmdLine  [iphone, test-twitts.txt]
 
  {--
  data ScriptPath Source
 
  Constructors:
  Executable FilePathit was (probably) a proper compiled executable
  RunGHC FilePathit was a script run by runghc/runhaskell
  Interactive we are in GHCi
  --}
 
  getMyPath = do
curDir - getCurrentDirectory -- from System.Directory
scriptPath  - getScriptPath -- from System.Environment.Executable
let path = getMyPath' scriptPath curDir
return path
 
  getMyPath' (Executable path) _ = fst (splitFileName path)
  getMyPath' (RunGHC path) _  = fst (splitFileName path)
  getMyPath' Interactive curDir = curDir++/
 
 
 
  ___
  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] writeFile: commitBuffer: invalid argument (Illegal byte sequence)

2011-12-04 Thread dokondr
Hi,
In  GHC 7.0.3 / Mac OS X when trying to:

writeFile  someFile (Hoping You Have A iPhone When I Do This) Lol Sleep
Is When You Close These ---gt; \55357\56384

I get:
commitBuffer: invalid argument (Illegal byte sequence)

The string I am trying to write can also be seen here:
http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen

It looks like 'writeFile' can not write unicode characters.
Any workarounds?

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)

2011-12-04 Thread dokondr
Correct url of a bad string:
http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen

On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote:

 Hi,
 In  GHC 7.0.3 / Mac OS X when trying to:

 writeFile  someFile (Hoping You Have A iPhone When I Do This) Lol Sleep
 Is When You Close These ---gt; \55357\56384

 I get:
 commitBuffer: invalid argument (Illegal byte sequence)

 The string I am trying to write can also be seen here:

 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen

 It looks like 'writeFile' can not write unicode characters.
 Any workarounds?

 Thanks!
 Dmitri



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] writeFile: commitBuffer: invalid argument (Illegal byte sequence)

2011-12-04 Thread dokondr
Is there any other way to solve this problem without changing LANG
environment variable?

On Sun, Dec 4, 2011 at 8:27 PM, Erik Hesselink hessel...@gmail.com wrote:

 What is the value of your LANG environment variable? Does it still
 give the error if you set it to e.g. en_US.UTF-8?

 Erik

 On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote:
  Correct url of a bad string:
 
 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
 
 
  On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote:
 
  Hi,
  In  GHC 7.0.3 / Mac OS X when trying to:
 
  writeFile  someFile (Hoping You Have A iPhone When I Do This) Lol
 Sleep
  Is When You Close These ---gt; \55357\56384
 
  I get:
  commitBuffer: invalid argument (Illegal byte sequence)
 
  The string I am trying to write can also be seen here:
 
 
 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aenhttp://twitter.com/#%21/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
 
  It looks like 'writeFile' can not write unicode characters.
  Any workarounds?
 
  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


[Haskell-cafe] How to get a file path to the program invoked?

2011-12-01 Thread dokondr
Hi,
When my program starts it needs to know a complete path to the directory
from which it was invoked.
In terms of standard shell (sh) I need the Haskell function that will do
equivalent to:

#!/bin/sh
path=$(dirname $0)

How to get this path in Haskell?

getProgName :: IO String
defined System.Environment only returns a file name of the program without
its full path.

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to get a file path to the program invoked?

2011-12-01 Thread dokondr
System.Directory.getCurrentDirectory does not solve the problem.
System.Directory.getCurrentDirectory returns the directory *from which* the
program was called, also called working directory.
The directory *from which* the program was called is not the same that the
directory *where the program executable is*, which my program needs to know.
For example:
/opt/myApp/test/myProg  - is a program
One may call it in many ways:
1)
cd /opt/myApp/test/
./myProg
Current or working directory: ./

or:

2)
cd /usr/local
/opt/myApp/test/myProg
Current or working directory: /usr/local

On the contrary, standard shell variable $0 - contains a full path to the
program location in the directory structure, no matter from what directory
the program was called.

How to find this path using GHC libraries?


On Thu, Dec 1, 2011 at 8:53 PM, Felipe Almeida Lessa felipe.le...@gmail.com
 wrote:


 Neither does $0, does it?  It depends on how the program is called.

 You can always use System.Directory.getCurrentDirectory with
 System.FilePath.{isRelative,replaceDirectory} if you somehow need the
 full path.  Note, however, that not even this is generally guaranteed
 to be correct.

 Cheers,

 --
 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] How to get a file path to the program invoked?

2011-12-01 Thread dokondr
To be precise, $0 always contains the path to the program called. You are
right, this path will change depending on location from which the program
was called. So $0 is OK for my case, while current directory  is unrelated.

Try this:

#!/bin/sh

echo Arg 0: $0
echo All Parameters:  [$@]

Again, any way to get the same functionality in GHC?


On Thu, Dec 1, 2011 at 10:32 PM, Giovanni Tirloni gtirl...@sysdroid.comwrote:

 On Thu, Dec 1, 2011 at 5:26 PM, dokondr doko...@gmail.com wrote:

 On the contrary, standard shell variable $0 - contains a full path to the
 program location in the directory structure, no matter from what directory
 the program was called.


 Are you sure?

 $ zero.sh
 ./zero.sh

 $ ./zero.sh
 ./zero.sh

 $ /home/gtirloni/zero.sh
 /home/gtirloni/zero.sh



 --
 Giovanni



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to get a file path to the program invoked?

2011-12-01 Thread dokondr
Balazs,  thanks!
It's great that these packages exist!


On Thu, Dec 1, 2011 at 11:17 PM, Balazs Komuves bkomu...@gmail.com wrote:


 Hello,

 I'm not subscribed to haskell cafe, but I browse the archives sometimes.

 As Simon Hengel wrote there, there are two packages on Hackage
 trying to solve this exact problem (since GHC and the standard library
 does not provide the necessary information):

 http://hackage.haskell.org/package/executable-path
 http://hackage.haskell.org/package/FindBin

 (Hackage is down at the moment, so I'm not completely sure about the
 second link).
 I'm the author of the first one.

 Balazs


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-11-16 Thread dokondr
Steve, thanks for sharing your experience with AWS!
At the moment I have evaluated several NoSQL storage solutions including
SimpleDB, Riak, MongoDB and Cassandra. Lessons learned:
1) Storage that SimpleDB provides is too low-level and not very convenient
to store dictionaries and other b-tree data structures that my app. works
with.
2) simpledb/dev simulator is out of date and does not support the
complete feature set of SimpleDB today. Thus, without major rewrite
simpledb/dev emulator can not be used for the development.
3) SimpleDB storage is 100% specific to Amazon framework. From this follows
that developing directly to SimpleDB interface will make app not portable
across different cloud platforms.
4) Cassandra row/column abstraction is awkward for Data.Map structures that
my app needs.
5) Riak provides convenient bucket/key/value abstraction and works in
robust to failure node framework. REST/JSON protocol is simple to use, yet
it is inefficient for data exchanges used by my app. I couldn't find simple
libraries for binary exchange that Riak also supports.
6) MongoDB answers my requirements best of all - it is powerful on a server
side (Javascript filters, etc) and works with efficient communication
protocol based on BSON data exchange.

I also plan to use RabitMQ  for communication between several Haskell
processes and Java Web front-end that my app incorporates.
It would be great to know what tools people use in the cloud (AWS, etc.) to
communicate Web front-end with rest of the (Haskell) system ?
What Haskell tools to build Web front-end?

Thanks!
Dmitri


On Wed, Nov 16, 2011 at 9:01 PM, Steve Severance st...@medwizard.netwrote:

 We use AWS extensively. We use the aws package and have contributed to it,
 specifically SQS functionality. I will give you the rundown of what we do.

 We moved off of SimpleDb and now use mondodb. The reason is that simple db
 seemed to have problems with write pressure and there are not good tools
 for profiling your queries. My main application is extremely write heavy
 with a single instance needing to do 100s or 1000s of writes a second.
 Mongodb has worked well for us. I am scared of things like cassandra having
 looked at the code, however some people have made it work.

 We store data such as crawled web pages in S3. The files are lzma
 compressed and the data format is built on protocol buffers. We picked lzma
 for both storage costs of cold data and the fact that the pipe between S3
 and EC2 is somewhat limited and we want to make the most effective use of
 it as possible.

 In my experience AWS simulators are more trouble than they are worth since
 they don't accurately model the way AWS will respond to you under load. The
 free tier at AWS should allow you to experiment with building an app. The
 first couple of months of development cost us less than $1.

 Steve

 On Tue, Nov 1, 2011 at 1:27 AM, dokondr doko...@gmail.com wrote:



 On Tue, Nov 1, 2011 at 10:53 AM, Neil Davies 
 semanticphilosop...@gmail.com wrote:

 Word of caution

 Understand the semantics (and cost profile) of the AWS services first -
 you can't just open a HTTP connection and dribble data out over several
 days and hope for things to work. It is not a system that has that sort of
 laziness at its heart.

 AWS doesn't supply a traditional remote file store semantics - is
 queuing, simple database and object store have all been designed for large
 scale systems being offered as a service to a (potentially hostile) large
 set of users - you can see that in the way that things are designed. There
 are all sorts of (sensible from their point of view) performance related
 limits and retries.

 The challenge in designing nice clean layers on top of AWS is how/when
 to hide the transient/load related failures.



 As a straw-man approach I would go first to NData.Map backed by Data.Map
 with addition of flush function  to write Data.Map to external key-value
 store / NoSQL DB.
 Another requirement for NData.Map is concurrent consistency, so different
 clients could modify its state preserving happen-before relationship. For
 this I would add to NData.Map a reftresh function, that updates local
 copy from  external key-value store.

 As for hSimpleDB package, it looks like it doesn't build on ghc7:
 http://hackage.haskell.org/package/hSimpleDB


 The hSimpleDB package

 Interface to Amazon's SimpleDB service.
 PropertiesVersions0.1 http://hackage.haskell.org/package/hSimpleDB-0.1,
 0.2 http://hackage.haskell.org/package/hSimpleDB-0.2, *0.3*
 Dependenciesbase http://hackage.haskell.org/package/base-3.0.3.2 (≥3
  ≤4), bytestringhttp://hackage.haskell.org/package/bytestring-0.9.2.0,
 Crypto http://hackage.haskell.org/package/Crypto-4.2.4, 
 dataenchttp://hackage.haskell.org/package/dataenc-0.14.0.2,
 HTTP http://hackage.haskell.org/package/HTTP-4000.1.2, 
 hxthttp://hackage.haskell.org/package/hxt-9.1.4,
 network http://hackage.haskell.org/package/network-2.3.0.7, 
 old-localehttp

Re: [Haskell-cafe] Haskell Platform for OSX ?

2011-11-09 Thread dokondr
On Wed, Nov 9, 2011 at 3:48 AM, Rogan Creswick cresw...@gmail.com wrote:

 On Tue, Nov 8, 2011 at 4:30 PM, Giovanni Tirloni gtirl...@sysdroid.com
 wrote:
  3) How to install it into a separate location so it would not ruin my
  current platform?
 
   You can install it under a different username.


Haskell Platform (HP) is installed for *all* users in one location at OSX:
 /Library/Frameworks/GHC.framework/Versions/
total 8
drwxrwxr-x  4 root  admin  136 21 feb  2011 .
drwxrwxr-x  5 root  admin  170 21 feb  2011 ..
drwxrwxr-x  4 root  admin  136 11 jun  2010 612
lrwxr-xr-x  1 user  staff3 21 фев  2011 Current - 612

1) How different username will help here?
2) Is there any way to see what packages HP includes without actually
installing it? Some online document listing HP packages?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Easiest to use NoSQL storage with Haskell?

2011-11-09 Thread dokondr
Hi,
What  Haskell package to work with NoSQL storage is both mature and easiest
to use?
I need persistent storage for simple key/value lists (not complex JSON
docs).
CouchDB and Cassandra seems to be overkill for my needs. What about Riak,
MongoDB,  Voldemort, etc. ?

Thanks!
Dmitri.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Platform for OSX ?

2011-11-09 Thread dokondr
On Wed, Nov 9, 2011 at 2:11 PM, Giovanni Tirloni gtirl...@sysdroid.comwrote:

 I meant install new packages through cabal under a different username. The
 cabal repo should be localized unless you specify --global

 Please see Rogan's suggestions.


Thanks for your help!
In case I upgrade to the latest Haskell Platform, what will happen to
packages already installed  in my ~/.cabal folder? Some of these are quite
old and most probably will be incompatible with GHC 7
Does upgrade process remove old  and create anew ~/.cabal folder?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Easiest to use NoSQL storage with Haskell?

2011-11-09 Thread dokondr
On Wed, Nov 9, 2011 at 5:46 PM, Daniel Schoepe dan...@schoepe.org wrote:

 On Wed, 9 Nov 2011 13:59:46 +0300, dokondr doko...@gmail.com wrote:
  Hi,
  What  Haskell package to work with NoSQL storage is both mature and
 easiest
  to use?
  I need persistent storage for simple key/value lists (not complex JSON
  docs).
  CouchDB and Cassandra seems to be overkill for my needs. What about Riak,
  MongoDB,  Voldemort, etc. ?

 persistent (part of yesod, but useable without other yesod libraries) is
 quite pleasant to use and supports MongoDB:

 http://hackage.haskell.org/package/persistent-0.6.4
 http://hackage.haskell.org/package/persistent-mongoDB-0.6.3

 Cheers,
 Daniel


I am wondering if Database.Persist can work with key/value storage such as
Riak or SimpleDB where records are lists of key/value pairs and any two
lists can have different keys?
Is simple implementation of 'persistent'  based on files with key/value
records possible?
For example 'persistent' based on KyotoCabinet package?
(http://hackage.haskell.org/package/KyotoCabinet)http://hackage.haskell.org/package/KyotoCabinet


Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Easiest to use NoSQL storage with Haskell?

2011-11-09 Thread dokondr
On Wed, Nov 9, 2011 at 8:41 PM, Bas van Dijk v.dijk@gmail.com wrote:

 On 9 November 2011 11:59, dokondr doko...@gmail.com wrote:
  What  Haskell package to work with NoSQL storage is both mature and
 easiest
  to use?
  I need persistent storage for simple key/value lists (not complex JSON
  docs).

 If your data fits in RAM then acid-state is also an option:

 http://hackage.haskell.org/package/acid-state

 It's used as the storage library for the new hackage server.


I need to share data across processes running both on the same node or
different nodes. Every process has its own memory space.
Can acid-state memory be shared between several system processes?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] cabal install: Could not find module `Text.XML.HXT.Arrow'

2011-11-08 Thread dokondr
Hi,
On Mac OSX, ghc-6.12.3, I have successfully installed the 'hxt' package:
http://hackage.haskell.org/package/hxt-8.5.2

Registering hxt-9.1.4...
Installing library in /Users/user/.cabal/lib/hxt-9.1.4/ghc-6.12.3

Now when I try to install hSimpleDB (
http://hackage.haskell.org/package/hSimpleDB) I get the following error:

cabal install hSimpleDB
...
Registering HTTP-4000.0.9...
Installing library in /Users/user/.cabal/lib/HTTP-4000.0.9/ghc-6.12.3
Registering HTTP-4000.0.9...
Configuring hSimpleDB-0.3...
Preprocessing library hSimpleDB-0.3...
Building hSimpleDB-0.3...

src/Network/AWS/Authentication.hs:47:7:
Could not find module `Text.XML.HXT.Arrow':
  Use -v to see a list of the files searched for.
cabal: Error: some packages failed to install:
hSimpleDB-0.3 failed during the building phase. The exception was:
ExitFailure 1

Any ideas how to solve this?

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] cabal install: Could not find module `Text.XML.HXT.Arrow'

2011-11-08 Thread dokondr
Thanks,
Alas adding '--constraint=hxt==9.0.\*' after cabal-install command does not
help. I get the same error.

On Tue, Nov 8, 2011 at 2:10 PM, Erik Hesselink hessel...@gmail.com wrote:

 This is because hSimpleDB doesn't specify version ranges on its
 dependencies, when it should. Since hxt changed its module structure
 going from 9.0 to 9.1, hSimpleDB doesn't build against 9.0.

 You can try to build it by adding '--constraint=hxt==9.0.\*' after
 your cabal-install command. You can also ask the author to add version
 ranges to the package.

 Erik

 On Tue, Nov 8, 2011 at 11:58, dokondr doko...@gmail.com wrote:
  Hi,
  On Mac OSX, ghc-6.12.3, I have successfully installed the 'hxt' package:
  http://hackage.haskell.org/package/hxt-8.5.2
 
  Registering hxt-9.1.4...
  Installing library in /Users/user/.cabal/lib/hxt-9.1.4/ghc-6.12.3
 
  Now when I try to install hSimpleDB
  (http://hackage.haskell.org/package/hSimpleDB) I get the following
 error:
 
  cabal install hSimpleDB
  ...
  Registering HTTP-4000.0.9...
  Installing library in /Users/user/.cabal/lib/HTTP-4000.0.9/ghc-6.12.3
  Registering HTTP-4000.0.9...
  Configuring hSimpleDB-0.3...
  Preprocessing library hSimpleDB-0.3...
  Building hSimpleDB-0.3...
 
  src/Network/AWS/Authentication.hs:47:7:
  Could not find module `Text.XML.HXT.Arrow':
Use -v to see a list of the files searched for.
  cabal: Error: some packages failed to install:
  hSimpleDB-0.3 failed during the building phase. The exception was:
  ExitFailure 1
 
  Any ideas how to solve this?
 
  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] cabal install: Could not find module `Text.XML.HXT.Arrow'

2011-11-08 Thread dokondr
On Tue, Nov 8, 2011 at 2:31 PM, Audun Skaugen audunskau...@gmail.comwrote:

 Erik Hesselink wrote:

 On Tue, Nov 8, 2011 at 12:16, Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com wrote:


 On 8 November 2011 22:10, Erik Hesselink hessel...@gmail.com wrote:


 This is because hSimpleDB doesn't specify version ranges on its
 dependencies, when it should. Since hxt changed its module structure
 going from 9.0 to 9.1, hSimpleDB doesn't build against 9.0.

 You can try to build it by adding '--constraint=hxt==9.0.\*' after
 your cabal-install command. You can also ask the author to add version
 ranges to the package.


 Is the escape needed if you're using single quotes?



 I don't know. I always escape *s in shell commands to be sure the
 shell doesn't expand them, but in most of the cases, it probably works
 without them. It will likely even work without quotes and without the
 escape, unless you have files matching the pattern.


 The single quote doesn't expand anything, so you don't need to escape the
 *. Actually, this will result in the backslash also being passed to cabal,
 so I would be surprised if your command works at all.



No matter how you escape *, you get the same error:

Preprocessing library hSimpleDB-0.3...
Building hSimpleDB-0.3...

src/Network/AWS/Authentication.hs:47:7:
Could not find module `Text.XML.HXT.Arrow':
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] cabal install: Could not find module `Text.XML.HXT.Arrow'

2011-11-08 Thread dokondr
Package Text.XML.HXT.Arrow existed only in 8.5.2 version of hxt:
http://hackage.haskell.org/packages/archive/hxt/8.5.2/doc/html/Text-XML-HXT-Arrow.html

Yet trying to install with this version produce even more problems:

~cabal --constraint=hxt==8.5.2 install hSimpleDB
Resolving dependencies...
cabal: cannot configure Crypto-4.2.3. It requires QuickCheck =2.4.0.1
For the dependency on QuickCheck =2.4.0.1 there are these packages:
QuickCheck-2.4.0.1, QuickCheck-2.4.1 and QuickCheck-2.4.1.1. However none of
them are available.
QuickCheck-2.4.0.1 was excluded because tagsoup-0.8 requires QuickCheck
==2.1.*
QuickCheck-2.4.1 was excluded because tagsoup-0.8 requires QuickCheck
==2.1.*
QuickCheck-2.4.1.1 was excluded because tagsoup-0.8 requires QuickCheck
==2.1.*


On Tue, Nov 8, 2011 at 2:43 PM, dokondr doko...@gmail.com wrote:



 On Tue, Nov 8, 2011 at 2:31 PM, Audun Skaugen audunskau...@gmail.comwrote:

 Erik Hesselink wrote:

 On Tue, Nov 8, 2011 at 12:16, Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com wrote:


 On 8 November 2011 22:10, Erik Hesselink hessel...@gmail.com wrote:


 This is because hSimpleDB doesn't specify version ranges on its
 dependencies, when it should. Since hxt changed its module structure
 going from 9.0 to 9.1, hSimpleDB doesn't build against 9.0.

 You can try to build it by adding '--constraint=hxt==9.0.\*' after
 your cabal-install command. You can also ask the author to add version
 ranges to the package.


 Is the escape needed if you're using single quotes?



 I don't know. I always escape *s in shell commands to be sure the
 shell doesn't expand them, but in most of the cases, it probably works
 without them. It will likely even work without quotes and without the
 escape, unless you have files matching the pattern.


 The single quote doesn't expand anything, so you don't need to escape the
 *. Actually, this will result in the backslash also being passed to cabal,
 so I would be surprised if your command works at all.



 No matter how you escape *, you get the same error:


 Preprocessing library hSimpleDB-0.3...
 Building hSimpleDB-0.3...

 src/Network/AWS/Authentication.hs:47:7:
 Could not find module `Text.XML.HXT.Arrow':


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell Platform for OSX ?

2011-11-08 Thread dokondr
Hi,
I am running GHC 6.12.3 at Mac OSX and have numerous problems with 'cabal
install' of different packages.
For example:
~cabal install mongoDB
Resolving dependencies...
Configuring mongoDB-1.1.0...
Preprocessing library mongoDB-1.1.0...
Building mongoDB-1.1.0...
...
Control/Monad/MVar.hs:16:34:
Module `Control.Exception.Control' does not export `mask'
cabal: Error: some packages failed to install:
mongoDB-1.1.0 failed during the building phase. The exception was:
ExitFailure 1

Questions about current Haskell Platform for OSX  2011.2.0.1. :
(http://hackage.haskell.org/platform/mac.html)

1) Where can I find release notes to understand what version of GHC Haskell
Platform for OSX  2011.2.0.1 includes?
2) Will I be able to install mongoDB-1.1.0 on this release?
3) How to install it into a separate location so it would not ruin my
current platform?

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-11-01 Thread dokondr
On Tue, Nov 1, 2011 at 5:03 AM, Ryan Newton rrnew...@gmail.com wrote:

  Any example code of using hscassandra package would really help!


 I'll ask my student.  We may have some simple examples.

 Also, I have no idea as to their quality but I was pleasantly surprised to
 find three different amazon related packages on Hackage (simply by
 searching for the word Amazon in the package list).

http://hackage.haskell.org/package/hS3
http://hackage.haskell.org/package/hSimpleDB
http://hackage.haskell.org/package/aws

 It would be great to know if these work.


Thinking about how to implement Data.Map on top of hscassandra or any other
key-value storage ...
For example creating new map with fromList will require to store *all*
(key, value) list elements in external storage at once. How to deal with
laziness in this case?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-11-01 Thread dokondr
On Tue, Nov 1, 2011 at 10:53 AM, Neil Davies
semanticphilosop...@gmail.comwrote:

 Word of caution

 Understand the semantics (and cost profile) of the AWS services first -
 you can't just open a HTTP connection and dribble data out over several
 days and hope for things to work. It is not a system that has that sort of
 laziness at its heart.

 AWS doesn't supply a traditional remote file store semantics - is queuing,
 simple database and object store have all been designed for large scale
 systems being offered as a service to a (potentially hostile) large set of
 users - you can see that in the way that things are designed. There are all
 sorts of (sensible from their point of view) performance related limits and
 retries.

 The challenge in designing nice clean layers on top of AWS is how/when to
 hide the transient/load related failures.



As a straw-man approach I would go first to NData.Map backed by Data.Map
with addition of flush function  to write Data.Map to external key-value
store / NoSQL DB.
Another requirement for NData.Map is concurrent consistency, so different
clients could modify its state preserving happen-before relationship. For
this I would add to NData.Map a reftresh function, that updates local
copy from  external key-value store.

As for hSimpleDB package, it looks like it doesn't build on ghc7:
http://hackage.haskell.org/package/hSimpleDB


 The hSimpleDB package

 Interface to Amazon's SimpleDB service.
 PropertiesVersions0.1 http://hackage.haskell.org/package/hSimpleDB-0.1,
 0.2 http://hackage.haskell.org/package/hSimpleDB-0.2, *0.3*Dependencies
 base http://hackage.haskell.org/package/base-3.0.3.2 (≥3  ≤4),
 bytestring http://hackage.haskell.org/package/bytestring-0.9.2.0, 
 Cryptohttp://hackage.haskell.org/package/Crypto-4.2.4,
 dataenc http://hackage.haskell.org/package/dataenc-0.14.0.2, 
 HTTPhttp://hackage.haskell.org/package/HTTP-4000.1.2,
 hxt http://hackage.haskell.org/package/hxt-9.1.4, 
 networkhttp://hackage.haskell.org/package/network-2.3.0.7,
 old-locale http://hackage.haskell.org/package/old-locale-1.0.0.3,
 old-time http://hackage.haskell.org/package/old-time-1.0.0.7,
 utf8-string http://hackage.haskell.org/package/utf8-string-0.3.7License
 BSD3AuthorDavid Himmelstrup 2009, Greg Heartsfield 2007MaintainerDavid
 Himmelstrup 
 lem...@gmail.comCategoryDatabasehttp://hackage.haskell.org/packages/archive/pkg-list.html#cat:database,
 Web http://hackage.haskell.org/packages/archive/pkg-list.html#cat:web,
 Networkhttp://hackage.haskell.org/packages/archive/pkg-list.html#cat:networkUpload
 dateThu Sep 17 17:09:26 UTC 2009Uploaded byDavidHimmelstrupBuilt onghc-6.10,
 ghc-6.12Build failureghc-7.0 
 (loghttp://hackage.haskell.org/packages/archive/hSimpleDB/0.3/logs/failure/ghc-7.0
 )

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Persistent Concurrent Data Structures

2011-11-01 Thread dokondr
Hi,
Please comment on the idea and advise on steps to implement it.
Real world applications need persistent data, that can be accessed and
modified concurrently by several clients, in a way that preserves
happen-before relationship.
Idea: Design and implement Persistent Concurrent Data Types in Haskell.
These data types should mirror existing Data.List , Data.Map and similar
types but provide persistency and support consistent concurrent access and
modification (or simply - concurrency).
Persistency and concurrency should be configurable through these type
interfaces. Configuration should include:
1) Media to persist data, such as file, DBMS, external key-value store (for
example Amazon SimpleDB, CouchDB, MongoDB, Redis, etc)
2) Caching policy - when (on what events) and how much data to read/write
from/to persistent media. Media reads / writes can be done asynchronously
in separate threads.
3) Concurrency configuration: optimistic or pessimistic data locking.

One may ask why encapsulate persistency and concurrency in the data type
instead of using native storage API, such as for example key-value /
row-column API that  NoSQL databases provide?
The answer is simple: APIs that your code use greatly influence the code
itself. Using low-level storage  API directly in your code results in
bloated obscure code, or you need to encapsulate this low-level API in
clear and powerful abstractions. So why not to do this encapsulation once
and for all for such powerful types as Data.Map, for example, and forget
all Cassandra and SimpleDB low-level access method details?
When the right time comes and you will need to move your application to the
next new shiny_super_cloud, you will just write the implementation of
NData.Map backed by Data.Map in terms of low-level API of this super-cloud.

(Side note: I really need such a NData.Map type. I was requested to move my
code that heavily uses Data.Map and simple text file persistence into
Amazon AWS cloud. Looking at SimpleDB API, I realized that I will have to
rewrite 90% of code. This rewrite will greatly bloat my code and will make
it very unreadable. In case I had NData.Map I would just switch
implementation from 'file' to SimpleDB persistency inside my NData.Map
type.)

Implementation:
To start playing with this idea, NData.Map persisted in a regular file will
do, no concurrency yet. Next step -   NData.Map persisted in SimpleDB or
Cassandra or Redis, with concurrent access supported.

So it looks like  NData.Map should be a monad ...
Any ideas on implementation and similar work?

Thanks!
Dmitri
---
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] Persistent Concurrent Data Structures

2011-11-01 Thread dokondr
Thanks everybody for advice!
I'll try to clarify what I mean by persistence and concurrent access that
preserves happens-before relationship.
1) Persistence - imagine Haskell run-time executing in infinite physical
memory. My idea is to implement really huge,  almost infinite memory in
the cloud of one or another type. Nothing more nothing less, nothing
imperative, exactly the same environment that GHC runtime  works today, but
extended to huge virtual memory in the cloud.

2) Concurrent access that preserves happens-before relationship. Before
talking about transactions, I would use locking data structures in two
different ways:
- Optimistic lock - everybody can read and write / delete simultaneously,
system ensures only happens-before relationship. In other words Best
Effort Modification - you can try to modify data, but there is no guarantee
that  your modification will work.
- Pessimistic lock - when you get lock - structure is all yours  as long as
you held the lock - everybody else can only read, happens-before
relationship is ensured at all times.
About happens-before relationship:
http://en.wikipedia.org/wiki/Happened-before
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Persistent Concurrent Data Structures

2011-11-01 Thread dokondr
On Wed, Nov 2, 2011 at 3:12 AM, dokondr doko...@gmail.com wrote:

 Thanks everybody for advice!
 I'll try to clarify what I mean by persistence and concurrent access that
 preserves happens-before relationship.
 1) Persistence - imagine Haskell run-time executing in infinite physical
 memory. My idea is to implement really huge,  almost infinite memory in
 the cloud of one or another type. Nothing more nothing less, nothing
 imperative, exactly the same environment that GHC runtime  works today, but
 extended to huge virtual memory in the cloud.


I am afraid I am confused everybody, didn't mean it, sorry. I understand
that  infinite physical memory is not quite the same that implementing
NData.* on top of some cloud framework. Yet NData.* may be the first step
in this direction. Infinite memory will require support in Haskell
run-time, run-time distributed across many physical instances. Yet, it
looks like physical memory will eventually will be very huge virtual memory
persistent in the cloud for some period of time. IMHO this will simplify
programming model considerably.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-10-31 Thread dokondr
Hi,
Please share your experience / ideas on AWS storage most friendly to
Haskell.
So far I store my data mostly in Data.Map structures serialized to text
files with write / read functions. Now I was requested to move my app and
data to Amazon cloud. As far as I know there are two main storage types
that Amazon provides: S3 - basic block storage and SimpleDB (
http://docs.amazonwebservices.com/AmazonSimpleDB/latest/GettingStartedGuide/
)
Questions:
1) I would like to continue working with my data using abstractions similar
to the ones that Data.Map provides. Any ideas how to iterate and modify
SimpleDB records in a similar powerful way as provided by Data.Map? Or
maybe S3?
2) It would be great to do development and testing offline without actually
connecting to AWS S3 / SimpleDB. Are there any AWS simulators + Haskell
libraries that  will allow to do such an offline development?
3) Any experience / ideas  with Haskell libs for NoSQL, not AWS-native,
storages, that will run well both offline and in AWS?
4) My code processes hundreds of messages. Every message is processed in
exactly the same way as the others. So the code can be easily parallelized.
Any Haskell frameworks that will allow me to run this code in a simple
concurrency model?

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-10-31 Thread dokondr
On Mon, Oct 31, 2011 at 6:50 PM, John Lenz l...@math.uic.edu wrote:


 4) My code processes hundreds of messages. Every message is processed in

 exactly the same way as the others. So the code can be easily
 parallelized. Any Haskell frameworks that will allow me to run this code
 in a simple concurrency model?


 Yes, there are many options.

 http://www.haskell.org/**haskellwiki/GHC/Concurrencyhttp://www.haskell.org/haskellwiki/GHC/Concurrency



John, thanks for detailed reply!
I am looking at Haskell Concurrency wiki, but can not figure out which
framework - STM, sparks, threads, etc. Amazon AWS will be able to scale?
As far as I know, to scale CPU and program memory in Amazon, all you can
ask from AWS is to start some number of additional extra VMs. Every VM
contains a complete image of your OS and executables, all images are
exactly the same.
That's fine with me as currently all my workflow tasks are performed by
separately compiled Haskell executables communicating via regular files.
So to reformulate my question:
- Does any Haskell  framework exist that allow to orchestrate separate
processes  (NOT threads that share the same process memory)?
On the other hand, in case there is a way to make Amazon AWS  to scale
Haskell STM, sparks, threads, etc. - I would happily rewrite my Haskell
code to use these frameworks.  So my second question:
- Is there a way to make Amazon AWS  to scale Haskell STM, sparks, threads
or any other Haskell concurrency frameworks?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-10-31 Thread dokondr
On Mon, Oct 31, 2011 at 6:50 PM, John Lenz l...@math.uic.edu wrote:

 CouchDB works great, although I decided to go with SimpleDB since then it
 is amazon's problem to scale and allocate disk and so forth, which I like
 better.  For couchdb, you can use my package couchdb-enumerator on hackage.


 Regarding CouchDB. So far I have my records keyed by Id and stored in
Data.Map which I serialize to  text file. Using Data.Map functions I do
many operations with these records including mapping functions over keys
and values, accumulation, lookup, intersection, union etc.
When I move this data to CouchDB and start using couchdb-enumerator to work
with it, how natural will it be to implement all these functions that I use
from Data.Map?
Or maybe it makes more sense to store my serialized Data.Map as a blob in
CouchDB? And do not use views or similar CouchDB / SimpleDB interfaces at
all?  Just retrieve necessary blob and deserialize it to Data.Map, update
and then store modified blob to CouchDB again?

It would be great if somebody had time to implement Data.List, Data.Map,
etc on top of generic  NoSQL DB interface with specific instances for
CouchDB, SimpleDB, etc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Amazon AWS storage best to use with Haskell?

2011-10-31 Thread dokondr
On Tue, Nov 1, 2011 at 12:07 AM, Ryan Newton rrnew...@gmail.com wrote:

 ...
 For a NOSQL layer -- I'm looking for the answer to that same question
 myself!  We've been experimenting with Cassandra (used via the hscassandra
 package based in turn on cassandra-thrift).  Already it's clear that there
 are many areas that need work.  The Haskell code generated by Thrift itself
 has a lot of room for improvement (for the intrepid hacker: cycles there
 would be well-spent).


Any example code of using hscassandra package would really help!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Libraries to compare trees?

2011-10-28 Thread dokondr
On Fri, Oct 28, 2011 at 2:31 AM, Ivan Lazar Miljenovic 
ivan.miljeno...@gmail.com wrote:

 Well, for arbitrary directed graphs, FGL is probably your best bet, or
 roll-your-own.

 _But_ you'll need to write the parser yourself using something like
 trifecta, uu-parsinglib, polyparse, parsec, etc.

 It would help if you described the structure of these graphs and what
 kind of support you'd want in a data structure.



Thanks for the feedback!
As I wrote in first message I need to compare both structure and node
contents of two graphs, find similar sub-graphs, and need some metric to
measure distance between two graphs. These graphs are produced by POS (part
of speech) sentence tagging. POS tagging is done by Standford statistical
parser: http://nlp.stanford.edu/software/lex-parser.shtml

For example in the graph G1:
(ROOT
  (S
(NP (DT The) (NN voice) (NN quality))
(VP (VBD was)
  (ADJP (JJ clear) (RB too)))
(. .)))

G1 has an NP node (lets call this sub-graph SG1)  which has three child leaf
nodes: (DT The) (NN voice) (NN quality), where
DT, NN - nodes names, and
The, voice, quality - corresponding leaf values of these nodes.

I need to compare this graph with graph G2:
(ROOT
  (S
(SBAR (IN Although)
  (S
(NP (DT the) (NN battery) (NN life))
(VP (VBD was) (RB not)
  (ADJP (JJ long)
(, ,)
(NP (DT that))
(VP (VBZ is)
  (VP (VBN ok)
(PP (IN for)
  (NP (PRP me)
(. .)))

G2 also has the NP node (let's call it sub-graph SG2)  which also has three
child leaf nodes: (DT the) (NN battery) (NN life))
I need to find that G1 and G2 has sub-graphs SG1 and SG2 with the similar
structure, but with different values of the leaf nodes.
I also need to devise some general metric that will allow me to estimate
distance between any two graphs. This distance should account both for
structural and leaf-node values similarity.

It would be easier to measure distance between vectors then graphs. So I am
thinking how to convert directed graph (that results from POS tagging) into
vector. Any ideas, links here?

Thanks!

On 28 October 2011 00:27, dokondr doko...@gmail.com wrote:
 My mistake: need advice on libraries and data types not for trees but for
 directed graphs.

 On Thu, Oct 27, 2011 at 4:49 PM, dokondr doko...@gmail.com wrote:

 Please advise on Haskell libraries to compare trees in textual
 representation.
 I need to compare both structure and node contents of two trees, find
 similar sub-trees, and need some metric to measure distance between two
 trees.
 Also need advice on simple parser to convert textual tree representation
 into a data type convenient for tree manipulation (comparison, matching,
 etc.) What data type to use for trees with arbitrary structure?

 Example trees:

 *** Tree 1:
 (ROOT
   (S
 (NP (DT The) (NN voice) (NN quality))
 (VP (VBD was)
   (ADJP (JJ clear) (RB too)))
 (. .)))


 *** Tree 2:
 (ROOT
   (S
 (SBAR (IN Although)
   (S
 (NP (DT the) (NN battery) (NN life))
 (VP (VBD was) (RB not)
   (ADJP (JJ long)
 (, ,)
 (NP (DT that))
 (VP (VBZ is)
   (VP (VBN ok)
 (PP (IN for)
   (NP (PRP me)
 (. .)))

 Thanks!
 Dmitri







 ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 



 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com




-- 
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] Libraries to compare trees?

2011-10-27 Thread dokondr
Please advise on Haskell libraries to compare trees in textual
representation.
I need to compare both structure and node contents of two trees, find
similar sub-trees, and need some metric to measure distance between two
trees.
Also need advice on simple parser to convert textual tree representation
into a data type convenient for tree manipulation (comparison, matching,
etc.) What data type to use for trees with arbitrary structure?

Example trees:

*** Tree 1:
(ROOT
  (S
(NP (DT The) (NN voice) (NN quality))
(VP (VBD was)
  (ADJP (JJ clear) (RB too)))
(. .)))


*** Tree 2:
(ROOT
  (S
(SBAR (IN Although)
  (S
(NP (DT the) (NN battery) (NN life))
(VP (VBD was) (RB not)
  (ADJP (JJ long)
(, ,)
(NP (DT that))
(VP (VBZ is)
  (VP (VBN ok)
(PP (IN for)
  (NP (PRP me)
(. .)))

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Libraries to compare trees?

2011-10-27 Thread dokondr
My mistake: need advice on libraries and data types not for trees but for
directed graphs.

On Thu, Oct 27, 2011 at 4:49 PM, dokondr doko...@gmail.com wrote:

 Please advise on Haskell libraries to compare trees in textual
 representation.
 I need to compare both structure and node contents of two trees, find
 similar sub-trees, and need some metric to measure distance between two
 trees.
 Also need advice on simple parser to convert textual tree representation
 into a data type convenient for tree manipulation (comparison, matching,
 etc.) What data type to use for trees with arbitrary structure?

 Example trees:

 *** Tree 1:
 (ROOT
   (S
 (NP (DT The) (NN voice) (NN quality))
 (VP (VBD was)
   (ADJP (JJ clear) (RB too)))
 (. .)))


 *** Tree 2:
 (ROOT
   (S
 (SBAR (IN Although)
   (S
 (NP (DT the) (NN battery) (NN life))
 (VP (VBD was) (RB not)
   (ADJP (JJ long)
 (, ,)
 (NP (DT that))
 (VP (VBZ is)
   (VP (VBN ok)
 (PP (IN for)
   (NP (PRP me)
 (. .)))

 Thanks!
 Dmitri


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The best way to call Java from Haskell?

2011-10-11 Thread dokondr
On Tue, Oct 11, 2011 at 12:42 PM, Yitzchak Gale g...@sefer.org wrote:

 Dmitri wrote:
  I need to call Stanford NLP Parser from Haskell
  (unfortunately Haskell does not have a similar one)...

 Just out of curiosity, why do you not consider GF
 at all similar? To an outsider like me, there does
 appear to be quite a bit of similarity.

 http://www.grammaticalframework.org/

 Thanks,
 Yitz


As I understand GF is well suited for parsing well defined formal languages.
Not sure that GF can be used as NLP parser for blog messages that I need.
Please correct me if I am wrong.

As a general note, Java has tons of useful libraries that will take infinite
time to re-implement in Haskell. To my mind it makes a lot of sense to have
a reliable mechanism to call Java from Haskell.
BTW, yet another way to do this: wrap Java library in RESTFUL web service )

-- 
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] The best way to call Java from Haskell?

2011-10-10 Thread dokondr
Hi,
I need to call Stanford NLP Parser from Haskell (unfortunately Haskell does
not have a similar one):
http://nlp.stanford.edu/software/lex-parser.shtml

What would be the most reliable framework for this?

Thanks!
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread dokondr
On Wed, Aug 24, 2011 at 4:44 PM, Iustin Pop ius...@google.com wrote:

 On Wed, Aug 24, 2011 at 04:35:42PM +0400, dokondr wrote:
  Hi,
  What is the Haskell way to compose functions in run-time?
  Depending on configuration parameters I need to be able to compose
 function
  in several ways without recompilation.


A simple alternative to if would be:

  options = [ (foo, f1 . f2 . f3)
, (bar, f1 . f3 )]

 and then lookup param options. I don't know if this is what you're
 looking for, though.


Thanks!
Yes, this is what I need - simple and easy. Yet, how function application
will work in this case ?
I mean after lookup returns me a composition ... need to check what type
will it be.

-- 
All the best,
dokondr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function composition in run-time?

2011-08-24 Thread dokondr
On Wed, Aug 24, 2011 at 4:52 PM, Arseniy Alekseyev 
arseniy.alekse...@gmail.com wrote:

 If your functions have the same type, then you can easily collect them
 in a data structure, say list, and fold that.

 For example:

 function :: String - (String - String)
 function f1 = f1
 function f2 = f2
 function f3 = f3

 runAUserSpecifiedComposition :: String - F
 runAUserSpecifiedComposition = foldl (.) id . map function . words

 runAUserSpecifiedComposition f1 f2 f3 should be equal to (f1 . f2 . f3)
 now.


This is a nice one, looks already like tiny DSL )

I think I've got the main idea - enumerate in my program all function
compositions in some data structure for Haskell to compile, and the
associate these with parameter values in external file.

Thanks everybody!
dokondr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Actors, Linda, publish / subscribe models?

2011-08-15 Thread dokondr
On Mon, Aug 15, 2011 at 12:36 PM, Holger Reinhardt hreinha...@gmail.comwrote:

 Hi,

 the actor package seems unmaintained and probably doesn't fit your needs.
 If you want to implement some kind of publish/subscribe system over the
 network, I'd suggest you take a look at ZeroMQ[1] and AMQP[2].
 AMQP is probably easier to get started with, but it requires you to set up
 a dedicated broker, which (if you have very high throughput) might become a
 bottleneck. ZeroMQ, on the other hand, allows for a more decentralized
 architecture.

 Regards,
 Holger

 [1] http://hackage.haskell.org/package/zeromq-haskell
 [2] http://hackage.haskell.org/package/amqp


 Thanks! I will try these out.
I wish I could find something that will provide a *single* publish /
subscribe framework to work with threads *both* in the same and separate
address spaces.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Actors, Linda, publish / subscribe models?

2011-08-15 Thread dokondr
On Mon, Aug 15, 2011 at 11:41 PM, Ryan Newton rrnew...@gmail.com wrote:

 It seems that the recent Cloud Haskell paper is relevant:


 http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/remote.pdf

 The repo is here:

https://github.com/jepst/CloudHaskell

 I haven't tried it yet myself but would like to.

 Cheers,
   -Ryan


Thanks for the really great news!
Finally Erlang actor model of communication comes to Haskell!
I hope that one day Haskell will also evolve to provide dynamic code update
as Erlang does.
It would then be the ideal PL for reliable programming  of adaptive,
distributed real-world systems!

-- 
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] Haskell Actors, Linda, publish / subscribe models?

2011-08-14 Thread dokondr
On Sat, Aug 13, 2011 at 3:54 PM, dokondr doko...@gmail.com wrote:

 Hi,
 I am trying to figure out what Haskell libraries can be used to build
 publish / subscribe communication between threads running both in the same
 and different address spaces on the net.
 For my needs any of these models will work:
 - Actors [ http://en.wikipedia.org/wiki/Actor_model ]
 - Linda tuple space [
 http://en.wikipedia.org/wiki/Linda_%28coordination_language%29 ]
 - Publish / subscribe [
 http://en.wikipedia.org/wiki/Java_Message_Service#Publish.2Fsubscribe_model]

 I need to build a framework to coordinate task producers / consumers
 distributed in the same and different address spaces. I need to scale a data
 processing application somewhat Hadoop-like way yet in more flexible manner,
 without Hadoop-specific distributed FS constraints.

 Looking through Applications and libraries/Concurrency and parallelism:

 http://www.haskell.org/haskellwiki/Applications_and_libraries/Concurrency_and_parallelism

 I found Haskell actor package [
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/actor ] that
 fails to build with ghc 7.0.

 Please advise on latest working libraries.

 Thanks!



 Have anybody used Haskell actor package [
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/actor ]?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell Actors, Linda, publish / subscribe models?

2011-08-13 Thread dokondr
Hi,
I am trying to figure out what Haskell libraries can be used to build
publish / subscribe communication between threads running both in the same
and different address spaces on the net.
For my needs any of these models will work:
- Actors [ http://en.wikipedia.org/wiki/Actor_model ]
- Linda tuple space [
http://en.wikipedia.org/wiki/Linda_%28coordination_language%29 ]
- Publish / subscribe [
http://en.wikipedia.org/wiki/Java_Message_Service#Publish.2Fsubscribe_model]

I need to build a framework to coordinate task producers / consumers
distributed in the same and different address spaces. I need to scale a data
processing application somewhat Hadoop-like way yet in more flexible manner,
without Hadoop-specific distributed FS constraints.

Looking through Applications and libraries/Concurrency and parallelism:
http://www.haskell.org/haskellwiki/Applications_and_libraries/Concurrency_and_parallelism

I found Haskell actor package [
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/actor ] that
fails to build with ghc 7.0.

Please advise on latest working libraries.

Thanks!

-- 
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] Approximate String Matching

2011-07-27 Thread dokondr
Hi,
I am looking for Haskell libraries to do approximate string matching:
http://en.wikipedia.org/wiki/Approximate_string_matching
I need this to reduce a set of English word variants with spelling errors to
a single canonical dictionary entry.
Any libraries to work with spelling will also help.

Thanks,
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Library for Sparse Vectors?

2011-07-26 Thread dokondr
Hi,
Can't find on hackage any sparse vector library. Does such thing exist?
I need efficient storage and dot product calculation for very sparse
vectors with about 10 out of 40 000 non-zero components.
One solution would be to represent Sparse Vector as Data.Map with
(component_index, component_value) pairs to store non-zero components of the
vector.
In this case, for example, calculating cosine similarity (
http://en.wikipedia.org/wiki/Cosine_similarity) for for every pair of 10 000
vectors, would not be very nice and efficient, I am afraid.

Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Library for Sparse Vectors?

2011-07-26 Thread dokondr
Thanks for the detailed reply and example!
Using IntMap as a vector seems to be a good idea.
In your example:
1)  I would use:

   dot = dot' * dot'
   dot'  = sum . elems . intersectionWith (*)
   norm = sum . fmap (**2) . elems

 instead of:

dot  = sum . elems . intersectionWith (*)
norm = (**0.5) . sum . fmap (**2) . elems

2)  I don't understand the syntax:
cosineSimilarity $ lookup x space
 * lookup y space

What are $ and *?

Thanks,
Dmitri

On Wed, Jul 27, 2011 at 1:46 AM, Alexander Solla alex.so...@gmail.comwrote:



 On Tue, Jul 26, 2011 at 1:30 PM, dokondr doko...@gmail.com wrote:

 Hi,
 Can't find on hackage any sparse vector library. Does such thing exist?
 I need efficient storage and dot product calculation for very sparse
 vectors with about 10 out of 40 000 non-zero components.
 One solution would be to represent Sparse Vector as Data.Map with
 (component_index, component_value) pairs to store non-zero components of the
 vector.


 I would make a different suggestion:

 Store a Set (or maybe an IntMap) of (IntMap scalar)s.

 In other words, let each vector be represented by an IntMap whose key
 represents the n'th component of the vector, and whose value is the proper
 scalar.


 In this case, for example, calculating cosine similarity (
 http://en.wikipedia.org/wiki/Cosine_similarity) for for every pair of 10
 000 vectors, would not be very nice and efficient, I am afraid.


 Given two (IntMap Double)s a and b, I would compute the projection of a
 along b as

 cosineSimilarity :: IntMap Double - IntMap Double - Double
 cosineSimilarity a b  = (dot a b) / ((norm a) * (norm b)) where
  dot  = sum . elems . intersectionWith (*)
  norm = (**0.5) . sum . fmap (**2) . elems


 The only part I find tricky is enumerating all 1^2 pairs

 pairs :: Int - [Int]
 pairs dim = do
x - [1..dim]
y - [1..dim]
return (x,y)

 and computing the projection for each pair:

 projections :: Floating scalar = IntMap (IntMap scalar) - Map (Int, Int)
 scalar
 projections space = let dimensions = undefined -- find max key in elements
 of space?
 m_projection space x y = cosineSimilarity $
 lookup x space
   *
 lookup y space
  in fromList . filter (isMaybe . snd)
  . fmap (\(x,y) - ((x,y), m_projection
 space x y)
  . pairs
  $ dimensions



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe