Re: [Haskell-cafe] Call for GUI examples - Functional Reactive Programming
Henning Thielemann wrote: Heinrich Apfelmus wrote: Could you expand a little on your arrow-like stream processors? What do the arrows look like, data SF a b = SF (a - (b, SF a b)) ? My stream processors are not Arrows, because 'first' cannot be implemented. However, 'arr' and '.' can be implemented. [..] For example, an arpeggiator stream processor consists of two functions: 1. Receive key up/down events and keep track of the currently pressed keys. 2. Receive a MIDI controller that controls the tempo of the arpeggiator. The stream processor sets the alarm according the current tempo and at every alarm event it sends a single key chosen from the set of the currently pressed keys. This example shows, that a stream processor cannot support Arrow.first, that is extending (arrow a b) to (arrow (a,c) (b,c)), since for an alarm event, we have no input of type c that could be passed through. Ok, that sounds nasty. And of course, I am particularly interested in the nasty examples that you came up with. :) For example I want to write a Guitar simulator: You press a set of keys together and the processor converts this into successive tones on a guitar. Technically I like to do it this way: When a key is pressed, collect all key press events in the following 10ms. After this period emit all pressed keys according to a certain pattern. When one of the pressed keys is released, then send key-press(!) events for all currently pressed keys according to another pattern. Repeat this cycle. Manage somehow the keys that are pressed after the first key-down-collecting phase and the keys that are released during this initial phase. Ignore them or do something more sensible about them, but make sure that in the output all key-down events are eventually matched with a key-up event and that for the same key you never send two successive key-down events or two successive key-up events. That is, for the same key, key-up and key-down events must alternate. An exception might be if you receive bogus input. But even then, the number of key-up and key-down events for one note in the output shall match, whenever this is true for the input. The guitar simulator is a great example! And much to my surprise, it's already possible to implement (parts of) it in reactive-banana 0.4.1! At least in the real-time version, where we have access to timers from wxHaskell. In particular, have a look at the new Wave.hs example, to be found at the bottom of http://haskell.org/haskellwiki/Reactive-banana/Examples It generates a wave-like pattern whenever you click on of the buttons (strum a chord). When you click two buttons in rapid succession (think left = key-down, right = key-up), the second wave will not start after the first one has completed. (I think this example also makes it clear that it's already to possible to implement the arpeggiator as you described with timers.) Of course, the code is not particularly high-level; after all, I am essentially duplicating event streams as [(Duration,a)]. Then again, we cannot describe each wave as Event a because we need a notion of this event stream has finished in order to be able to stall the second wave. In other words, the vanilla Event a is potentially infinite, there is no way to test whether it has finished, so *some* other notion is needed anyway. Question: how would you actually like to describe the guitar simulator at a high-level? Did you already wish for some specific combinators? Assume that you had something like reactive-banana available and imagine that there were a benevolent djinn granting you three new primitive combinators of your choice. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] [ANN] PAM library, Iptables web-interface
Hello! I'd like to announce my project called Iptadmin. It's a web interface for linux Iptables firewall [1]. It supports just few Iptables options by now. The main feature of Iptadmin is user friendly help messages. Iptadmin works in a daemon mode. It doesn't keep any auxiliary information in a system, firewall configuration is taken from the «iptables-save» script. All changes is made by Iptables calling. Firewall rules are saved by «/etc/init.d/iptables save» script. Several linux distributions such as Debian require additional Iptables configuration. Iptadmin uses PAM [2] authentication. Access is granted for root and for any other user with membership in «iptadmin» system group. Iptadmin is written using Happstack, so it doesn't support https yet. To prevent sending system password by network in plain text, the web interface is listening only on loopback network interface. In order to access Iptadmin remotely user should setup https proxying using external web server. There is also dedicated library for parsing and printing Iptables rules [3]. While working on Iptadmin I've implemented library with subset of PAM api bindings[4]. A code of my project is licensed under BSD3. Sources are uploaded to hackage [3,4,5]. More information can be found on a project homepage[6]. [1] http://www.netfilter.org/ [2] http://www.kernel.org/pub/linux/libs/pam/ [3] http://hackage.haskell.org/package/iptables-helpers-0.3 [4] http://hackage.haskell.org/package/pam-0.1 [5] http://hackage.haskell.org/package/iptadmin-1.0.0 [6] http://iptadmin.confmgr.org -- Best regards, Evgeny Tarasov ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
Perhaps this is interesting? On the relationship between exploratory (a.k.a. sloppy or theoretical) and rigorous math. http://arxiv.org/pdf/math/9307227v1 -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HaskellDB DB Layout Description
On 18:12 Sat 09 Jul , Tom Murphy wrote: Hi, I've found good explanations of the HaskellDB combinators, but I can't find good information about how to correctly define the database layout. Can anyone point me to a resource, or give a quick example? Thanks! Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe I don't have any examples at hand, but I'll look through the api with you. There are three ways to create the dblayout interface, manually, through dbinfo or through template haskell. The vanilla way is to use the DBInfo(3) module to describe your database layout. It can also be used to create the database schema, but as the dbinfo language is very restricted, I don't recommend it. DBInfo { dbName DatabaseName opts = DBOptions { useBString = False , makeIdent = mkIdentPreserving } tbls = [TInfo {tname = tablename cols = [CInfo {cname = columnname, descr = (IntT, False)}] } ] } This would create a layout describing a database called DatabaseName with one table tablename with one column columnname which is of type int and can't be null. The mkIdentPreserving is an undocumented function in (5) The description then needs to be created into module files with dbInfoToModuleFiles(4). This creates a root DatabaseName.hs file and DatabaseName directory. The root file is uncompilable and can be safely removed. The fact that there is two stages for the compilation, makes it difficult to compile. I believe this restriction is because haskelldb was created when there was no template haskell. With template haskell (2) you could do the following: $(mkDbDirectTable tablename [(columnname, [t|Int|])] I don't know how to specify whether the field can be null or not, but at least this way you get your dblayout descriptions at compile time. [1] http://hackage.haskell.org/package/haskelldb [2] http://hackage.haskell.org/package/haskelldb-th [3] http://hackage.haskell.org/packages/archive/haskelldb/2.1.1/doc/html/Database-HaskellDB-DBSpec-DBInfo.html [4] http://hackage.haskell.org/packages/archive/haskelldb/2.1.1/doc/html/Database-HaskellDB-DBSpec-DBSpecToDBDirect.html [5] http://hackage.haskell.org/packages/archive/haskelldb/2.1.1/doc/html/src/Database-HaskellDB-DBSpec-PPHelpers.html -- Mats Rauhala MasseR pgp4JOTyhvDIn.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haddock and the type inference
Hello Café, As far as I know, there is currently no way to tell haddock to run the type inferer to document functions without explicit type signature. Is that done on purpose (e.g. to force the developpers to write at least the type signatures of the public API, which is a fair reason) or is it a limitation? Is it planned to add that support to haddock? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] class and instance
Hi, I am trying to understand the following code. I have written my current (mis-)understanding and questions below. I do not wish to improve the code, it is from a research paper[1] that I am trying to understand. Pat [1] ftp://ftp.geoinfo.tuwien.ac.at/medak/phdmedak.pdf -- A specification. The class Points takes two type variables. -- The functions take variables of type p, a; return a value of type a. class Points p a where getX :: p a - a getY :: p a - a -- A parameterized representation -- One constructor takes two elements of type a and produces a Point. data Point a = Pt a a -- An implementation of the class Points on the data type (Point a) -- In Pt b c constructor the variables b and c areboth of type a. -- The type a is left undefined until evaluation instance Points Point a where getX (Pt b c) = b getY (Pt b c) = c -- This runs with any type e.g. Integers -- getX(Pt 1 2) -- :t getX(Pt 1 2) -- getX(Pt 1 2) :: forall t. (Num t) = t My main question is in understanding the relationship between the arguments of the functions getX and getY in the class and in the instance. It seems to me that the constructor Pt 1 2 produces one element of type Point which has two components. How does this square with the class definition of getX which has two arguments? Is there a difference between: getX :: p a - a and getX :: p - a - a This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] class and instance
On Sun, Jul 10, 2011 at 06:49, Patrick Browne patrick.bro...@dit.ie wrote: My main question is in understanding the relationship between the arguments of the functions getX and getY in the class and in the instance. It seems to me that the constructor Pt 1 2 produces one element of type Point which has two components. How does this square with the class definition of getX which has two arguments? One argument. But your main confusion is between the data constructor which takes two arguments, and the type constructor which takes one. Point a -- type constructor, takes a type a and produces a new type Point a Pt a a -- data constructor, takes two values of some type a and produces a new value of type Point a Type constructors are used in type signatures; data constructors are used in code. You can't use Pt a a as a type; it's a (polymorphic) value. Conversely, you can't use Point a as a value (that is, foo (Point a) is an error, because foo requires a value, not a type). -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] class and instance
On 07/10/2011 12:49 PM, Patrick Browne wrote: Hi, I am trying to understand the following code. I have written my current (mis-)understanding and questions below. I do not wish to improve the code, it is from a research paper[1] that I am trying to understand. Pat [1] ftp://ftp.geoinfo.tuwien.ac.at/medak/phdmedak.pdf -- A specification. The class Points takes two type variables. -- The functions take variables of type p, a; return a value of type a. No. The class 'Points' takes two type variables, 'p' of kind (* - *) (that is, p is a type constructor: it can be applied to a type, yielding a type), and 'a' of kind *. Then 'p a' is a type and getX, getY take /one/ argument respectively, of this type. class Points p a where getX :: p a - a getY :: p a - a -- A parameterized representation -- One constructor takes two elements of type a and produces a Point. data Point a = Pt a a -- An implementation of the class Points on the data type (Point a) Actually, it's an implementation (we say instance) of the class Points for the type constructor 'Point' and any type 'a'. -- In Pt b c constructor the variables b and c areboth of type a. -- The type a is left undefined until evaluation I would say 'arbitrary' instead of 'undefined': The code below says that for any type of your choice, which we call 'a', you get an instance Points Point a. instance Points Point a where getX (Pt b c) = b getY (Pt b c) = c -- This runs with any type e.g. Integers -- getX(Pt 1 2) -- :t getX(Pt 1 2) -- getX(Pt 1 2) :: forall t. (Num t) = t My main question is in understanding the relationship between the arguments of the functions getX and getY in the class and in the instance. It seems to me that the constructor Pt 1 2 produces one element of type Point which has two components. How does this square with the class definition of getX which has two arguments? Is there a difference between: getX :: p a - a and getX :: p - a - a Yes, the first version takes one argument of type 'p a', and the second takes two of types 'p' and 'a'. See above. This seemed to be you main issue. As a last note, if you always have instances like the one above, where the second parameter is arbitrary, your definition of the class 'Points' could be simplified to class Points p where -- forall a is added implicitly. getX :: p a - a getY :: p a - a instance Points Point where -- copy'n'paste from above -- Steffen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] class and instance
On Sun, 10 Jul 2011 11:49:44 +0100, Patrick Browne patrick.bro...@dit.ie wrote: My main question is in understanding the relationship between the arguments of the functions getX and getY in the class and in the instance. It seems to me that the constructor Pt 1 2 produces one element of type Point which has two components. How does this square with the class definition of getX which has two arguments? Is there a difference between: getX :: p a - a This applies the type constructor p, in this case Point to the type variable a. It is not a function that takes two arguments. A minor clarification: Pt 1 2 produces a value of type (Num a) = Point a, so a type where the type constructor Point is already applied to something. Just Point is not a valid type a value can have, but something that you have to apply to another type, called a type constructor. and getX :: p - a - a This is a function that takes two arguments. Cheers, Daniel pgpHx4UHpkIaI.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Call for GUI examples - Functional Reactive Programming
On Sat, Jul 9, 2011 at 7:58 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: My stream processors are not Arrows, because 'first' cannot be implemented. However, 'arr' and '.' can be implemented. ... Since I have no Arrow instance I even have to write my own combinators that are counterparts to () and friends. If you have arr, (.) and (), then you have first as well: f g = (arr fst f) (arr snd g) first' f = f arr id Am I missing something here? =) Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Call for GUI examples - Functional Reactive Programming
On Sun, 10 Jul 2011, Felipe Almeida Lessa wrote: On Sat, Jul 9, 2011 at 7:58 AM, Henning Thielemann lemm...@henning-thielemann.de wrote: My stream processors are not Arrows, because 'first' cannot be implemented. However, 'arr' and '.' can be implemented. ... Since I have no Arrow instance I even have to write my own combinators that are counterparts to () and friends. If you have arr, (.) and (), then you have first as well: f g = (arr fst f) (arr snd g) first' f = f arr id Am I missing something here? =) I have only something like (), but not precisely (). I have for instance parallel :: (Monoid b) = T a b - T a b - T a b The arrow (T a b) emits a value of type 'b' for every incoming event of type 'a', but may also emit a 'b' without any input trigger. Monoid.mappend is used to merge the events if both input arrows generate an output at the same time. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Call for GUI examples - Functional Reactive Programming
On Sun, 10 Jul 2011, Heinrich Apfelmus wrote: Question: how would you actually like to describe the guitar simulator at a high-level? Did you already wish for some specific combinators? Assume that you had something like reactive-banana available and imagine that there were a benevolent djinn granting you three new primitive combinators of your choice. If I would know of appropriate combinators, I would just implement them and not ask the djinn. :-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] JSON Querry examples
Hi, I am trying to search known-in-advance fields in JSON object with unknown structure. It looks like Data.JSON2.Query is most appropriate for this task. Yet, I can not figure out how to use filters this package provides to filter JSON arrays and objects. Are there any end-to-end examples of making queries of unknown JSON objects? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] error with nanocurses-1.5.2
On Sat, Jul 09, 2011 at 01:59:12PM -0300, José Romildo Malaquias wrote: Hello. When trying to install nanocurses-1.5.2 on my Fedora Linux system, I am getting the following error: $ cabal install nanocurses Resolving dependencies... Configuring nanocurses-1.5.2... Preprocessing library nanocurses-1.5.2... In file included from Curses.hsc:42:0: cbits/utils.h:7:20: fatal error: config.h: No such file or directory compilation terminated. compiling dist/build/UI/Nanocurses/Curses_hsc_make.c failed (exit code 1) command was: /usr/bin/gcc -c dist/build/UI/Nanocurses/Curses_hsc_make.c -o dist/build/UI/Nanocurses/Curses_hsc_make.o -fno-stack-protector -fno-stack-protector -D__GLASGOW_HASKELL__=700 -Dlinux_BUILD_OS -Dlinux_HOST_OS -Dx86_64_BUILD_ARCH -Dx86_64_HOST_ARCH -Icbits -I/usr/lib64/ghc-7.0.2/unix-2.4.2.0/include -I/usr/lib64/ghc-7.0.2/bytestring-0.9.1.10/include -I/usr/lib64/ghc-7.0.2/base-4.3.1.0/include -I/usr/lib64/ghc-7.0.2/include -I/usr/lib64/ghc-7.0.2/include/ cabal: Error: some packages failed to install: nanocurses-1.5.2 failed during the building phase. The exception was: ExitFailure 1 It would be nice to have this buf fixed. The attached patch fixes the compilation issues. Basically it changes the build type from simple to configure in the cabal file, and it renames the function getline in cbits/utils.{h,c} to mygetline. If appropriate, please release a new version with the fixes. Romildo diff -ur nanocurses-1.5.2.orig/cbits/utils.c nanocurses-1.5.2/cbits/utils.c --- nanocurses-1.5.2.orig/cbits/utils.c 2008-05-18 18:09:23.0 -0300 +++ nanocurses-1.5.2/cbits/utils.c 2011-07-10 11:23:02.082418889 -0300 @@ -38,7 +38,7 @@ } /* sometimes we write to the wrong spot after a refresh */ -int getline(char *buf, FILE *hdl) { +int mygetline(char *buf, FILE *hdl) { char *p; int c; @@ -52,7 +52,7 @@ while (c != '\n') c = getc(hdl); -return getline(buf,hdl);/* read another line */ +return mygetline(buf,hdl);/* read another line */ /* normal packet */ } else { @@ -60,7 +60,7 @@ p = fgets(buf+1, BUFLEN-1, hdl); /* read rest of line */ if (p == NULL) { -// perror(getline failed\n); +// perror(mygetline failed\n); return (-1); } buf[0] = c; /* drop the '@' */ diff -ur nanocurses-1.5.2.orig/cbits/utils.h nanocurses-1.5.2/cbits/utils.h --- nanocurses-1.5.2.orig/cbits/utils.h 2008-05-18 18:09:23.0 -0300 +++ nanocurses-1.5.2/cbits/utils.h 2011-07-10 11:22:18.180418821 -0300 @@ -12,5 +12,5 @@ /* packed string IO */ FILE *openfd(int fd); -int getline(char *buf, FILE *hdl); +int mygetline(char *buf, FILE *hdl); void forcenext(void); diff -ur nanocurses-1.5.2.orig/nanocurses.cabal nanocurses-1.5.2/nanocurses.cabal --- nanocurses-1.5.2.orig/nanocurses.cabal 2008-05-18 18:09:23.0 -0300 +++ nanocurses-1.5.2/nanocurses.cabal 2011-07-10 11:21:43.256418788 -0300 @@ -21,7 +21,7 @@ (It does not differ significantly from Hmp3's Curses binding, as the Curses.hsc in Nanocurses is essentially extracted from Hmp3.) -build-type: Simple +build-type: Configure build-depends: base3, unix, bytestring tested-with:GHC==6.8.2 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Call for GUI examples - Functional Reactive Programming
Henning Thielemann wrote: Heinrich Apfelmus wrote: Question: how would you actually like to describe the guitar simulator at a high-level? Did you already wish for some specific combinators? Assume that you had something like reactive-banana available and imagine that there were a benevolent djinn granting you three new primitive combinators of your choice. If I would know of appropriate combinators, I would just implement them and not ask the djinn. :-) Fair enough. :D How did you do it with lazy lists? The more I think about it, the more I come to the conclusion that it's impossible to implement this without duplicating the event data type. As said, the main problem is that you want a combinator append :: Pattern - Pattern - Pattern that plays the second pattern (event sequence, the guitar strum) right after the first one. This means that patterns are *finite*, but this seems to collide with the requirement that any FRP style Event must be potentially infinite. Once you do implement a small DSL for patterns, everything is fine, though, as the Wave.hs example demonstrates. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] unbuffered raw keyboard input on Windows
On Wed, Jul 06, 2011 at 02:48:47PM -0700, David Barbour wrote: You could try the SDL package to support user input. Unfortunatly it does not run on a terminal. 2011/7/6 José Romildo Malaquias j.romi...@gmail.com Hello. I want to write a Haskell console application (a game) in ghc where the user will interact using the keyboard. I need to read the keys as soon as they are typed and without echoing to the console. Although Haskell provides this capability in the standard libraries (using hSetEcho and hSetBuffering from System.IO), it does not work on Windows due to a bug (http://hackage.haskell.org/trac/ghc/ticket/2189). I have tried installing packages like vty, hscurses, and ncurses, but they did not install on Windows. Which workarounds are available for that? Romildo ___ 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] unbuffered raw keyboard input on Windows
On Wed, Jul 06, 2011 at 06:46:32PM -0300, José Romildo Malaquias wrote: Hello. I want to write a Haskell console application (a game) in ghc where the user will interact using the keyboard. I need to read the keys as soon as they are typed and without echoing to the console. Although Haskell provides this capability in the standard libraries (using hSetEcho and hSetBuffering from System.IO), it does not work on Windows due to a bug (http://hackage.haskell.org/trac/ghc/ticket/2189). I have tried installing packages like vty, hscurses, and ncurses, but they did not install on Windows. Considering that there are curses for Windows (pdcurses[1] and the latest ncurses[2]), would it be too difficult to port such libraries to Windows? [1] http://pdcurses.sourceforge.net/ [2] http://www.gnu.org/software/ncurses/ Romildo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] unbuffered raw keyboard input on Windows
2011/7/10 José Romildo Malaquias j.romi...@gmail.com On Wed, Jul 06, 2011 at 02:48:47PM -0700, David Barbour wrote: You could try the SDL package to support user input. Unfortunatly it does not run on a terminal. http://www.gamedev.net/topic/340894-how-do-i-keep-sdl-from-outputting-stdout-to-a-file/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] External system connections
Hello all, I'm trying to understand how to properly structure a connection to an external system. I'm writing an application that processes requests (it's an IRC bot - ya, I've looked at lambabot but it's a bit beyond my current understanding and I'm really trying to learn this stuff and find the best way to do that is to write it myself) and sends requests to an external system, via SOAP. The SOAP requests should be sent on separate threads. The SOAP server requires an initial request for authentication be made to obtain a token used on subsequent requests. There are three ways I can structure this. One is to do the authentication with the SOAP server when the application starts up and just use that token for all subsequent requests. This will fall over if the token times out and I'd have to restart the application. Another way is to do authenticate with the server and get a new token for each request. This is obviously really inefficient. What I'd like to do is something a bit smarter. When a request to the SOAP server is to be made, if we have a token then we try and use it. If it fails, we reauthenticate and get a new token. When establishing a new token, other threads trying to send SOAP requests should block until a new token is available. There are other conditions that should be handled - such as an exponential back-off when the SOAP server can't be reached - but I feel like reestablishing the authentication token is really the key concern here. Unfortunately, I have no idea right now how to write this in Haskell. Any pointers would be awesome. Thanks! Rich ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] External system connections
You don't need to do it, it is already done =). See the pool package by Michael Snoyman on Hackage [1]. More specifically, see createPoolCheckAlive [2]. Cheers, [1] http://hackage.haskell.org/package/pool [2] http://hackage.haskell.org/packages/archive/pool/0.1.0.2/doc/html/Data-Pool.html#v:createPoolCheckAlive -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] External system connections
On Sun, Jul 10, 2011 at 15:04, Richard Wallace rwall...@thewallacepack.net wrote: What I'd like to do is something a bit smarter. When a request to the SOAP server is to be made, if we have a token then we try and use it. If it fails, we reauthenticate and get a new token. When establishing a new token, other threads trying to send SOAP requests should block until a new token is available. There are other conditions that Typically you'd use a Chan or TChan for communication with the SOAP thread. Other threads write to the Chan and block if the reading thread is busy. There's also a non-blocking version. (TChan uses STM, which provides atomic transactions; in this case it may be overkill, especially if you're just getting started.) I wouldn't be surprised if there's already a (or several) package on Hackage for it -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
Hi, Also a library for string normalization in the sense of stripping diacritical marks would be handy too. Does anything in this respect exist that would be usable from haskell? Thanks On Fri, Jul 01, 2011 at 02:31:34PM +0400, Dmitri O.Kondratiev wrote: Hi, Please advise on NLP libraries similar to Natural Language Toolkit ( www.nltk.org) First of all I need: - tools to construct 'bag of words' ( http://en.wikipedia.org/wiki/Bag_of_words_model), which is a list of words in the article. - tools to prune common words, such as prepositions and conjunctions, as well as extremely rare words, such as the ones with typos. - stemming tools - Naive Bayes classifier - SVM classifier - k-means clustering Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] NLP libraries and tools?
On Sun, Jul 10, 2011 at 12:59 PM, ivan vadovic p...@pobox.sk wrote: Hi, Also a library for string normalization in the sense of stripping diacritical marks would be handy too. Does anything in this respect exist that would be usable from haskell? The closest thing I know of is this: http://hackage.haskell.org/package/text-icu You still have to install ICU separately, that library is just a binding for working with it from Haskell. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Call for GUI examples - Functional Reactive Programming
Oh! I have a good, small (single-purpose; reusable), useful one! A text field which tab-completes words or phrases from a dictionary. Haskeline provides useful (non-FRP) for implementing this, but it seems like FRP could handle this in an interesting way. Tom On 7/10/11, Heinrich Apfelmus apfel...@quantentunnel.de wrote: Henning Thielemann wrote: Heinrich Apfelmus wrote: Question: how would you actually like to describe the guitar simulator at a high-level? Did you already wish for some specific combinators? Assume that you had something like reactive-banana available and imagine that there were a benevolent djinn granting you three new primitive combinators of your choice. If I would know of appropriate combinators, I would just implement them and not ask the djinn. :-) Fair enough. :D How did you do it with lazy lists? The more I think about it, the more I come to the conclusion that it's impossible to implement this without duplicating the event data type. As said, the main problem is that you want a combinator append :: Pattern - Pattern - Pattern that plays the second pattern (event sequence, the guitar strum) right after the first one. This means that patterns are *finite*, but this seems to collide with the requirement that any FRP style Event must be potentially infinite. Once you do implement a small DSL for patterns, everything is fine, though, as the Wave.hs example demonstrates. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ 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] External system connections
On Sun, Jul 10, 2011 at 2:54 PM, Brandon Allbery allber...@gmail.com wrote: On Sun, Jul 10, 2011 at 17:34, Richard Wallace rwall...@thewallacepack.net wrote: Rather than a single separate thread that makes requests I was hoping to make several soap requests concurrently, rather than have them be made serially. I would only want to block other threads making soap request if one of them returns a response indicating the token they were using is no longer valid. Is there one shared token, or one per requesting thread, or some other arrangement? There should be one shared token. In either case, separation of concerns makes me think the token handling belongs on the other end: a thread writes a request down a Chan, a queue dispatcher thread reads it if there are available workers and the token is available (with callers blocking otherwise), dispatcher sends request to available worker. If the worker finds the token is invalid, it calls back in to the dispatcher with a token renewal request, which causes anything else that needs that token to block as above, and itself blocks until a valid token is returned. Ahhh... I see. That sounds like a much better plan. It also keeps the fact that the token is mutable confined to a single thread, the dispatcher thread. One thing I'd have to be careful to handle is iIf multiple worker threads find that the token is now invalid. In that case they would all send the token renewal request to the dispatcher and they would each try and do the re-auth. To avoid that, part of the token renewal request could be the used token. When the dispatcher does the token renewal, it checks if the used token is the same as the current token. If so, it does the token renewal. If not, it dispatches to the SOAP worker thread with the new token. Another advantage of this is that adding more workers is done in an obvious place (the queuer thread). That said, I still don't know enough details to say if that token management implementation actually makes sense. I'd still go with the worker/queuer thread setup, which is I think what you were pointed to (the pool hackage). Ok, I still don't see how the Pool package helps. I had assumed the pooled resource would be the token, so the size of the pool would be 1. Now that I rethink it, it seems like you are suggesting the resource is the worker threads. Is that right? When I read what you were talking about above with the dispatcher thread I had thought it would use forkIO to start the worker threads. The worker threads would read from a Chan that the dispatcher wrote to.In that way, the dispatcher doesn't have to worry about worker threads being available. Am I misunderstanding something? Thanks, Rich -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] External system connections
On Sun, Jul 10, 2011 at 19:16, Richard Wallace rwall...@thewallacepack.net wrote: On Sun, Jul 10, 2011 at 2:54 PM, Brandon Allbery allber...@gmail.com wrote: One thing I'd have to be careful to handle is iIf multiple worker threads find that the token is now invalid. In that case they would all send the token renewal request to the dispatcher and they would each try and do the re-auth. To avoid that, part of the token renewal One of the reasons to send the request back to the dispatcher instead of doing it inline is so that the dispatcher can note that a renewal request is already in flight (which it needs to know anyway, so it can block other requests) and wake all threads waiting on it when it's done, instead of having multiple renewals in flight. 1. Now that I rethink it, it seems like you are suggesting the resource is the worker threads. Is that right? When I read what you were talking about above with the dispatcher thread I had thought it would use forkIO to start the worker threads. The worker threads would read from a Chan that the dispatcher wrote to. In that way, the dispatcher doesn't have to worry about worker threads being available. Am I misunderstanding something? The point of a pool is so (a) you can throttle it in special cases, such as when you need to renew the token, and (b) so you don't find yourself juggling a couple thousand threads if things get unexpectedly busy (or buggy). You can limit the pool to something sensible (probably something like 4 during development and debugging so things can't get too out of hand) and increased later; plus, the pool manager will provide the primitives to deal with managing shared resources (such as your token) within the pool. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] External system connections
On Sun, Jul 10, 2011 at 4:38 PM, Brandon Allbery allber...@gmail.com wrote: One of the reasons to send the request back to the dispatcher instead of doing it inline is so that the dispatcher can note that a renewal request is already in flight (which it needs to know anyway, so it can block other requests) and wake all threads waiting on it when it's done, instead of having multiple renewals in flight. Ok, I can see that. Though I was thinking that the worker threads would send the request back to the dispatcher by way of the same Chan the dispatcher reads requests from. Obviously I was thinking the dispatcher would use the original token to filter requests in the Chan. If I understand what you are talking about, the dispatcher would do the token renewal in a separate thread, continuing to process it's incoming Chan while that is going on, accumulating incoming requests somewhere, perhaps in another Chan. Then, when the token renewal is complete, the dispatcher stops forwarding incoming requests to the secondary Chan, processes the accumulated requests using the new token, and, when done with those, the switches back to processing the incoming Chan. Is that something like what you had in mind, or did I make it more complicated than necessary? The point of a pool is so (a) you can throttle it in special cases, such as when you need to renew the token, and (b) so you don't find yourself juggling a couple thousand threads if things get unexpectedly busy (or buggy). You can limit the pool to something sensible (probably something like 4 during development and debugging so things can't get too out of hand) and increased later; plus, the pool manager will provide the primitives to deal with managing shared resources (such as your token) within the pool. Hmm. I'm still not entirely seeing it and I think the problem is just my lack of knowledge of Haskell concurrency. If the pool is of threads, how do you start the threads? How do you submit work to the threads? The only way I know of in Haskell of creating threads to do work is forkIO. That takes a function and runs to completion. Would a worker thread just be one that loops forever and checks a MVar for something to do? So the pool would really consist of (MVar, ThreadId) pairs. When we speak of getting a thread out of a pool and giving it work to do, are we really talking about sticking a value in an MVar that the thread is blocking on, waiting for data to be available to do something with, so that it can go and do some work? And when we are done with the thread we return it to the pool? Rich P.S. Thanks for talking me through this! I'm learning a ton about concurrency in Haskell. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] External system connections
On Sun, Jul 10, 2011 at 20:19, Richard Wallace rwall...@thewallacepack.net wrote: On Sun, Jul 10, 2011 at 4:38 PM, Brandon Allbery allber...@gmail.com wrote: Ok, I can see that. Though I was thinking that the worker threads would send the request back to the dispatcher by way of the same Chan the dispatcher reads requests from. Obviously I was thinking the dispatcher would use the original token to filter requests in the Chan. If I understand what you are talking about, the dispatcher would do the token renewal in a separate thread, continuing to process The same Chan is used to send a request; the thread processing token renewal might or might not be otherwise a normal worker thread, but it's separated out as a Maybe ThreadId instead of being in a pool, because (a) there can only be zero or one of them, and (b) if it's not Nothing then the dispatcher thread accepts only token renewals. (This actually requires either multiple Chans or something more complex than a normal Chan, since you can't filter a Chan based on the type of message.) You also need some way to block the sender, which suggests that a message written down a Chan must include an MVar which will be signaled when the operation is complete. This suggests to me something along the lines of data WorkRequest = SOAPData ... (MVar Bool) | TokenRequest Token (MVar Token) -- | ReadyForWork (MVar WorkRequest) where the requestor allocates an MVar, writes it as part of the WorkRequest, and then does a takeMVar to wait for the response. The dispatcher reads WorkRequests, dispatches any it can to available workers, and queues the rest internally; if it's a TokenRequest then it's queued separately and all SOAPData requests get queued regardless of whether there are free workers. When the single token processor returns, all entries in the TokenRequest queue get awakened (putMVar threadMVar newToken) and normal processing of the standard request queue resumes. Or you can see if the pool hackage handles the ugly details here automatically; I haven't looked. If the pool is of threads, how do you start the threads? How do you submit work to the threads? The only way I know of in Haskell of creating threads to do work is forkIO. That takes a function and runs to completion. Would a worker thread just be one that loops forever Yes; the dispatcher keeps a list of workers, which are forkIO-d threads that are waiting on an MVar or Chan for work to do. When they receive something, they go off and do it, write the result into another MVar or Chan which was specified in the request, and go back to waiting on the initial MVar/Chan for something to do. If the list is shorter than the maximum, more workers are forkIO-d to fill it as needed; if longer, idle workers are sent shut down requests. (The latter is polite handling of program shutdown, and also allows for the pool size to be modified dynamically if needed.) I think doing this right also requires that a worker that's ready for more work explicitly check in, so the dispatcher knows it's available; that could be handled by an additional WorkRequest type (see commented-out line above, where a worker that's ready to handle another request passes its input MVar to the dispatcher)... but there may be better ways; I have some grasp of concurrency, but my Haskell library fu is still somewhat weak. Hopefully someone else will jump in if appropriate. (You can see how quickly this becomes complex, though; if the canned solution does what you need, you might want to avoid reinventing this particular wheel unless you're doing it for educational purposes.) -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] External system connections
Alright, I'll have to think on this some more but I think we're speaking the same language now - and what's more I even understand it! Thanks again for all your help, Rich On Sun, Jul 10, 2011 at 6:46 PM, Brandon Allbery allber...@gmail.com wrote: On Sun, Jul 10, 2011 at 20:19, Richard Wallace rwall...@thewallacepack.net wrote: On Sun, Jul 10, 2011 at 4:38 PM, Brandon Allbery allber...@gmail.com wrote: Ok, I can see that. Though I was thinking that the worker threads would send the request back to the dispatcher by way of the same Chan the dispatcher reads requests from. Obviously I was thinking the dispatcher would use the original token to filter requests in the Chan. If I understand what you are talking about, the dispatcher would do the token renewal in a separate thread, continuing to process The same Chan is used to send a request; the thread processing token renewal might or might not be otherwise a normal worker thread, but it's separated out as a Maybe ThreadId instead of being in a pool, because (a) there can only be zero or one of them, and (b) if it's not Nothing then the dispatcher thread accepts only token renewals. (This actually requires either multiple Chans or something more complex than a normal Chan, since you can't filter a Chan based on the type of message.) You also need some way to block the sender, which suggests that a message written down a Chan must include an MVar which will be signaled when the operation is complete. This suggests to me something along the lines of data WorkRequest = SOAPData ... (MVar Bool) | TokenRequest Token (MVar Token) -- | ReadyForWork (MVar WorkRequest) where the requestor allocates an MVar, writes it as part of the WorkRequest, and then does a takeMVar to wait for the response. The dispatcher reads WorkRequests, dispatches any it can to available workers, and queues the rest internally; if it's a TokenRequest then it's queued separately and all SOAPData requests get queued regardless of whether there are free workers. When the single token processor returns, all entries in the TokenRequest queue get awakened (putMVar threadMVar newToken) and normal processing of the standard request queue resumes. Or you can see if the pool hackage handles the ugly details here automatically; I haven't looked. If the pool is of threads, how do you start the threads? How do you submit work to the threads? The only way I know of in Haskell of creating threads to do work is forkIO. That takes a function and runs to completion. Would a worker thread just be one that loops forever Yes; the dispatcher keeps a list of workers, which are forkIO-d threads that are waiting on an MVar or Chan for work to do. When they receive something, they go off and do it, write the result into another MVar or Chan which was specified in the request, and go back to waiting on the initial MVar/Chan for something to do. If the list is shorter than the maximum, more workers are forkIO-d to fill it as needed; if longer, idle workers are sent shut down requests. (The latter is polite handling of program shutdown, and also allows for the pool size to be modified dynamically if needed.) I think doing this right also requires that a worker that's ready for more work explicitly check in, so the dispatcher knows it's available; that could be handled by an additional WorkRequest type (see commented-out line above, where a worker that's ready to handle another request passes its input MVar to the dispatcher)... but there may be better ways; I have some grasp of concurrency, but my Haskell library fu is still somewhat weak. Hopefully someone else will jump in if appropriate. (You can see how quickly this becomes complex, though; if the canned solution does what you need, you might want to avoid reinventing this particular wheel unless you're doing it for educational purposes.) -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Good XML-Enumerator Examples
Hi Cafe. I'm writing a library which will be parsing XML data from a web API. I'm fairly well versed at this point in parsing JSON (aeson being my library of choice). For XML, I like the API of xml-enumerator over hxt because it appears to be nice and simple .The problem is that the example in the documentation isn't really sufficient for me to get a grasp of how to traverse XML and parse elements with multiple child nodes into a record. My first question: Am I barking up the wrong tree using xml-enumerator for anything beyond fairly flat, basic XML? If not, can anyone direct me to some good code samples using xml-enumerator to parse more complicated data? If I am indeed barking up the wrong tree, what would you all suggest? Thanks, -- Michael Xavier http://www.michaelxavier.net LinkedIn http://www.linkedin.com/pub/michael-xavier/13/b02/a26 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Good XML-Enumerator Examples
On Mon, Jul 11, 2011 at 8:42 AM, Michael Xavier nemesisdes...@gmail.com wrote: Hi Cafe. I'm writing a library which will be parsing XML data from a web API. I'm fairly well versed at this point in parsing JSON (aeson being my library of choice). For XML, I like the API of xml-enumerator over hxt because it appears to be nice and simple .The problem is that the example in the documentation isn't really sufficient for me to get a grasp of how to traverse XML and parse elements with multiple child nodes into a record. My first question: Am I barking up the wrong tree using xml-enumerator for anything beyond fairly flat, basic XML? If not, can anyone direct me to some good code samples using xml-enumerator to parse more complicated data? If I am indeed barking up the wrong tree, what would you all suggest? Thanks, I think you're not barking up the wrong tree. I use xml-enumerator extensively for some internal XML parsing, and some of it is very complicated. Unfortunately, I can't share that code ;). However, there are a few examples out there of some significant XML parsing: https://github.com/snoyberg/yesodwiki/blob/master/Handler/UploadDitamap.hs https://github.com/aristidb/aws (Aristid would have more info here) I would recommend using either the Cursor or Resolved modules for development, unless you really need more control over unresolved entities. As a side point, I was just thinking this morning that I should really write a tutorial on xml-enumerator. If you have some specific questions, please pass them on, maybe I'll put together a cookbook. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe