Re: [Haskell-cafe] Why is Haskell flagging this?
Hi Michael The type of lst is IO [Int] and therefore fmap (+1) applies (+1) to the hole lists of integers, and not to each member of the list. That is: fmap (+1) lst = fmap (+1) (return [1,2,3,4,5]) = return ([1,2,3,4,5] + 1) and you cannot say [1,2,3,4,5] + 1. Does that make sense? Maybe you want to say: main = do let lst = [1,2,3,4,5] print $ map (+1) lst /Mads On Fri, 2010-12-17 at 09:04 -0800, michael rice wrote: I don't understand this error message. Haskell appears not to understand that 1 is a Num. Prelude :t 1 1 :: (Num t) = t Prelude :t [1,2,3,4,5] [1,2,3,4,5] :: (Num t) = [t] Prelude Michael === f :: [Int] - IO [Int] f lst = do return lst main = do let lst = f [1,2,3,4,5] fmap (+1) lst === Prelude :l test [1 of 1] Compiling Main ( test.hs, interpreted ) test.hs:5:17: No instance for (Num [Int]) arising from the literal `1' at test.hs:5:17 Possible fix: add an instance declaration for (Num [Int]) In the second argument of `(+)', namely `1' In the first argument of `fmap', namely `(+ 1)' In the expression: fmap (+ 1) lst Failed, modules loaded: none. Prelude ___ 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] TLS package server interface do not seem to allow for asyncrhonious communication
Hi Antoine, Rereading my earlier post, I can see I did not explain myself properly. What I do now with sockets is: 1. Bind a socket to a port 2. Call Network.accept, then take the resultant Handle, and call forkIO _twice_ with the handle. Making one thread that listens for incoming messages and one thread that sends outgoing messages. And then I go back to one. That is, two threads for each handle. I follow the scheme above, as my server do not follow a request/response pattern, but is asynchronous and must never get blocked by a client that do not send messages. Why do I not think, I cannot do the same thing with the TLS package? Because of this API description: recvData :: Handle - TLSServer IO ByteStringSource recvData get data out of Data packet, and automatically renegociate if - a Handshake ClientHello is received Thus, recvData will not only read messages from the handle, it may also do a handshake. I presume that a handshake will both send and receive data. Thus, I would have thread that just sends data, and another thread that both sends and receives data. I am afraid that the two threads may step on each others toes. With ordinary sockets, I have one thread that only sends data, and another thread that only receives data. So with ordinary sockets there is no chance of stepping on each others toes. Also the TLSServer monad contains state. If I start two threads using the same SSL connection, I presume that the TLSServer-state will be different for the two threads. And I presume that two threads using the same SSL connection, needs the same state in the TLSServer monad. One workaround is use two SSL connections for each client, but I would like to avoid that. Regards and hope I make myself clearer, Mads On Tue, 2010-12-14 at 17:20 -0600, Antoine Latter wrote: Maybe I'm missing something - but shouldn't the code listening on the Handle already be in it's own thread? The general recipe is: 1. Bind a socket to port 2. Call Network.accept, then take the resultant Handle, call forkIO with the TLS actions and the resultant handle. Go back to 1. So even though the TLS code blocks on the handle, that's in a different thread from the code which is waiting on the socket to accept additional connections. Take care, Antoine On Tue, Dec 14, 2010 at 2:21 PM, Mads Lindstrøm mads.lindstr...@gmail.com wrote: Hi Haskeleers, I got a working SSL server using the TLS package. Great. However, I really intended to use SSL for an asynchronous server. That is, the server must constantly listen for a client message, which may result in zero or more messages send _to_ the client. And the server will, without being waken up by a client message, send messages to the client. And this interface http://hackage.haskell.org/packages/archive/tls/0.3.1/doc/html/Network-TLS-Server.html do not seem to allow for an asynchronous server. That is, whenever I call: recvPacket :: Handle - TLSServer IO (Either TLSError [Packet]) or recvData :: Handle - TLSServer IO ByteString The server is stuck until the client sends a message. Or am I missing something? Contrast this to Network package socket implementation. Here I can spawn two threads and simultaneously listen for client messages and send messages to the client. It seems to me that a general SSL implementation should not preclude asynchronous servers. I know, the TLS package is not more than a few months old and one can already use it for SSL servers and clients, which is quite impressive. So do not read this as a negative comment, more as suggestions for a better interface. Regards, Mads Lindstrøm ___ 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] TLS package server interface do not seem to allow for asyncrhonious communication
Hi Antoine On Thu, Dec 16, 2010 at 2:38 PM, Mads Lindstrøm Maybe a better interface would be along the lines of: -- | Do not use the handle when you are done! openTLSConnection: Handle - { information? Maybe not needed} - IO TLSConnection And then some thread-safe operations on the TLSConnection: recv :: TLSConnection - Int - IO ByteString send :: TLSConnection - ByteString - IO () Or it could be: openTLSConnection: Handle - { Certificates private key} - IO Handle the returned handle would then act like a normal handle, except that it would encrypt and decrypt data. But I do not know if it is possible to implement that. /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Taking the TLS package for a spin ... and failing
Hi Vincent, I got it to work :) But there seems to be some bugs in the Haskell server certificate handling. It seems that TLS do not transfer the ST (state, as in California) parameter in the X509 subject field. It also seems that the Haskell server do not send the email-address. The reason for my suspicion is that when I connect my Java client to the Haskell server, the client sees this certificate: *** Certificate chain chain [0] = [ [ Version: V3 Subject: OU=Head office, O=Mads Inc., C=DK, CN=192.168.1.6 Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5 Key: Sun RSA public key, 2048 bits modulus: 747914719126678758768988 (the modulus is longer, but I cut it down). public exponent: 65537 Validity: [From: Tue Dec 14 11:07:05 CET 2010, To: Fri Dec 13 11:07:05 CET 2013] Issuer: OU=Head office, O=Mads Inc., C=DK, CN=192.168.1.6 SerialNumber: [e11f077d a534af39] ] Whereas, if I connect the Java client to the Java server I get this certificate: chain [0] = [ [ Version: V3 Subject: emailaddress=mads.lindstr...@gmail.com, CN=192.168.1.6, OU=Head office, O=Mads Inc., L=Copenhagen, ST=Denmark, C=DK Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5 Key: Sun RSA public key, 2048 bits modulus: 747914719126678758768988 (the modulus is longer, but I cut it down) public exponent: 65537 Validity: [From: Tue Dec 14 11:07:05 CET 2010, To: Fri Dec 13 11:07:05 CET 2013] Issuer: emailaddress=mads.lindstr...@gmail.com, CN=192.168.1.6, OU=Head office, O=Mads Inc., L=Copenhagen, ST=Denmark, C=DK SerialNumber: [e11f077d a534af39] Certificate Extensions: 3 [1]: ObjectId: 2.5.29.14 Criticality=false SubjectKeyIdentifier [ KeyIdentifier [ : B3 F9 87 37 7D 80 53 2C F4 B1 B2 05 43 24 21 51 ...7..S,C$!Q 0010: FD 37 4C C8.7L. ] ] And without ST and/or email-address the Java client will not recognize the certificate. To avoid these problems I created a new certificate, using: openssl req -new -x509 -key privkey.pem -subj /OU=Head office, O=Mads Inc., C=DK, CN=192.168.1.6 -out cacert.pem -days 1095 That is, without email and without ST parameter. I then recreated the Java keystore. And now it works. Woohooo! I have attached the modified Java client, if anybody is interested in how to force SSL3 from Java. /Mads On Mon, 2010-12-13 at 08:51 +, Vincent Hanquez wrote: On Sun, Dec 12, 2010 at 08:13:59PM +0100, Mads Lindstrøm wrote: Hi Haskellers, I am trying to connect a Java client to a Haskell server using the Haskell tls package, and things are not working out for me. There is a lot of steps involved and I do not know what I am doing wrong, so this is a long message. But first I create a private/public key-pair: On Mon, Dec 13, 2010 at 01:22:17AM +0100, Mads Lindstrøm wrote: Hi again, I found a simpler way to test the server connection, but it is still not working. Namely, openssl s_client -connect 192.168.1.6:8000 Hi Mads, This one has to do with the fact that openssl try to send a SSLv2 hello message, which is not yet supported by TLS (and not in the supported Version list in the params if it was). unfortunately lots of clients still do that for compatibility; even though that doesn't buy much since nobody should connect to a pure SSLv2 server. For the openssl cmdline, you can add a simple -ssl3 flag or -tls1 flag to start negociating at the right version straight away. [snip] main, WRITE: SSLv2 client hello message, length = 101 [snip] This lines appears suspicious; I think that's exactly the same problem. I suppose there's a way to instanciate your java SSL connection to SSL3 or TLS1 It would be nice to add support to the SSLv2 hello message directly though, but I don't have any timeline for that to happens. import javax.net.*; import java.net.*; import javax.net.ssl.*; import java.io.*; class Client { public static void main(String[] args) { try { int port = 8000; String hostname = 192.168.1.6; // Insert your localhost ip SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); //SSLContext ctx = SSLContext.getInstance(SSL); //ctx.init(null, null, null); //SocketFactory socketFactory = ctx.getSocketFactory(); SSLSocket socket = (SSLSocket) socketFactory.createSocket(hostname, port); socket.setEnabledProtocols(new String[] {SSLv3, TLSv1}); System.out.println(Need client auth: + socket.getNeedClientAuth()); System.out.println(Want client auth: + socket.getWantClientAuth()); socket.startHandshake(); // Create streams to securely send and receive data to the server InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); PrintWriter writer = new PrintWriter(out); writer.println(Hello world); // Read from in and write
[Haskell-cafe] TLS package server interface do not seem to allow for asyncrhonious communication
Hi Haskeleers, I got a working SSL server using the TLS package. Great. However, I really intended to use SSL for an asynchronous server. That is, the server must constantly listen for a client message, which may result in zero or more messages send _to_ the client. And the server will, without being waken up by a client message, send messages to the client. And this interface http://hackage.haskell.org/packages/archive/tls/0.3.1/doc/html/Network-TLS-Server.html do not seem to allow for an asynchronous server. That is, whenever I call: recvPacket :: Handle - TLSServer IO (Either TLSError [Packet]) or recvData :: Handle - TLSServer IO ByteString The server is stuck until the client sends a message. Or am I missing something? Contrast this to Network package socket implementation. Here I can spawn two threads and simultaneously listen for client messages and send messages to the client. It seems to me that a general SSL implementation should not preclude asynchronous servers. I know, the TLS package is not more than a few months old and one can already use it for SSL servers and clients, which is quite impressive. So do not read this as a negative comment, more as suggestions for a better interface. Regards, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Taking the TLS package for a spin ... and failing
Hi Vincent, On Mon, 2010-12-13 at 08:51 +, Vincent Hanquez wrote: that doesn't buy much since nobody should connect to a pure SSLv2 server. For the openssl cmdline, you can add a simple -ssl3 flag or -tls1 flag to start negociating at the right version straight away. Yes, that worked :) [snip] main, WRITE: SSLv2 client hello message, length = 101 [snip] This lines appears suspicious; I think that's exactly the same problem. I suppose there's a way to instanciate your java SSL connection to SSL3 or TLS1 I have tried a little, and it is not easy at least. But I will try some more. Thank you for answering, Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Taking the TLS package for a spin ... and failing
Hi Haskellers, I am trying to connect a Java client to a Haskell server using the Haskell tls package, and things are not working out for me. There is a lot of steps involved and I do not know what I am doing wrong, so this is a long message. But first I create a private/public key-pair: openssl genrsa -out privkey.pem 2048 then I make a self-signed certificate: openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095 Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:192.168.1.6 Email Address []: then I convert the certificate to DER format and stuff it into a Java keystore: openssl x509 -in cacert.pem -out cert.der -outform DER keytool -keystore myKeystore.store -importcert -storepass foobar -keypass foobar -file cert.der now I start the Haskell server: ghc -hide-package monads-tf Server.hs -e main and then the Java client: javac Client.java java -Djavax.net.debug=all -Djavax.net.ssl.trustStore=myKeystore.store -Djavax.net.ssl.trustStorePassword=foobar Client JavaClientOutput.txt 21 The server output is: interactive: user error (unexpected type received. expecting handshake ++ Left (Error_Packet invalid type)) and not Hello world as expected. The client output is very long, but the most interesting part is properly: main, received EOFException: error main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake main, SEND TLSv1 ALERT: fatal, description = handshake_failure I have attached the Haskell server, the Java client and the full java output. Hope somebody can help figure out what I do wrong. I am using the Haskell tsl package version 0.3.1. And I run Debian Linux. I also tried connecting a Java client to a Java server. First create server keystore: openssl pkcs8 -topk8 -nocrypt -in privkey.pem -inform PEM -out privkey.der -outform DER java -Dkeystore=myServerKeystore.store ImportKey privkey.der cert.der ImportKey.java can be found here http://www.agentbob.info/agentbob/79-AB.html . then start Java server: javac JavaServer.java java -Djavax.net.ssl.keyStore=myServerKeystore.store -Djavax.net.ssl.keyStorePassword=importkey JavaServer and run the client again: java -Djavax.net.debug=all -Djavax.net.ssl.trustStore=myKeystore.store -Djavax.net.ssl.trustStorePassword=foobar Client and the server outputs: Hello world as expected. Thus I think the certificates are fine, and the Java client is fine. But what am I doing wrong in the Haskell server? I have attached JavaServer.java. Regards, Mads Lindstrøm import javax.net.*; import java.net.*; import javax.net.ssl.*; import java.io.*; class Client { public static void main(String[] args) { try { int port = 8000; String hostname = 192.168.1.6; // Insert your localhost ip SocketFactory socketFactory = SSLSocketFactory.getDefault(); Socket socket = socketFactory.createSocket(hostname, port); // Create streams to securely send and receive data to the server InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); PrintWriter writer = new PrintWriter(out); writer.println(Hello world); // Read from in and write to out... // Close the socket writer.close(); in.close(); out.close(); } catch(IOException e) { e.printStackTrace(); System.out.println(e.getMessage()); } } } import javax.net.*; import java.net.*; import javax.net.ssl.*; import java.io.*; class JavaServer { public static void main(String[] args) { try { int port = 8000; String hostname = 192.168.1.6; // Insert your localhost ip ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault(); ServerSocket ssocket = ssocketFactory.createServerSocket(port); // Listen for connections Socket socket = ssocket.accept(); // Create streams to securely send and receive data to the client InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); System.out.println(reader.readLine()); // Read from in and write to out... // Close the socket reader.close(); in.close(); out.close(); } catch(IOException e) { e.printStackTrace(); System.out.println(e.getMessage()); } } } -- ghci -hide-package monads-tf Server.hs module Main where import qualified Control.Monad.Trans as Trans import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as L import qualified Data.Certificate.PEM as PEM import qualified Data.Certificate.Key as Key import qualified Data.Certificate.X509 as X509 import qualified Network.TLS.Server
Re: [Haskell-cafe] Taking the TLS package for a spin ... and failing
Hi again, I found a simpler way to test the server connection, but it is still not working. Namely, penssl s_client -connect 192.168.1.6:8000 CONNECTED(0003) 18683:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:188: Regards, Mads Lindstrøm On Sun, 2010-12-12 at 20:14 +0100, Mads Lindstrøm wrote: Hi Haskellers, I am trying to connect a Java client to a Haskell server using the Haskell tls package, and things are not working out for me. There is a lot of steps involved and I do not know what I am doing wrong, so this is a long message. But first I create a private/public key-pair: openssl genrsa -out privkey.pem 2048 then I make a self-signed certificate: openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095 Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:192.168.1.6 Email Address []: then I convert the certificate to DER format and stuff it into a Java keystore: openssl x509 -in cacert.pem -out cert.der -outform DER keytool -keystore myKeystore.store -importcert -storepass foobar -keypass foobar -file cert.der now I start the Haskell server: ghc -hide-package monads-tf Server.hs -e main and then the Java client: javac Client.java java -Djavax.net.debug=all -Djavax.net.ssl.trustStore=myKeystore.store -Djavax.net.ssl.trustStorePassword=foobar Client JavaClientOutput.txt 21 The server output is: interactive: user error (unexpected type received. expecting handshake ++ Left (Error_Packet invalid type)) and not Hello world as expected. The client output is very long, but the most interesting part is properly: main, received EOFException: error main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake main, SEND TLSv1 ALERT: fatal, description = handshake_failure I have attached the Haskell server, the Java client and the full java output. Hope somebody can help figure out what I do wrong. I am using the Haskell tsl package version 0.3.1. And I run Debian Linux. I also tried connecting a Java client to a Java server. First create server keystore: openssl pkcs8 -topk8 -nocrypt -in privkey.pem -inform PEM -out privkey.der -outform DER java -Dkeystore=myServerKeystore.store ImportKey privkey.der cert.der ImportKey.java can be found here http://www.agentbob.info/agentbob/79-AB.html . then start Java server: javac JavaServer.java java -Djavax.net.ssl.keyStore=myServerKeystore.store -Djavax.net.ssl.keyStorePassword=importkey JavaServer and run the client again: java -Djavax.net.debug=all -Djavax.net.ssl.trustStore=myKeystore.store -Djavax.net.ssl.trustStorePassword=foobar Client and the server outputs: Hello world as expected. Thus I think the certificates are fine, and the Java client is fine. But what am I doing wrong in the Haskell server? I have attached JavaServer.java. Regards, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Things I would like to see in protocol-buffers
Hi I have been trying to use protocol-buffers[2], and I have some ideas which would have improved the protocol-buffers package for my usage (and maybe for others): * hprotoc should have an option to generate messages with [Char], Int and [] in stead of Utf8, Int32 and Seq. While some people may need the speed of bytestrings, for others they are just cumbersome. And if you need to convert bytestring to [Char] anyway (maybe some other library requires [Char]) you really do not gain any performance anyway. * Integration with System.IO.Handle, so that I would have a simpler interface like: readDelimitedMessage :: System.IO.Handle - IO MessageType writeDelimitedMessage :: System.IO.Handle - MessageType - IO () * Union types. A common protocol buffers idiom for union types is[3]: message Foo { enum FooType { SOME_FOO_MESSAGE = 0; ANOTHER_FOO_MESSAGE = 1; } message SomeFoo { ... } message AnotherFoo { ... } required FooType fooType = 1; optional SomeFoo someFoo = 2; optional AnotherFoo anotherFoo = 3; } While the message can (statically) contain both someFoo and anotherFoo, it would be a runtime error. In reality it is a union type, that must either contain someFoo or antoherFoo. It would be nice if one could mark in the .proto file that hprotec should see Foo as a union type. Hprotoc should then generate the Foo type as: data Foo = SomeFoo ... | AnotherFoo ... Maybe the custom option mechanism[1] can be used in the .proto file, to implement this feature. What do people think of these ideas? Regards, Mads Lindstrøm [1] http://code.google.com/apis/protocolbuffers/docs/proto.html#options [2] http://hackage.haskell.org/package/protocol-buffers [3] http://code.google.com/apis/protocolbuffers/docs/techniques.html#union ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Protocol buffer network examples
Hi I am trying to read and write delimited messages[3] using protocol-buffers [1,2] over a socket. I have managed to write delimited messages and I was looking for examples of reading delimited messages. Maybe somebody has an example of reading delimited messages from a socket? The Haskell protocol-buffer[1] package mostly uses bytestrings, but I need to read from a socket. Of cause, I can use the bytestring package to read X number of bytes from a socket-handle. But it is impossible to know what X is, before you start parsing the message, as even integers are variable length in protocol buffers. Hope somebody can help, Mads Lindstrøm [1] http://hackage.haskell.org/package/protocol-buffers [2] http://code.google.com/p/protobuf/ [3] Delimited messages is a protocol buffers technique, where one writes the size of the message before the actual message: http://code.google.com/apis/protocolbuffers/docs/techniques.html#streaming ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: secure-sockets version 1.0
Hi David On Mon, 2010-09-06 at 13:50 -0700, David Anderson wrote: - Simple timing attacks: If code path A takes longer than code path B to execute, an attacker can use that information to reverse engineer the outcome of branching tests, and from there possibly recover secret key material. This is particularly nasty because the attack can be carried out remotely, by repeatedly executing the protocol in a way that exercises the vulnerable code path. I do not know much about cryptography, so I may be writing nonsense here, but it seems to me that it should not be too hard insuring that all wrongly encrypted data takes equally long to process. One could use an algorithm like: * make interrupt/timer that will finish in one second * process data from client * If data is correctly encrypted, stop interrupt/timer and return information to the client * If data is wrongly encrypted, prepare error-result, (busy) wait for interrupt/timer to finish, return result to client That will mean that all clients, that uses a wrong key, will take one second to finish. But as clients, with a correct key, finishes fast I do not see any problems. What am I missing here? /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: happstack 0.5.0
Hi Pressing documentation-link here http://happstack.com/index.html I still get the 0.4.1 version. But impressive set of new features. /Mads On Mon, 2010-05-03 at 12:57 -0500, Jeremy Shaw wrote: (Note: Reply-to is set to haskell-cafe@haskell.org) Hello, I am very pleased to announce Happstack 0.5.0. It should install cleanly from hackage via: cabal install happstack If it does not, please report errors to the happstack mailing list: http://groups.google.com/group/HAppS (You will, unfortunately, need to be subscribed due to SPAM issues). Here are the official release notes: Release Notes: This release should fix many (hopefully all) known cabal install related issues. It also includes many other improvements detailed below. Known issues: * dropped support for GHC 6.8. GHC 6.10 and 6.12 currently supported. * happstack-data compiled with -O0 due to bug in cabal http://thread.gmane.org/gmane.comp.lang.haskell.cafe/69215 You may be able to change that to -O2 if you first do: cabal install --reinstall syb-with-class --disable-documentation But we need a solution that works automatically when people run, cabal install happstack. Changes since 0.4.1: * many IxSet improvements by Gracjan Polak - hide IxSet constructor. use ixSet instead. - improved efficiency of gteTLE, getGTE, and getRange - get rid of Dynamic, just use Data.Typeable (internal change) - added deleteIx - Eq and Ord instances for IxSet - removed a bunch of cruft - greatly improved documentation - added stats function - Protect user from using unindexed keys in searches in IxSet - Runtime safeguard for badly formed inferIxSet indexes - Fixed IxSet Default instance - More detailed error messages in IxSet * work around bug in bytestring which causes the server to hang (http://hackage.haskell.org/trac/ghc/ticket/3808) * support for uincode Text and lazy Text types - Serialize/Version instances now provided automatically by happstack-data - instances of EmbedAsChild and EmbedAsAttr for Text for Identity, IdentityT, ServerPartT, and WebT. - patches sent upstream to HSP, waiting on acceptance * Added Serialize/Version instances for time / Data.Time library * Improvements to GuestBook demo by Gracjan Polak - better handling of Ctrl-C - simplified .cabal to only build executable * Improvements to GuestBook demo by Gracjan Polak - nice command line interface with help message and version information - restructured parsing of command line to make it scale better with further parameters - added reference to Paths_guestbook module to enable incorporating version and path information generated by cabal. - added withLogger transformer guaranteeing clean setup and teardown of loggers - Added clean shutdown to logging component. * fail instance for WebT now includes location of pattern match failure. e.g. src\AppControl.hs:43:24: Pattern match failure in do expression * added expireCookie function * Improvements to documentation * Additional test cases * Fixes many build failures * Experimental: Added proof of concept port of happstack-server to WAI. http://www.haskell.org/pipermail/haskell-cafe/2010-March/074142.html * added 'dirs' guard. (Similar to dir, but for a list of path components). * set SO_KEEPALIVE so that dropped connections will eventually time out * happstack-util only depends on QuickCheck when compiled with -ftests. This is wrong but solves a lot of annoy install failures. * file serve functions now use MonadPlus instead of setting explicit 404 * XMLMetaData for webHSP * Allow colons in cookie names Contributors: A big thanks to everyone who contributed patches for this release, including: Gracjan Polak (25 patches in this release!) Simon Meier Paulo Tanimoto Joachim Fasting Antoine Latter Simon Michael Adam Vogt Joe Edmonds Andrea Vezzosi Nils Schweinsberg ___ 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] happstack/SOAP
Hi I do not have an example for you, but I do have some text conversion functions you may find useful. I have attached the text conversion functions in a file. /Mads On Mon, 2010-04-26 at 09:46 +, Johannes Waldmann wrote: Hi - I'm looking for an example/demo happstack server that handles SOAP requests. - Thanks, J.W. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe {-# OPTIONS -Wall -XOverloadedStrings #-} module TextConversion ( soapXmlUtf8, soapXmlToString , soapContentType , E.DecodingException , E.EncodingException ) where import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy.Char8 as BsC8 import qualified Data.Encoding as E import qualified Data.Encoding.UTF8 as E import Text.Regex import Text.Parsec import Text.Parsec.ByteString.Lazy -- soapXmlUtf8, soapXmlToString, bsToUtf8, bsToString, StringToUtf8Bs may throw DecodingException -- or EncodingException -- |Converts a SOAP request to UTF8. If the request contains a XML header, -- the text encoding is set to UTF8. soapXmlUtf8 :: String-- ^The content type as seen in the HTTP header - BS.ByteString - BS.ByteString soapXmlUtf8 contentType = bsToUtf8 (encoding contentType) . setUtf8EncodingInXmlHeader -- |Converts a SOAP request to String. If the request contains a XML header, -- the text encoding is set to UTF8. soapXmlToString :: String-- ^The content type as seen in the HTTP header - BS.ByteString - String soapXmlToString contentType = bsToString (encoding contentType) . setUtf8EncodingInXmlHeader bsToUtf8 :: String - BS.ByteString - BS.ByteString bsToUtf8 enc = stringToUtf8Bs . bsToString enc bsToString :: String - BS.ByteString - String bsToString enc bs = E.decodeLazyByteString (E.encodingFromString enc) bs stringToUtf8Bs :: String - BS.ByteString stringToUtf8Bs = E.encodeLazyByteString E.UTF8 -- *** HTTP Header -- |Produces a HTTP content type header from a charector encoding soapContentType :: Maybe String -- ^ If nothing then it defaults to ISO-8859-1 - String soapContentType = maybe (application/soap+xml;charset= ++ httpDefaultEncoding) id -- |Extracts charector encoding from a HTTP content type header encoding :: String - String encoding httpContentType = case matchRegex (mkRegex charset=([^; ]*)) httpContentType of Just (x:_) - x _ - httpDefaultEncoding -- Default charset=ISO-8859-1. See: -- http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1 -- http://www.w3.org/International/O-HTTP-charset httpDefaultEncoding :: String httpDefaultEncoding = ISO-8859-1 -- *** XML Header -- http://www.w3.org/TR/REC-xml/#TextEntities setUtf8EncodingInXmlHeader :: BS.ByteString - BS.ByteString setUtf8EncodingInXmlHeader xml = let replaceEnc (name, value) | name == encoding = (name, UTF-8) | otherwise = (name, value) in case parse headerParser xml of Left _ - xml Right (attrs, rest) - BS.append (mkHeader $ map replaceEnc attrs) rest mkHeader :: [(String, String)] - BS.ByteString mkHeader attrs = let mkAttr (name, value) = ++ name ++ =\ ++ value ++ \ in BsC8.pack (?xml ++ concatMap mkAttr attrs ++ ?\n) headerParser :: Parser ([(String, String)], BS.ByteString) headerParser = do _ - string ?xml spaces attrs - many attrParser _ - string ? endPos - getInput return (attrs, endPos) attrParser :: Parser (String, String) attrParser = do name - many1 letter spaces _ - char '=' spaces _ - char '' value - many $ noneOf \ _ - char '' spaces return (name, value) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Getting used and available memory
Hi On Tue, 2010-04-27 at 14:55 -0700, Don Stewart wrote: We could bind to Rts.c in the GHC runtime, and get all the stats programmatically that you can get with +RTS -s That would be nice. /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Control.Exception try and catch
Hi From http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-Exception.html#3 ... The difference between using try and catch for recovery is that in catch the handler is inside an implicit block (see Asynchronous Exceptions) which is important when catching asynchronous exceptions ... However, 'try' is implemented by calling catch http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/src/Control-Exception-Base.html#try: try :: Exception e = IO a - IO (Either e a) try a = catch (a = \ v - return (Right v)) (\e - return (Left e)) Thus, I wonder, why do 'try' not inherit the implicit block mentioned above? Looking at catch: catch :: Exception e = IO a -- ^ The computation to run - (e - IO a) -- ^ Handler to invoke if an exception is raised - IO a catch io h = H'98.catch io (h . fromJust . fromException . toException) I see no call to 'block'. But maybe it is hidden in H'98.catch? And is H'98.catch == Prelude.catch ? /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Getting used and available memory
Hi I have tried haskell.org, Google and Hoolge, but I cannot find any function to give me the available and/or used memory of a Haskell program. Is it just not there? Or am I missing it somehow? /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Getting used and available memory
Hi I was _not_ looking for the OS-level measure, but rather something reported by the run-time. Thanks you for the answer anyway. /Mads On Tue, 2010-04-27 at 15:32 -0400, Daniel Peebles wrote: It's not an easy measurement to even define. There was a huge debacle recently about a windows program that reported misleading numbers about used memory. The fact that GHC has its own allocator and hogs OS memory (it never returns it to the OS) might complicate the definition further. But in general, if you're looking for an OS-level measure you're probably going to need to go to the FFI and talk to the specific OS's API for the task. I'm not sure if the GHC runtime allows you to ask much about allocated memory. The only thing I've done with it was FFI out to a variable that counts the number of bytes allocated to measure allocations in calls like GHCi does. On Tue, Apr 27, 2010 at 12:01 PM, Mads Lindstrøm mads.lindstr...@gmail.com wrote: Hi I have tried haskell.org, Google and Hoolge, but I cannot find any function to give me the available and/or used memory of a Haskell program. Is it just not there? Or am I missing it somehow? /Mads ___ 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] The instability of Haskell libraries
Hi On Sat, 2010-04-24 at 19:25 +1000, Ivan Lazar Miljenovic wrote: Roman Leshchinskiy r...@cse.unsw.edu.au writes: John Goerzen gave one in the very first post of this thread: the fix to old-locale which didn't change any types but apparently changed the behaviour of a function quite drastically. Another example would be a change to the Ord instances for Float and Double which would have compare raise an exception on NaNs as discussed in a different thread on this list. Another one, which is admittedly silly but demonstrates my point, would be changing the implementation of map to map _ _ = [] In general, any significant tightening/changing of preconditions and loosening/changing of postconditions would qualify. OK, fair enough, I see how these can be considered changing the API. Thing is, whilst it would be possible in general to have a tool that determines if the API has changed based upon type signatures, etc. how would you go about automating the test for detecting if the intention of a function changes in this manner? You could automatically generate QuickCheck tests for many pure functions. It will not catch every API change, but it would catch some. It would have caught the API change that John mentioned. But automatically generating QuickCheck tests to test if funOld == funNew, would require quite a bit work. But better than everybody having to write unit tests, as other have proposed. /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The instability of Haskell libraries
Hi On Sat, 2010-04-24 at 19:47 +1000, Ivan Lazar Miljenovic wrote: Mads Lindstrøm mads.lindstr...@gmail.com writes: You could automatically generate QuickCheck tests for many pure functions. It will not catch every API change, but it would catch some. It would have caught the API change that John mentioned. As in comparing the old and the new functions? Yes But automatically generating QuickCheck tests to test if funOld == funNew, would require quite a bit work. But better than everybody having to write unit tests, as other have proposed. Agreed; however, this has its own problems: you have to load up two versions of the same library and compare each pair of functions. Note that even this comparison isn't really legitimate: what happens if there was some edge/corner case that the old version didn't handle properly and thus the new one fixes it? The QC tests would say that they are different, even though they are actually the same. But that would be an API change. It is of cause a question of how strict we want to be. I have seen several times that commercial software developers denies changes bugs, as the fix would constitute API changes. We obviously do not want to go there, but we could bump the version number as it would require little work. Even if we could get around this, there remains another problem: automatically generating the kind of input each function expects (how do you encode pre-conditions automatically for such a tool to pick up? What about pure parsing functions?). Yes, for some functions it would be useless. Library developers could specify test-input in these cases. This would require work of each library developer, but still less than writing unit tests. /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: HXT Namespaces and XPath
Hi Uwe Hi Mads, Replying to myself: I think another example will clarify my point. The code: simpleXmlOne, simpleXmlTwo :: String simpleXmlOne = a:Foo xmlns:a=\http://foo.org\/ simpleXmlTwo = b:Foo xmlns:b=\http://foo.org\/ nsEnv :: [(String, String)] nsEnv = [ (notFoo, http://notfoo.org;) ] evalXPath :: String - [XmlTree] evalXPath xml = runLA ( xread propagateNamespaces getXPathTreesWithNsEnv nsEnv //a:Foo this line contains the problem: getXPathTreesWithNsEnv assumes, that for all prefixes used in the XPath expr, the nsEnv contains an entry. Furthermore the default namespace can be given by an entry for the empty prefix . So you'll only get reasonable results, when nsEnv contains at least an entry for a, e.g. nsEnv = [ (a, http://x.y;), ... ] when you use the XPath expr //a:Foo. You may argue, that in your example, an error should be raised by the XPath parser, instead of accepting //a:Foo. But currently it's assumed, that getXPathTreesWithNsEnv is used only in an innocent way. Yes, that was what I would have expected. Cheers, Uwe /Mads signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How do I use ByteString?
Hi Don Stewart wrote: gue.schmidt: Hi all, I've never found an easy way to deal with ByteStrings. I'm using the RSA library and it en- and decodes Data.ByteString.Lazy.ByteString. I initially start with Strings, ie. [Char], but there is no function to convert the 2 back and forth. There is however a function which takes [Word8] to BytesString and back. It all wouldn't be so confusing if there weren't several versions of ByteString in several modules to choose from. And a number of libraries requiring different types of ByteString. I am sure the designers of the bytestring package had good reason for this design, is there also a webpage which explains which one to use and under what circumstances? I really would like such a webpage, because I am also confused about when to use what type of strings. As a general rule you should never convert between String and bytestring. You can read bytestrings from files, or write literals using pack or the -XOverloadedStrings extension Except that different libraries require different kind of strings. Some use strict bytestring, some use lazy bytestring, some use [Char], some use lazy Data.Text, ... So you really need to convert between different representations. It may seem unfair that I put byte-strings and char-strings in the same bucket, but libraries do use byte-strings to contain characters. For example, Parsec has a [Char] and a bytestring interface. Strings are the glue that binds many libraries together, and the many different types of strings complicate this glue. It is therefore much more complicated to compose different libraries than it was when most libraries used [Char]. It really would make Haskell programming easier if we could settle on one char-string type (and one type for byte-strings). Converting between lazy and strict bytestrings is a representation change, and changes complexity - so be aware of what you're doing. You can do this via fromChunks or concat . toChunks. Reading the introduction to lazy bytestring here http://hackage.haskell.org/packages/archive/bytestring/0.9.1.5/doc/html/Data-ByteString-Lazy.html it seems that lazy bytestring always has at least as good complexity as strict bytestrings. Lazy Data.Text strings also has at least as good complexity as strict Data.Text strings. So, for public library interfaces it would be great if could settle for some lazy string type like Data.Text. Preferably a string type that could be efficiently converted to lazy bytestrings for libraries that deal with bytes and not characters. This however, requires that the community can settle for one char-string type and a good beginning could be a description of how string handling is supposed to happen in Haskell (I am thinking about a webpage like Günther writes about). /Mads -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: HXT error handling
Hi Uwe This is a right point. Here the current XPath calling interface is too simple. A separation into XPath parsing and evaluation would be more flexible. The parsing (and error handling of XPath syntax errors) could be done once. I will extend the interface to support this. That would be great. Thank you. Thanks for your comments and hints, Uwe /Mads signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: HXT Namespaces and XPath
Hi Uwe I read your reply multiple times, but I am still confused. I think either I misunderstand you or I did not explain myself properly in the first mail. Hi Mads, In HXT, namespace prefixes bound by an XML document are valid in the context of an XPath. How do avoid that? An example program will clarify: simpleXml :: String simpleXml = soap:Body xmlns:soap=\http://www.w3.org/2003/05/soap-envelope\/ nsEnv :: [(String, String)] nsEnv = [ (s, http://www.w3.org/2003/05/soap-envelope;) ] evalXPath :: String - String - [XmlTree] evalXPath xpath xml = runLA ( xread propagateNamespaces getXPathTreesWithNsEnv nsEnv xpath ) xml Here: evalXPath //s:Body simpleXml == evalXPath //soap:Body simpleXml Even though I only mentions the prefix s (and not soap) in the function nsEnv. When working with namespaces in XML, the prefixes are not longer significant. After namespace propagation every name in the XML document is identified by a qualified name. This is a pair consisting of the namespace URI and the local part. The prefixes become irrelevant. This is my point. Prefixes are relevant in the current implementation of HXT. A namespace aware XPath expression needs a namespace environment, as given in the example, to construct these qualified names for the names in the XPath expression. So the results of both evalXPath calls in your example must be the same. Yes, but in the namespace environment I give to getXPathTreesWithNsEnv I only mention the prefix s, yet I am still able to evaluate the xpath //soap:Body. Furthermore //s:body and //soap:Body gives the same results. Why? I think another example will clarify my point. The code: simpleXmlOne, simpleXmlTwo :: String simpleXmlOne = a:Foo xmlns:a=\http://foo.org\/ simpleXmlTwo = b:Foo xmlns:b=\http://foo.org\/ nsEnv :: [(String, String)] nsEnv = [ (notFoo, http://notfoo.org;) ] evalXPath :: String - [XmlTree] evalXPath xml = runLA ( xread propagateNamespaces getXPathTreesWithNsEnv nsEnv //a:Foo ) xml Now notice that simpleXmlOne and simpleXmlTwo are equivalent. Yes, they have a different prefix for http://foo.org;, but the documents means the same. And as you write yourself, ... the prefix is no longer releavant ... Yet: evalXPath simpleXmlOne /= evalXPath simpleXmlTwo Hope that clarifies things. Regards, Mads signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: HXT Namespaces and XPath
Hi Replying to myself: I think another example will clarify my point. The code: simpleXmlOne, simpleXmlTwo :: String simpleXmlOne = a:Foo xmlns:a=\http://foo.org\/ simpleXmlTwo = b:Foo xmlns:b=\http://foo.org\/ nsEnv :: [(String, String)] nsEnv = [ (notFoo, http://notfoo.org;) ] evalXPath :: String - [XmlTree] evalXPath xml = runLA ( xread propagateNamespaces getXPathTreesWithNsEnv nsEnv //a:Foo ) xml Now notice that simpleXmlOne and simpleXmlTwo are equivalent. Yes, they have a different prefix for http://foo.org;, but the documents means the same. And as you write yourself, ... the prefix is no longer releavant ... Yet: evalXPath simpleXmlOne /= evalXPath simpleXmlTwo Just to clarify things. The point I am making is that: getXPathTreesWithNsEnv nsEnv //a:Foo do not only see the prefixes in 'nsEnv', but also the prefixes in the XML it is applied to. I think that the getXPathTreesWithNsEnv function should only see the prefixes mentioned in its first parameter. Regards, Mads signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HXT Namespaces and XPath
Hi all, In HXT, namespace prefixes bound by an XML document are valid in the context of an XPath. How do avoid that? An example program will clarify: simpleXml :: String simpleXml = soap:Body xmlns:soap=\http://www.w3.org/2003/05/soap-envelope\/ nsEnv :: [(String, String)] nsEnv = [ (s, http://www.w3.org/2003/05/soap-envelope;) ] evalXPath :: String - String - [XmlTree] evalXPath xpath xml = runLA ( xread propagateNamespaces getXPathTreesWithNsEnv nsEnv xpath ) xml Here: evalXPath //s:Body simpleXml == evalXPath //soap:Body simpleXml Even though I only mentions the prefix s (and not soap) in the function nsEnv. I do not want the XPath to see prefixes declared in the xml-document, as it means that two semantically similar XML documents can get different results when applied to the same XPath. Also, is there any way to get 'getXPathTreesWithNsEnv' to recognize XPath namespace declarations? I am thinking about declarations like: declare namespace foobar='http://foobar.org/foobar' Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HXT error handling
Hi I am trying to use HXT to evaluate XPath expressions. The XPath expressions are not specified by myself, but by users of my program. However, the idea behind HXT's error handling confuses me. Maybe somebody can enlighten me. This program fragment: evalXPath :: String - String - [XmlTree] evalXPath xpath xml = runLA ( xread propagateNamespaces getXPathTrees xpath ) xml seems to work fine, except when it comes to error handling. If the xml-string is malformed, the error is simply ignored and the evalXPath-function just returns an empty list. I can understand what happens. 'getXPathTrees xpath' tries to match the xpath to a XmlTree which represents a parse error, and it therefore never matches anything. What I do not understand, is when this behavior would be desirable. Or why do the error in 'xread' not propagate throughout the arrow, similar to how: foobar :: Either String Int foobar = do _ - fail Some failure return 2 the error in 'foobar' would propagate and 'foobar = Left Some failure'. What if the xpath-parameter contains an invalid XPath expression? Well, then the output depends upon both the xpath and the xml -parameters. That is: length (evalXPath /./ foo/ ) == 3 whereas length (evalXPath /./ foo/) == 1 Which just seems strange to me. If we add a getText to evalXPath: evalXPath :: String - String - [String] evalXPath xpath xml = runLA ( xread propagateNamespaces getXPathTrees xpath getText -- added here ) xml Then an error in the xpath-parameter will be hidden by the getText function, similar to how 'getXPathTrees xpath' ignores errors in the xread function. Again, I understand what happens, I just cannot see why it is designed as it is. What I really would like was functions like: parseStr :: (Monad m) = String - m XmlTrees parseStr xml = case Parsec.xread xml of (x:xs) - if (Dom.isError x) then fail Could not parse tree else return (x:xs) [] - fail No XML tree resultet from parsing XML And a similar function for the XPath. This could also speed up my program, as I would not parse the same XPath again and again. A stand-alone function to parse an XPass expression, would also make it easy to create a Template Haskell parse-xpath-function, that gave compile-time error messages and increased performance for XPath expression know at compile-time. Regards, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] libraries [was GUI haters]
Hi gladst...@gladstein.com wrote: As a working engineer, one of my greatest frustrations is my inability to use Haskell in the workplace. The unfortunate fact is that my media industry clients use mostly Windows, some Macs, and no linux except for servers. The core system works everywhere, but many contributed libraries don't. GUIs are the big showstopper. One of the reasons Java won out over Common Lisp is that it had huge libraries. Franz's libraries were superb but few in number. One diehard Lisp user converted his lab to Java because Java gives you everything you want, for free. That languages are distinct from their libraries escapes a lot of people; they see each language as a package. I met a COBOL programmer recently (I'm not making this up) that was looking into Java. He didn't see how people could use it, he said, because it had thousands of commands. Looking at Wikipedia I can see that COBOL 2002[1] got user defined functions, but prior it was impossible to define your own functions. You could define sub-rutines (semantically similar to jsr/gosub in assembler/basic), but not functions that could be used like the build-in (intrinsic in COBOL speak) functions. Most COBOL programmers properly still do not use user-defined functions. So from their perspective, it is perfectly reasonable to see functions as part of the language. My point is, that it is properly true that most COBOL programmers sees functions as part of the language. But you cannot generalize from COBOL programmers to programmers in say Java, in this particular case. I'll stop whining now. Greetings, Mads Lindstrøm [1] http://en.wikipedia.org/wiki/COBOL#COBOL_2002_and_object-oriented_COBOL signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Garbage collecting pointers
Hi For some time I have been thinking about an idea, which could limit Haskell's memory footprint. I don't know if the idea is crazy or clever, but I would love to hear peoples thoughts about it. The short story is, I propose that the garbage collector should not just reclaim unused memory, it should also diminish the need for pointers, by replacing nested data structures with larger chunks of consecutive memory. In other words, I would diminish the need for pointers for arbitrary recursive data types, just as replacing linked lists with arrays eliminate the need for pointers. I will explain my idea by an example of a data type we all know and love: data List a = Cons a (List a) | Nil each Cons cell uses two pointers - one for the element and one for the rest of the list. If we could somehow merge the element and the rest of the list into consecutive memory, we would be able to eliminate the pointer to the rest of list. On 64 bit architectures merging would save us 8 bytes of wasted memory. If we could merge n elements together we could save n*8 bytes of memory. 64 bit pointers are wasteful in another way, as nobody has anywhere near 2^64 bytes of memory. And nobody is going to have that much memory for decades to come. Thus, we could use the 8 most significant bits for something besides pointing to memory, without loosing any significant ability to address our memories. This would be similar to how GHC uses some of the least significant bits for pointer tagging. I suggest using the 8 most significant bits for what could be termed the length of the pointer. A length of zero would mean that the pointer, pointed to a Cons-cell just like we have them today. A length of one would mean that one extra element were embedded into the cons cell. That is, we would have this block of consecutive memory: Cons marker pointer to 1. element Cons marker pointer to 2. element pointer to rest of list We could also call this a chunk of length two. A pointer of length two, would mean two embedded list elements (a chunk of length three). And so on... By embedding the length of the list in the pointer, it becomes possible that one pointer could point to the beginning of a chunk of n consecutive elements, while another one could point to the middle of the same chunk (but the pointer would be of a different length). This would enable sharing without having to break up into smaller chunks. How should chunks be created? Or if a functions creates a lot of one long chunks, how are they turned into longer chunks. I imagine that it would be the job of the garbage collector, to merge the different elements in a list into larger chunks. Of cause some code, like reading a file, could create chunks directly. I have used list as an example. But I imagine that GHC could do this for any recursively defined data type. I can see few, but big disadvantages also. Mainly, my scheme would complicate dereferencing a pointer, which make the compiled code larger and it might make branch prediction harder. The latter would only be a problem on architectures that are pipelined, but popular processors from Intel and AMD are both heavily pipelined. /Mads signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Garbage collecting pointers
Hi On Fri, 2010-03-26 at 21:24 +, Sebastian Sylvan wrote: On Fri, Mar 26, 2010 at 9:21 PM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On Mar 26, 2010, at 16:28 , Mads Lindstrøm wrote: For some time I have been thinking about an idea, which could limit Haskell's memory footprint. I don't know if the idea is crazy or clever, This is called pointer tagging. The original STG design avoided it because of the perceived performance loss in removing the tags before using the pointer, but as I understand it the current GHC design uses limited tagging. I don't think that's what he's talking about. He's saying the data that would normally be on the other side of the pointer would instead be stored inline, if I understand him correctly. Yes, that was what I tried to convey. Thanks, for clarifying for me. /Mads -- Sebastian Sylvan signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Garbage collecting pointers
Hi On Fri, 2010-03-26 at 21:33 +, Sebastian Sylvan wrote: Reorganizing data on the fly sounds like it may be a pretty sensible idea now that cache misses are so bad (in comparison). The fact that Haskell data is generally immutable helps too. However, I think your scheme sounds a bit complicated for my tastes, and I don't really understand the idea of lengths, what would n consecutive elements mean for a tree? Surely this wouldn't work just for list-like data structures? First of all, I had assumed that a data type's memory footprint was independent of its value. Similarly to how a C-union always occupies the same amount of memory. After reading your post, I reevaluated my assumption and my assumption might just be wrong. However, if my assumption is right we could lay out the memory in a preorder fashion. The following tree: a / \ / \ b c / \ / \ d e f g would have the following memory layout: a, b, d, e, c, f, g. A pointer to element a would be of length 6 (a + 6 additional elements). The preorder layout would also allow us to point to part of the structure. For example, we could make a pointer to element b of length 2 (b + 2 additional elements). In this way, we do not need to brake a larger chunk into smaller ones to enable sharing of data. Neither would we need to scan though the hole structure, when only pointing to a part of the structure. Something that seems a bit easier to work with would be to use just two data layouts, one which uses pointers everywhere like now, and one in which every single field is expanded one level (each of them could in turn be expanded one more level, but you don't know that until you look at it). If one of the fields can't be expanded (e.g. because it would become cyclic) then you just have to keep the fully pointerfied version. It's still a bit tricky because the offset to a specific member would be depend on the specific sizes of the previous fields in the layout (which can vary depending on the actual value). It would always possible to figure it out at runtime, though, by scanning through the fields each time finding the next one by incrementing the size, and you could just disable this feature for large data types. You could potentially store a heavily quantized lookup table (possibly at the expense of padding some members to align all members on a large common multiple from the base). Would scanning not run the risk of changing the asymptotic complexity of programs? What do heavily quantized lookup table mean? It is the heavily quantized part I do not get. The general idea seems interesting to me, but then I'm hardly an expert. I like the notion of using the fact that the language is free to change the data representation at runtime to improve performance by collapsing an immutable (recursive) data structure once it's been created. Partly because it's something that would be harder to do in other languages! -- Sebastian Sylvan /Mads signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bytestrings and [Char]
Hi David Leimbach wrote: On Mon, Mar 22, 2010 at 6:10 AM, Johan Tibell johan.tib...@gmail.com wrote: On Mon, Mar 22, 2010 at 1:16 PM, Johann Höchtl johann.hoec...@gmail.com wrote: My question or discussion point: Why not depreciate [Char] altogether and favour of lazy Bytestrings? A sequence of bytes is not the same thing as a sequence of Unicode code points. If you want to replace String by something more efficient have a look at Data.Text. Slight correction. A sequence of bytes is exactly the same thing as a sequence of Unicode bytes when you use UTF8. And a sequence of bytes is exactly the same thing as a UTF-32 string, when the sequence is encoded as UTF-32. But that is not the point. The point is that when some function is handed a ByteString, the ByteString can be encoded in many ways. It do not even have to be text. So you need a UTF-8 String type. /Mads -- Johan ___ 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 signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Why no instance of Happstack.Data.Default.Default for Data.ByteString.Lazy
Hi Why is that Happstack has: instance Happstack.Data.Default.Default Data.ByteString But not one for: instance Happstack.Data.Default.Default Data.ByteString.Lazy I am trying to make a HTTP proxy using Happstack and the client part with the Network.HTTP (see Hackage). Network.HTTP.simpleHttp returns a lazy Bytestring when given a lazy Bytestring (which makes sense). Happstack on the other hand contains a lazy ByteString in its request type: data Request = Request { ... rqHeaders :: Headers, ... rqBody :: RqBody ... } newtype RqBody = Body Data.ByteString.Lazy.Internal.ByteString which Happstack.Server.SimpleHttp.simpleHTTP feeds into my application. However Happstack.Server.SimpleHttp.simpleHTTP expects something returned which is an instance of Happstack.Data.Default.Default which lazy ByteString is not. Confused? So am I. Who thought String handling could be so complex. Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell (Byte)Strings - wrong to separate content from encoding?
Hi More and more libraries use ByteStrings these days. And it is great that we can get fast string handling in Haskell, but is ByteString the right level of abstractions for most uses? It seems to me that libraries, like the Happstack server, should use a string-type which contains both the content (what ByteString contains today) and the encoding. After all, data in a ByteString have no meaning if we do not know its encoding. An example will illustrate my point. If your web-app, implemented with Happstack, receives a request it looks like http://happstack.com/docs/0.4/happstack-server/Happstack-Server-HTTP-Types.html#t%3ARequest : data Request = Request { ... rqHeaders :: Headers, ... rqBody :: RqBody ... } newtype RqBody = Body ByteString To actually read the body, you need to find the content-type header, use some encoding-conversion package to actually know what the ByteString means. Furthermore, some other library may need to consume the ByteString. Now you need to know which encoding the consumer expects... But all this seems avoidable if Happstack returned a string-type which included both content and encoding. I could make a similar story about reading text-files. If some data structure contains a lot of small strings, having both encoding and content for each string is wasteful. Thus, I am not suggesting that ByteString should be scraped. Just that ordinarily programmers should not have to think about string encodings. An alternative to having a String type, which contains both content and encoding, would be standardizing on some encoding like UTF-8. I realize that we have the utf8-string package on Hackage, but people (at least Happstack and Network.HTTP) seem to prefer ByteString. I wonder why. Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Cabal will not find HaXml
Hi When I do: cabal list --simple-output | grep -i HaXml 1.20 I get: HaXml 1.20 HaXml 1.20.1 HaXml 1.20.2 But when running: runhaskell Setup.hs configure I get: Configuring XrcAccessors-0.0... Setup.hs: At least the following dependencies are missing: HaXml -any My cabal file looks like: snip Executable XrcAccessors Main-is: XrcAccessors.hs Build-Depends: base==3.0.*, pretty==1.0.*, HaXml hs-source-dirs:src /snip This is very confusing to me. Why will Cabal not find HaXml when running Setup.hs, but do find it when running cabal list ? My Setup.hs looks like: import Distribution.Simple main = defaultMain I have tried reinstalling HaXml, but that do not help. I have noticed one thing though, when doing: ghc-pkg I get output like: snip /home/ghc6103/lib/ghc-6.10.3/./package.conf: Cabal-1.6.0.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0, array-0.2.0.0, base-3.0.3.1, base-4.1.0.0, bytestring-0.9.1.4, containers-0.2.0.1, directory-1.0.0.3, (dph-base-0.3), (dph-par-0.3), /snip snip /home/ghc6103/.ghc/x86_64-linux-6.10.3/package.conf: Cabal-1.6.0.2, Cabal-1.8.0.2, Diff-0.1.2, HDBC-2.1.1, HDBC-odbc-1.1.6.0, HDBC-odbc-2.1.0.0, HTTP-4000.0.4, HUnit-1.2.2.1, HaXml-1.20.2, MetaHDBC-0.1.0, QuickCheck-2.1.0.3, SQLLib-0.0, /snip That is, HaXml shows itself in the /home/ghc6103/.ghc/x86_64-linux-6.10.3/package.conf list, but not in the /home/ghc6103/.ghc/x86_64-linux-6.10.3/package.conf . Is this the problem and how do I fix it? Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cabal will not find HaXml
Hi The --user flag did the trick. Thank you very much. /Mads Daniel Fischer wrote: Am Sonntag 28 Februar 2010 14:41:03 schrieb Mads Lindstrøm: Hi When I do: cabal list --simple-output | grep -i HaXml 1.20 I get: HaXml 1.20 HaXml 1.20.1 HaXml 1.20.2 So there are versions HaXml 1.20* available on hackage But when running: runhaskell Setup.hs configure For that, you must have one installed already, and unless you pass the -- user flag, that must be in the global package database. I get: Configuring XrcAccessors-0.0... Setup.hs: At least the following dependencies are missing: HaXml -any ghc-pkg I get output like: snip /home/ghc6103/lib/ghc-6.10.3/./package.conf: Cabal-1.6.0.3, HUnit-1.2.0.3, QuickCheck-1.2.0.0, array-0.2.0.0, base-3.0.3.1, base-4.1.0.0, bytestring-0.9.1.4, containers-0.2.0.1, directory-1.0.0.3, (dph-base-0.3), (dph-par-0.3), /snip global package database, no HaXml snip /home/ghc6103/.ghc/x86_64-linux-6.10.3/package.conf: Cabal-1.6.0.2, Cabal-1.8.0.2, Diff-0.1.2, HDBC-2.1.1, HDBC-odbc-1.1.6.0, HDBC-odbc-2.1.0.0, HTTP-4000.0.4, HUnit-1.2.2.1, HaXml-1.20.2, MetaHDBC-0.1.0, QuickCheck-2.1.0.3, SQLLib-0.0, /snip user package database, HaXml present That is, HaXml shows itself in the /home/ghc6103/.ghc/x86_64-linux-6.10.3/package.conf list, but not in the /home/ghc6103/.ghc/x86_64-linux-6.10.3/package.conf . Is this the problem Yes. and how do I fix it? a) cabal install XrcAccessors, in contrast to the runghc ./setup.hs ... route, cabal install's default is user installs b) pass the --user flag to runghc ./Setup.hs configure c) (not recommended in general) make a global install of HaXml, either by runghc ./Setup... or cabal install --global HaXml Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Recursively traversing a data structure with HXT
Hi I am trying to use HXT (8.3.2) for parsing XML. I think an example will clarify what I want to do. I want to parse XML like this: object class=ex1 foo/ foo object class=ex2/ object class=ex3/ /foo object class=ex4/ /object and want to turn it into the following Haskell data structure: data Widget = Widget { cls :: String , children :: [Widget] } The XML above should be turned into: Widget ex1 [Widget ex2 [], Widget ex3 [], Widget ex4 []] That is, I want everything but the object-tags stripped out. And I want to keep the hierarchy of the object-tags. I thus wrote the following program: {-# LANGUAGE Arrows, NoMonomorphismRestriction #-} module Main where import Text.XML.HXT.Arrow data Widget = Widget { cls :: String , children :: [Widget] } deriving Show main = (runX (readDocument [(a_validate,v_0)] test.xrc getObject)) = print getObject = deep (isElem hasName object) proc x - do cls - getAttrValue class- x cs - listA getObject getChildren - x -- recursive call here returnA - Widget cls cs But it do not work as intended. In stead I get the following output: [Widget {cls = ex1, children = []},Widget {cls = ex1, children = []},Widget {cls = ex1, children = []},Widget {cls = ex1, children = []},Widget {cls = ex1, children = []},Widget {cls = ex1, children = []},Widget {cls = ex1, children = []}] Hopefully somebody can point me in the right direction. Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Value classes
Hi A function inc5 inc5 :: Float - Float inc5 x = x + 5 can only be a member of a type class A, if we make all functions from Float - Float members of type class A. Thus, I assume, that _type_ class is named type class, as membership is decided by types. However, it makes no sense to say that all functions from Float - Float are invertible or continuous. We would want to specifically say that inc5 is continuous, not all Float - Float functions. Thus, we could have another abstraction, lets call it _value_ class, where we could say that an individual value (function) could be member. We could say something like: class Invertible (f :: a - a) where invert :: f - (a - a) instance Invertible inc5 where invert _ = \x - x - 5 In many cases this would be too specific. We would like to say, that applying the first argument to `+` returns an invertible function. Something like: instance Invertible (`+` x) where invert (x +) = \y - y - x We would properly also like to say, that composing two invertible functions results in another invertible function. I guess there are many more examples. This idea, of value classes, do not feel all that novel. Somebody has properly thought about it before, but gave it a different name. If anybody has links to some papers it would be much appreciated. If anybody has some thoughts of the desirability of value class it would also be much appreciated. /Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Possible bug in Data.IP (network-data package)
Hi The network-data (version 0.0.2) [1] contains the module Data.IP. This modules encapsulates IPv4 headers. The Data.IP modules contains the type IPv4Header: data IPv4Header = IPv4Hdr { hdrLength :: Int , version :: Int , tos :: Int , payloadLength :: Int ... The code to turn IPv4 packages into IPv4Heder looks like [2]: instance Binary IPv4Header where put (IPv4Hdr ihl ver tos len id flags off ttl prot csum src dst) = do pW8 $ (ihl .. 0xF) .|. (ver `shiftL` 4 .. 0xF0) pW8 tos pW16 len pW16 id let offFlags = (off .. 0x1FFF) .|. fromIntegral (fromEnum flags `shiftL` 13) pW16 offFlags pW8 ttl pW8 prot put csum put src put dst That is, the payload length is the 16-31'th bit of the IPv4 header. This field is according to [3] and [4] referred to as total length - not payload length. The total length include both the length of the data and the header. When I read the term payload length I first thought it referred to the length of the package excluding the header. So I am right to see this as a bug in network-data ? Regards, Mads Lindstrøm [1] http://hackage.haskell.org/package/network-data [2] http://hackage.haskell.org/packages/archive/network-data/0.0.2/doc/html/src/Data-IP.html [3] http://tools.ietf.org/html/rfc791 [4] http://en.wikipedia.org/wiki/IPv4#Header signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] excercise - a completely lazy sorting algorithm
Hi Petr, Maybe this will give inspiration http://en.wikipedia.org/wiki/Selection_algorithm It seems to me, that you just need a selection algorithm which works in O(n * k) time for k arbitrary elements. If you combine O(n*k) selection algorithm with any O(n * lg n) sort, you furfil your time constrain. Regards, Mads Hi all, about a month ago, we were discussing sorting in Haskell with a friend. We realized a nice property of lazy merge-sort (which is AFAIK the implementation of Data.List.sort): Getting the first element of the sorted list actually requires O(n) time, not O(n * log n) as in imperative languages. And immediately we asked: Would it be possible to create a lazy selection/sorting algorithm so that getting any element of the sorted list/array by its index would require just O(n) time, and getting all the elements would still be in O(n * log n)? More precisely: The result of sorting an n-element list or array should be a structure that allows to ask i-th element of the result (for example, a lazy array). Asking k arbitrary elements should take no more than O(min(n * log n, k * n)) I believe that this could be done, but so far I wasn't able to implement and show it myself. I think the solution would be somewhat modified lazy quicksort (or Median of Medians algorithm if we want to be sure that we get good pivots). Perhaps somebody else would also like to give it a try? Or perhaps explain me why it's not possible? Best regards, Petr ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ORM for haskell?
Hi Marc Weber Hi Mads! On Tue, Jun 30, 2009 at 11:49:40PM +0200, Mads Lindstrøm wrote: Hi Marc Weber Another example: Updating the age of a pupil: row = SELECT * FROM pupils where age = 13; UPDATE pupils SET age = 14 WHERE id = the id you got above p = session.query(Pupil).filter(Pupil.age==13).one().age=14 session.commit() difference? You don't have to care about ids. you just assign a new value and tell the engine that it should commit. So again less chances to get something wrong. Could you not do in SQL: UPDATE pupils SET age = 14 WHERE age = 13 Of course. But: you can pass around that pupil object to another function and still assign a new age then run session.commit(). When passing around the pupile you can follow the relation_ships (relations?) back to school. def doSomething(pupil): pupil['age'] = 13 pupil.teacher.school.rating += 1 doSomething(session.query(Pupil).filter(Pupil.age==13)) session.commit() Now how would you do this using SQL? As far as I know, you cannot. And it is very nice. On the other hand you sometimes want to execute more of the logic on the DBMS, as it leads to better performance. But maybe we can somehow have our cake and eat it too. E.g. if the user still have some control about where the logic is executed. Sorry about the confustion (relation / relation-ship). I mixed up the terminology. Anyway I guess you can see here how powerful an ORM can be and why we should write such a library for haskell. Don't be sorry about that. I know people often confuse the terms and I could have replied just asking if you had not swapped the two terms. In my native language relation can mean both relation and to relationship. Guess, it is the same in other languages... I think it's very hard to invent such a short synax in haskell cause you have to take monads into account etc.. And it matters how much time you have to spend writing code. Yes and yes. I think (my gut tells me so) you will need to use Template Haskell, if you want something as succinct as the Python code you showed. Or maybe if you give up type safety, but I guess your are not willing to do that. But it could be fun (and challenging) coming up with something really nice. Thanks for your feedback. I hope there will be some more. Marc Weber I may have sounded a bit negative in my previous mails. But I really can see something cool about what you describe. That said, I think people are sometimes too eager to replace SQL. As you properly are already aware, SQL+Relational databases has some very nice properties (list below is form the top of my head, there are other advantages): * They are accessed with a declarative language (SQL) * They can make high-level optimization automatically and guided by the user * They can, transparently, execute queries/updates using multiple servers/CPUs. It may require some changes to the database, but it can be done without changing your SQL * They are based on a nice theoretical foundation * If databases are normalized properly, data are a lot more transparent than other ways of organizing data. At least other ways I have seen. * Normalization provides a lot less ambiguous guidance, than other development methodologies. * Transaction support But as you point out yourself, everything is not rosy. And in addition to what you write, all the (un)marshaling you need when accessing databases from Haskell is quite cumbersome. And I realize that you are not trying to replace RDBs, just building a nicer interface to them. I am just concerned that some of the nice properties are lost in the process. I think my main concern comes from seeing people create databases, by automatically generating tables from OO-classes. They invariably ends up with something not nearly as nice, as if they had constructed the database in a more traditional fashion. To summarize, what you propose is cool. Just do not throw the baby out with the bathwater. Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ORM for haskell?
Hi Marc Example why it matters: schools - 1:n - teachers - 1:n - pupils If you want to list all schools which have a pupil with age 3 you'd write an sql query like this: SELECT dictinct * FROM schools as s JOIN teachers t ON (t.school_id = s.id) JOIN pupils as p ON (p.teacher_id = t.id) WHERE p.age 3 in SQLAlchemy it looks like this: session.query(School).join(School.teachers).join(Teacher.pupils).filter(Pupil.age 3).all() difference? Because SQLAlchemy knows about the relations you don't have to remember alias names. So there is no chance to get that wrong. I do not get this explanation, could you expand? I would have thought it should be: difference? Because SQLAlchemy knows about the relationships (not relations, but relation_ships_), it do not have to explicitly join on foreign keys.. Actually SQL has natural joins, where you can do without explicit join conditions. Unfortunately, natural joins seems like they were explicitly designed to create trouble. It would be nice if they fixed SQL to consider relationships. Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ORM for haskell?
Hi Marc Weber Another example: Updating the age of a pupil: row = SELECT * FROM pupils where age = 13; UPDATE pupils SET age = 14 WHERE id = the id you got above p = session.query(Pupil).filter(Pupil.age==13).one().age=14 session.commit() difference? You don't have to care about ids. you just assign a new value and tell the engine that it should commit. So again less chances to get something wrong. Could you not do in SQL: UPDATE pupils SET age = 14 WHERE age = 13 That is, without using ids. Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Utrecht Attribute Grammar and Emacs
Hi Has anybody implemented an Emacs mode for the Utrecht Attribute Grammar System (UUAG), and is willing to share it ? Greetings, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing a compiler in Hakell
Hi Doaitse Doaitse Swierstra wrote: Dear Rouan, on http://www.cs.uu.nl/wiki/HUT/WebHome you will find a collection of tools which may help you to construct a compiler. As an example you will find a Tiger compiler constructed with the uulib tools and the uuagc attribute grammar system. Tiger is the language used in the book series by Andrew Apple. Not that Tiger is a great language, but the compiler contains an instance of all the things that have to be done when writing a compiler. Once you like these tools you may take a look at the UHC compiler, which actually is a series of compilers, starting from a small language, which is than gradually extended, both with new language concepts and with new aspects, such as code generation, new forms of types etc. Here you will also see that writing a compiler for a language like Haskell is not a small endeavour. I tried the uu-parsinglib and must admit, that I got a bit frustrated. In my rant below I may sound very negative, but that is not my intention. My intention is to give you my initial impression of the rough spots when trying uu-parsinglib, which you may (or may not) use if you want to make uu-parsinglib more newcomer friendly. First the 55 page document Combinator Parsing: A Short Tutorial has, in my mind, some shortcoming: * A 55 page document should have a table of contents. It helps people understand the structure, and makes the document easier to navigate. * It is not really a tutorial! Or at least, not a tutorial that gets you quickly writing parses using uu-parselib. It describes alternative implementation, why something is implemented in a particular way, how something is implemented, ... These are all good things, but not something that helps me get started. They belong in an advanced section. Or maybe it would be better with two documents, with different target audiences. Furthermore, the Tiger example is good. But please provide type signatures for all functions. The signatures may be obvious to you, but for the newcomer they may not be. When I look at the uu-parselib interface [1] it seems very sparse. Compared to Parsec, I miss a lot of the standard combinators [2]. It seems like you have to implement those combinators yourself. Finally, there is no Haddock documentation in uu-parselib. The lack of entry-level documentation and few predefined parsing combinators in uu-parselib do make for a steep learning curve. Kind regards, Mads Lindstrøm [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uu-parsinglib [2] http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/Text-Parsec-Combinator.html signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] haskell - main function
Hi applebiz89 wrote: Could anyone look at this segment of code; it's not compiling wondering if anyone could correct me as to why. Thanks Code: -- Film as datatype type Title = String type Director = String type Year = Int type Fan = String data Film = Film Title Director Year [Fan] -- List of films testDatabase :: [Film] testDatabase = [(Film Casino Royale Martin Campbell 2006 [Garry, Dave, Zoe]) ] becomeFan :: Title - fanName - [Film] - [Film] becomeFan _ _ [] = [] becomeFan Title fanName ((Film Title Director Year fan):xs) | filmName == title = (Film Title Director Year fanName:fan) : xs | otherwise = (Film Title Director Year fan) : becomeFan Title fanName xs main :: [Film] - IO() main db = do putStr Hi there! what is your name: fanName = getLine do putStr 1 = Insert film, 2 = Become a Fan, 3 = The number of fans of a film, 4 = Film released in a year, 5 = Given fan, 6 = Stop : input = getLine x = read input :: Int if x == 1 then do putStr Enter film title: filmTitle - getLine putStr Enter director name: filmDirector - getLine putStr Enter release year: filmYear - getLine main insertFilm [Title Director Year [Film]] else if x == 2 then do putStr Enter film title: filmTitle - getLine putStr Enter fan name: fanName - getLine main becomeFan [Title fanName] else if x == 3 then do putStr Enter film title: filmTitle - getLine main numberOfFans [Title] else if x == 4 then do putStr Enter film release year: filmYear - getLine main filmsInGivenYear [Year [Film]] else if x == 5 then do putStr Enter the fan name: fanName - getLine main givenUser [fanName [Film]] else if x = 6 then return () You have an if without an else. You cannot have that. What should the program do when x /= 6. And you write x = 6 in stead of x == 6. But generally speaking, you want to include compiler output in this is not compiling-messages to haskell-cafe. Regards, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Interesting Thread on OO Usefulness (scala mailing list)
Hi Bulat Ziganshin wrote: Hello Paolo, Monday, May 4, 2009, 2:05:44 PM, you wrote: Martin Odersky advocates the OO features of the scala language proposing an interesting problem where the OO approach seams valuable. i know two problems in Haskell/GHC that require OO-loke features - extensible exceptions and GUI widget types hierarchy Yes, type hierarchies require OO. But, do we really need to represent different widget-types in a hierarchy? An alternative to a big hierarchy would be to let different widget-types implement different type classes. We could have type classes like MouseEvents, KeyboardEvents, Activated, ... /Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] When is it OK to create a new mailing list?
Hi I wanted a mailing list for my project WxGeneric and I am wondering when it is OK to do so? How big must the potential audience be? Is there any kind of etiquette or guidelines? Here http://haskell.org/mailman/admin it says that I must have the proper authority to create a mailing list. What is meant by proper authority? Can I just try to create one and see if I am successful? Or must I request someone to do it? Regards, Mads Lindstrøm signature.asc Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] SQL Parsers in Haskell
Hi Haskelleers Has anybody written a SQL parser in Haskell (and is willing to share the code) ? Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Sugestion for a Haskell mascot
Hi Maurício Great idea. I would love a toy one with a Lambda logo. I found one on Amazon http://www.amazon.com/Plush-Sloth-Bear-Cuddlekin-12/dp/B000FBLP76 , but without the logo. But we would of cause need one with Haskell logo printed upon it. I could not find a place with user-definable textile printing (if that is the right term in english) on plush sloth bears. Greetings, Mads Hi, Here in Brazil we have a forest animal we name 'preguiça' -- literally, lazyness. What better mascot we could have for Haskell? It lives (and sleeps) in trees, and if you see the main picture in wikipedia articles you can easily imagine the tree branch beeing replaced by a lambda: http://en.wikipedia.org/wiki/Sloth http://pt.wikipedia.org/wiki/Bicho-pregui%C3%A7a Best, Maurício ___ 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] Trouble building ArrayRef 0.1.3
Hi When I try to build ArrayRef 0.1.3 I get: Control/Concurrent/LockingBZ.hs:159:54: Ambiguous type variable `e' in the constraint: `Exception e' arising from a use of `throw' at Control/Concurrent/LockingBZ.hs:159:54-60 Probable fix: add a type signature that fixes these type variable(s) I am compiling with: runhaskell Setup.hs build I run Debian Linux with GHC 6.10.1. Anybody has a solution for my problem? Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Trouble building ArrayRef 0.1.3
Hi For anyone who may care, I have googled a workaround. The problem below is similar to the problem mentioned here http://stackoverflow.com/questions/431527/ambiguous-type-variable-error-msg . I wrote: Hi When I try to build ArrayRef 0.1.3 I get: Control/Concurrent/LockingBZ.hs:159:54: Ambiguous type variable `e' in the constraint: `Exception e' arising from a use of `throw' at Control/Concurrent/LockingBZ.hs:159:54-60 Probable fix: add a type signature that fixes these type variable(s) I am compiling with: runhaskell Setup.hs build I run Debian Linux with GHC 6.10.1. Anybody has a solution for my problem? Greetings, Mads Lindstrøm /Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Asking the GHC garbage collector to run
Hi all, Is it possible to ask the GHC garbage collector to run ? Something like a collectAllGarbage :: IO() call. Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Howto debug erros occuring just by linking to non-Haskell libraries
Hi Haskeleers I am trying to track down the cause of an error occurring in the Linux version of wxHaskell. The error occurs before the main function is executed. That is, it occurs if one imports the wxHaskell libraries, and it occurs even if one do not execute any wxHaskell function. Specifically, GLib complains that a initialization-function has not been called. My guess is, that it has something to do with the wxWidgets (and gtk or glib) libraries wxHaskell links to. Some people have suggested it may be an error in the way GHC links with C libraries. But that is all guesswork, I would need something more solid if I were to file GHC bugreport. Here is a simple Haskell program to illustrate the problem: module Main where import Graphics.UI.WX main = print sdfjkl and when we compile and execute this program we get: (process:13986): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use IA__g_type_init() prior to this function (process:13986): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed (process:13986): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use IA__g_type_init() prior to this function (process:13986): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed sdfjkl So even if I do not call any wxHaskell functions, just by linking to wxHaskell, I get these errors. As Jeroen Janssen reports here http://www.mail-archive.com/wxhaskell-us...@lists.sourceforge.net/msg00540.html , he is experiencing the same error, but his wxPython programs works. Thus, wxHaskell (or GHC or ...) must do something different. Could this error be related to the order which external libraries are loaded in? If so, do anybody know how to specify the load order? Can anybody help med with a good approach for debugging this error? Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] WYSIWYG literate programming
Hi, Have you considered using LyX ( http://www.lyx.org/Home ) in stead of TexMacs? I have never tried TexMacs, but newer versions of LyX do seem to have a more modern interface than TexMacs. I do not know have easy LyX is to modify to your needs though. Greetings Mads Lindstrøm Massimiliano Gubinelli wrote: Hi, I would like to advertise TeXmacs (http://www.texmacs.org/) to the Haskell comunity as a possible front-end for literate programming in Haskell (and GHCI interaction). TeXmacs is a system which allows the production of documents featuring high quality typesetting (comparable to TeX) and high level of customizability (a la Emacs). It does not rely on TeX for the typesetting (but can export to Latex, HTML, etc..). It is written in C++ (unfortunately not Haskell) and use Scheme as extension language (specifically Guile). It has been in use for at least 10 years and has plugins for many external applications like Pari, Axiom, Maxima, Octave, R, Yacas, etc... From the webpage: GNU TeXmacs is a free wysiwyw (what you see is what you want) editing platform with special features for scientists. The software aims to provide a unified and user friendly framework for editing structured documents with different types of content (text, graphics, mathematics, interactive content, etc.). The rendering engine uses high-quality typesetting algorithms so as to produce professionally looking documents, which can either be printed out or presented from a laptop. It would be nice to develop a pluging for GHC/GHCI to allow direct literate programming style with high-quality rendering. (If someone want to try before I find the time to do it myself ) Massimiliano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Threads with high CPU usage
Hi Günter Günther Schmidt wrote: Hi, in an application of mine I start a long-running operation in a thread via forkIO so that the UI process doesn't get blocked. It just so happens, that the long-running process also takes the CPU to nearly 100% while it runs. During that time the run-time system does *not* switch back and forth between the UI-process and the long-running task, it seems that the UI process only gets woken up *after* the high CPU thread finishes completely. To the effect of course that it makes no difference at all to the UIs responsiveness whether I use forkIO or not. The long running process is pretty atomic, it's a single query to the database which takes up to a minute to complete so I don't see a chance to squeeze a mainIteration in there. It could be the database library, as it may use unsafe foreign calls. Unsafe foreign calls blocks all other threads, even if you compile with the -threaded option. See http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#4 . I cannot claim to know how all Haskell database libraries are implemented, but at least some of them use unsafe foreign calls. So which database library is you using? What can I do? If the problem has to do with unsafe foreign calls, then you can implement the database calls in a separate process. Not the easiest options, but I can think of no other. Günther /Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Threads with high CPU usage
Hi Peter, Peter Verswyvelen wrote: Would forkOS instead of forkIO help in this case? No, according to http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#v%3AforkOS : Using forkOS instead of forkIO makes no difference at all to the scheduling behaviour of the Haskell runtime system. It is a common misconception that you need to use forkOS instead of forkIO to avoid blocking all the Haskell threads when making a foreign call; this isn't the case. To allow foreign calls to be made without blocking all the Haskell threads (with GHC), it is only necessary to use the -threaded option when linking your program, and to make sure the foreign import is not marked unsafe. /Mads On Sun, Dec 21, 2008 at 11:16 PM, Mads Lindstrøm mads_lindstr...@yahoo.dk wrote: Hi Günter Günther Schmidt wrote: Hi, in an application of mine I start a long-running operation in a thread via forkIO so that the UI process doesn't get blocked. It just so happens, that the long-running process also takes the CPU to nearly 100% while it runs. During that time the run-time system does *not* switch back and forth between the UI-process and the long-running task, it seems that the UI process only gets woken up *after* the high CPU thread finishes completely. To the effect of course that it makes no difference at all to the UIs responsiveness whether I use forkIO or not. The long running process is pretty atomic, it's a single query to the database which takes up to a minute to complete so I don't see a chance to squeeze a mainIteration in there. It could be the database library, as it may use unsafe foreign calls. Unsafe foreign calls blocks all other threads, even if you compile with the -threaded option. See http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#4 . I cannot claim to know how all Haskell database libraries are implemented, but at least some of them use unsafe foreign calls. So which database library is you using? What can I do? If the problem has to do with unsafe foreign calls, then you can implement the database calls in a separate process. Not the easiest options, but I can think of no other. Günther /Mads Lindstrøm ___ 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] Re: Threads with high CPU usage
Hi Günther, Hi Mads, I'm using HDBC with sqlite3 Looking at http://software.complete.org/software/repositories/entry/hdbc-sqlite3/Database/HDBC/Sqlite3/Connection.hs and http://software.complete.org/software/repositories/entry/hdbc-sqlite3/Database/HDBC/Sqlite3/Statement.hsc you can see that HDBC-sqlite's foreign calls are indeed marked unsafe. /Mads Günther ___ 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] package question/problem
Hi, Galchin, Vasili wrote: Hi Duncan, I was under the impression that HDBC doesn't support myqsl?? You can connect HDBC to MySQL using the HDBC-ODBC backend, see http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-odbc. Greetings, Mads Lindstrøm Regards, Vasili On Sat, Oct 18, 2008 at 6:36 PM, Duncan Coutts [EMAIL PROTECTED] wrote: On Fri, 2008-10-17 at 18:23 -0500, Galchin, Vasili wrote: Hello, I am trying to cabal install HSQL. I am using ghc 6.8.2. The simple answer is that the package is unmaintained and has not been updated to work with ghc 6.8.x. You can either use HDBC instead or fix HSQL by applying one of the patches floating around or fix it by following Bertram or Marc's advice. (Note that ghc-pkg hide/expose is a red herring) Duncan ___ 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] Re: Hmm, what license to use?
Hi Gour wrote: Don == Don Stewart [EMAIL PROTECTED] writes: Don * Only a small percent of Haskell libarires are LGPL, and Don nothing for which we don't have workarounds (e.g. HDBC vs Don galois-sqlite3 vs takusen). Hmm, Gtk2Hs wxhaskell - major GUI libs... wxHaskell uses a modified LGPL license (wxWidgets license). One that allows static linking. See http://www.haskell.org/haskellwiki/WxHaskell/License . From the description of the wxWidgets license http://www.wxwidgets.org/about/newlicen.htm : The wxWindows Licence is essentially the L-GPL (Library General Public Licence), with an exception stating that derived works in binary form may be distributed on the user's own terms. This is a solution that satisfies those who wish to produce GPL'ed software using wxWidgets, and also those producing proprietary software. Greetins, Mads Lindstrøm Sincerely, Gour ___ 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] Line noise
Andrew Coppin wrote: Idiomatic Haskell seems to consist *only* of single-letter variable names. When did you last see a pattern like (customer:customers)? No, it'd be (c:cs), which isn't very self-documenting. Ditto for type variables by the way. (Map k v, anyone?) It also seems to be Haskell convention to use a as a type variable; personally I always use x. I guess that's the algebra in my blood or something... The more abstract (generic) thing gets, the less likely you will be able to find a telling name. And if you cannot find a telling name, you can just as well make it short. And as Haskell is more abstract, we get more short identifiers. E.g. in your earlier sorting function: qsort (x:xs) = ... what would you propose to call the elements? Yes, if it sorted customers, you call 'em (customer:customers). But you have made a very abstract sorting function, which sorts a lot besides customers. And then you are bound to end up with a non-telling name. However, I will grant you that Map k v, could have used longer type variables. But we are not alone with using one letter type variable names http://java.sun.com/javase/6/docs/api/java/util/HashMap.html . And frankly, in this specific case, I think most programmers (Haskell or non-Haskell) will be able to guess what k and v means, when they are standing right after Map. Greetings, Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] MetaHDBC paper
Hi all, In May I started a Haskell-cafe discussions[1], where I proposed using Template Haskell to do type-safe database access. The idea got well received and turned into the MetaHDBC library[2]. Concurrently with development I also wrote a paper describing MetaHDBC. I have never writing a paper before, and I therefore tried to imitate the best by following Simon PJ's slides and video about writing papers in [3]. A draft of the paper can be found here [4]. Your opportunity to influence the paper is large, as my limited paper-writing experience means I have little preconception about what a good paper looks like. I would especially like comments about the overall quality of the paper, can it be called scientific and comments about anything I could do to improve the paper. And remember, if commenting, honest is better than polite. Greetings, Mads Lindstrøm [1] http://www.nabble.com/Using-Template-Haskell-to-make-type-safe-database-access-td17027286.html [2] http://www.haskell.org/haskellwiki/MetaHDBC [3] http://research.microsoft.com/~simonpj/papers/giving-a-talk/giving-a-talk.htm [4] http://lindstroem.files.wordpress.com/2008/09/metahdbc.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a question about Database.HDBC.ODBC
Hi, Changying Li wrote: I want to use hdbc to connect my mysql test db. so I set up my /etc/odbcinst.ini : [MySQL] Description = ODBC Driver for MySQL Driver = /usr/lib/libmyodbc.so Setup = /usr/lib/libodbcmyS.so FileUsage = 1 and /etc/odbc.ini: [test] Description = MySQL database test Driver = MySQL Server = localhost Database= test Port= 3306 User= root Socket = /tmp/mysql.sock Option = Stmt= user [EMAIL PROTECTED] must use password to connect mysql. other users needn't. I connect db like this: Prelude Database.HDBC.ODBC Database.HDBC handleSqlError (connectODBC DSN=test) *** Exception: user error (SQL error: SqlError {seState = [\HY000\], seNativeError = -1, seErrorMsg = connectODBC/sqlDriverConnect: [\1045: [unixODBC][MySQL][ODBC 3.51 Driver]Access denied for user 'chylli'@'localhost' (using password: NO)\]}) Prelude Database.HDBC.ODBC Database.HDBC handleSqlError (connectODBC DSN=test;UID=chylli) Prelude Database.HDBC.ODBC Database.HDBC in another term: mysql show processlist; ++-+---+--+-+--+---+--+ | Id | User| Host | db | Command | Time | State | Info | ++-+---+--+-+--+---+--+ | 31 | chylli¶è | localhost | test | Sleep | 1483 | | NULL | | 43 | root| localhost | test | Sleep | 116 | | NULL | my question is: 1. why not HDBC.ODBC use configuration in /etc/odbc.ini ? if is use, then connectODBC DSN=test should use root as user without password and it should succeed. Are you sure it is a HDBC and not a ODBC-library problem? It seems that you use unixODBC and can then try the command: isql test which will connect though unixODBC without involving HDBC. If you still have the same problems, then it must be unrelated to HDBC. 2. when using UID=chylli, why the user in 'show processlist' is not chylli but 'chylli¶è' ? if it use account 'chylli', that connection should fail. but in fact it succeed !!! Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Cleaning up the Debian act (report from the trenches)
Hi Ketil Malde wrote: I've had an interested user, who tried to get one of my programs to run on a Debian machine - running Debian Etch, released a couple of months ago. Here are some of the hurdles stumbled upon in the process: Debian Etch were released in April 8th, 2007. 16 months ago. Hardly a copule of months ago. See http://www.debian.org/News/2007/20070408.en.html . Sure, there have been updates since then, but they are mainly concerned with security and drivers for new hardware. 1. Etch comes with ghc-6.6, and that didn't work with my .cabal file. 2. ghc-6.8.3, presumably the binary snapshots, didn't work, neither in i386 nor in x86_64 incarnation. 3. ghc 6.8.1-i386 appears to work, but some of the dependencies failed to compile (tagsoup, in this case) 4. A precompiled (by me), statically linked binary refuses to run with a message of FATAL: kernel too old. Granted, not all of this is our fault, but it won't help users to start charging the windmills of Debian conservativism. We really need to make this process smoother, and ideally, provide debs for Etch backports. I'm not sure how to go about any of this, beyond debianizing my own packages. But that's why I'm telling you. :-) There are several options: 1) Use the testing or unstable branch of Debian. They got newer packages. Testing (aka. Lenny) has GHC 6.8.2 http://packages.debian.org/lenny/ghc6 . 2) Compile GHC yourself. You can even compile and install GHC (and most Haskell software) on a dedicated user account. In this way you avoid messing up you Debian installation if something goes wrong. 3) If testing/unstable is too risky, then use backports to stable. See http://www.backports.org/dokuwiki/doku.php . Unfortunately, they do not have GHC in their repository. Maybe somebody else has. 4) Wait for the next release of Debian. It should not be too far into the future, as the next release is now frozon http://www.debian.org/News/weekly/2008/08/ . But with a project like Debian that releases when ready, not on a deadline, you never quite know when the next release will be there. -k Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Using Template Haskell to make type-safe database access
Hi Bjorn Bringert wrote: Mads: Preparing the statement and asking the DB about the type at compile is a great idea! I've never thought of that. Please consider completing this and packaging it as a library. Thanks for the nice remark. And I will begin completing the idea, as soon I have packaged up and wrote a little tutorial about my other project (SybWidget). I already started that about three weeks ago, so it should be finished soon. Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Using Template Haskell to make type-safe database access
Hi Wouter, Wouter Swierstra wrote: Nice! I have to admit, it's much nicer than I expected it to be. Just out of curiousity, what happens when you write: selectTupleList :: Connection - IO [Integer] instead of selectTupleList :: Connection - IO [(Integer, String, String)] What kind of error message do you get? More specifically, is this error caught statically or dynamically. The type annotation in UseSqlExpr.hs was just for the reader. The compiler can infer the types completely. Thus when I make the suggested change I get a compile time error. It looks like this: UseSqlExpr.hs:27:6: Couldn't match expected type `Integer' against inferred type `(Integer, String, String)' Expected type: IO [Integer] Inferred type: IO [(Integer, String, String)] In the expression: (return $ (map (\ [x0[a2ZY], x1[a2ZZ], x2[a300]] - (readInteger x0[a2ZY], readString x1[a2ZZ], readString x2[a300])) rows[a2ZX])) In the expression: do rows[a2ZX] - fetchRows dsn[a2ZW] ['S', 'E', 'L', 'E', 'C', 'T', ' ', 'u', 's', 'e', 'r', '_', 'i', 'd', ',', ' ', 'u', 's', 'e', 'r', '_', 'n', 'a', 'm', 'e', ',', ' ', 'u', 's', 'e', 'r', '_', 'r', 'e', 'a', 'l', '_', 'n', 'a', 'm', 'e', ' ', 'F', 'R', 'O', 'M', ' ', 'u', 's', 'e', 'r', ';'] (return $ (map (\ [x0[a2ZY], x1[a2ZZ], x2[a300]] - (readInteger x0[a2ZY], readString x1[a2ZZ], readString x2[a300])) rows[a2ZX])) make: *** [all] Fejl 1 The only other limitation I can think of, would be in the situation where you don't have compile-time access to the database, e.g. developing software for a client with a database that can only be accessed from their intranet. I have no idea how much of a limitation that is. True, but this limitation is only relevant when you do not have access to the production database or a database with identical metadata. How often do people develop like that? How are they testing? I have a hard time picturing a setup without a test database with identical metadata to the production database. Perhaps I should explain my own thoughts on the subject a bit better. I got interested in this problem because I think it makes a nice example of dependent types in the real world - you really want to But won't you end up implementing all the functionality of an SQL parser? While possible, it does seem like a huge job. With a TH solution you will safe a lot of work. Yes - but parsing the result of an SQL describe statement is pretty easy. ok. A library that will be a lot more complex to learn than what I am proposing (assuming the developer already knows SQL). Hmm. This is a rather sticky point. One might also argue that Haskell developers have to learn SQL to use the solution you propose. I'm not particularly convinced. Both approaches have their merits I think. Yes. I was _not_ making what you could call a strong argument. I was assuming that most (Haskell) developers knew SQL anyway. I have no data to back it up. Just my gut feeling. To be fair I should mention a couple of drawbacks with the TH-based approach. While SQL got static typing, it is not really as powerful as it could be. For example if you do select sum(...) from ... the type system will tell you that a set of values are returned. In reality this set will never have more than one member. Your proposal would be able to return a Float in stead of a [Float]. Another advantage your proposal (and disadvantage of the TH based one) would be that it can abstract over variances in different database implementation. That is, you could translate to SQL depending on SQL backend. This would be really nice. But I guess it would also be a big task. Anyhow - nice work! Have you asked Bjorn Bringert what he thinks? He's a really clever and approachable guy - and he knows a lot more about interfacing with databases than I do. Kind regards, Wouter /Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Using Template Haskell to make type-safe database access
Hi Wouter Wouter Swierstra wrote: Here's a concrete example. Suppose you have a query q that, when performed, will return a table storing integers. I can see how you can ask the SQL server for the type of the query, parse the response, and compute the Haskell type [Int]. I'm not sure how to sum the integers returned by the query *in Haskell* (I know SQL can sum numbers too, but this is a simple example). What would happen when you apply Haskell's sum function to the result of the query? Does TH do enough compile time execution to see that the result is well-typed? Not only pictures, but also code can say more than a thousands words. Therefore, I have been implementing a proof of concept. The code is attached in two files - SqlExpr.hs and UseSqlExpr.hs. The former contains two SQL expressions + Haskell code. The latter is the Template Haskell (TH) code that makes it possible to type-safely access the database. UseSqlExpr.hs is a lot easier to understand than SqlExpr.hs. So if you only have time to look at one of them, look at UseSqlExpr.hs. The reason SqlExpr.hs is harder to understand is not just because it is longer, but also because TH is difficult. At least TH was difficult for me. It might just be because I have never worked with anything like TH before (have not learned Lisp yet :( ). It remained me of going from OO to FP. You have to change how you think. Your example of fetching a [Int] and take there sum is shown in UseSqlExpr.hs. The output from running UseSqlExpr.hs (on my computer) is: [1,2,3,4] [(1,WikiSysop,),(2,Mads,Mads Lindstr\195\184m),(3,Madstest,Bob),(4,Test2,Test 2)] Sum is: 10 Having the SQL server compute types for you does have other drawbacks, I think. For example, suppose your query projects out a field that does not exist. An error like that will only get caught once you ask the server for the type of your SQL expression. If you keep track of the types in Haskell, you can catch these errors earlier; Haskell's type system can pinpoint which part of the query is accessing the wrong field. I feel that if you really care about the type of your queries, you should guarantee type correctness by construction, rather than check it as an afterthought. But the SQL database will output a meaningful error message. And TH is asking the server at compile time. Thus, the user can also get the error message at compile time. TH is used as part of the compilation process. I _think_ it would be fair to say it occurs concurrently with type checking (or maybe intermittently). Thus the user do not get the error message later than with a type based approach. If you, with the currently implemented proof of concept, name a non-existing field in your SQL you get: compile time output UseSqlExpr.hs:22:6: Exception when trying to run compile-time code: Exception when trying executing prepared statement : execute execute: [1054: [MySQL][ODBC 3.51 Driver][mysqld-5.0.32-Debian_7etch5-log]Unknown column 'duser_id' in 'field list'] Code: compileSql DSN=MySQL_DSN;USER=StocksDaemon; SELECT duser_id FROM user; In the expression: $[splice](compileSql DSN=MySQL_DSN;USER=StocksDaemon; SELECT duser_id FROM user;) c In the definition of `selectIntegerList': selectIntegerList c = $[splice](compileSql DSN=MySQL_DSN;USER=StocksDaemon; SELECT duser_id FROM user;) c make: *** [all] Fejl 1 /compile time output ok, there is some noise. But at the end of line three it says Unknown column 'duser_id'. Also with a little more work I could properly improve the output. Perhaps I should explain my own thoughts on the subject a bit better. I got interested in this problem because I think it makes a nice example of dependent types in the real world - you really want to But won't you end up implementing all the functionality of an SQL parser? While possible, it does seem like a huge job. With a TH solution you will safe a lot of work. Also, almost every software developer already knows SQL. And the few that do not, will likely have to learn SQL if they are to do substantial work with databases. Whereas if you implement a type based solution a developer will have to learn how to use your library. A library that will be a lot more complex to learn than what I am proposing (assuming the developer already knows SQL). compute the *type* of a table based on the *value* of an SQL DESCRIBE. Nicolas Oury and I have written a draft paper describing some of our ideas: http://www.cs.nott.ac.uk/~wss/Publications/ThePowerOfPi.pdf I have not read the paper yet, as I have been busy coding. Plus I have a day job. But I did read the first couple of pages and so far the paper seems very interesting. When time permits I will read the rest. Hopefully this weekend. Any
Re: [Haskell-cafe] Using Template Haskell to make type-safe database access
Hi, Wouter Swierstra wrote: Hi Mads, I was wondering if anybody had experimented with using Template Haskell (TH) and ordinary SQL to make type-safe database access? I know HaskellDB, for example, does something quite similar. There's a preprocessor that generates a Haskell file with a Haskell representation of the types of the database's tables. You could of course replace this with a TH function. There are two very nice papers about the design of HaskellDB: http://research.microsoft.com/users/daan/download/papers/dsec.ps http://haskelldb.sourceforge.net/haskelldb.pdf Thanks. I think there may a bit of problem with the approach you suggest: as the type returned by the query is computed by the SQL server (if I understand you correctly), it's very hard to do anything with the result of the query - the Haskell compiler has no idea what type the result has, so you can't do anything with it. I think it makes much more sense to bookkeep type information on the Haskell side. But you can ask the SQL server for the type of the result. In the TH function you could: 1) Call ODBC function SQLPrepare (http://msdn.microsoft.com/en-us/library/ms710926(VS.85).aspx) . This just prepares a statement. It do _not_ execute it. 2) Call ODBC function SQLNumParams (http://msdn.microsoft.com/en-us/library/ms715409(VS.85).aspx) . This returns the number of parameters. 3) Call ODBC function SQLDescribeParam (http://msdn.microsoft.com/en-us/library/ms710188(VS.85).aspx) for each parameter to get type information. I imagine that this would all be done at compile time by the TH function. At run time we would call SQLPrepare (again) and SQLExecute. We obtained type information at compile time, so it should all be quite type safe. HDBC almost supports this with describeResult (http://software.complete.org/static/hdbc/doc/Database-HDBC.html#v% 3AdescribeResult ) and prepare (http://software.complete.org/static/hdbc/doc/Database-HDBC.html#v% 3Aprepare ), except that we need to execute a prepared SQL statement before calling describeResult (see link to describeResult). Calling functions that could potentially change data at compile time seems like a bad idea. For some people, maybe even a deal breaker. HSQL has similar functions. But I have not got it to work yet, so that I could test it. We would of cause need to map the type information returned by SQLDescribeParam to Haskell data types. But is seems to me that HSQL and HDBC can already do that. Of cause it all requires that the database have identical metadata at run and compile -time. Either using the same database or a copy. Though one should note that HaskellDB has the same disadvantage. Actually it do not seem much of a disadvantage it all, as most code accessing SQL databases depends on database metadata anyway. Greetings, Mads Lindstrøm Hope this helps, Wouter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Using Template Haskell to make type-safe database access
Hi, I was wondering if anybody had experimented with using Template Haskell (TH) and ordinary SQL to make type-safe database access? To clarify what I am thinking about I will sketch how it could be done. The TH function should take two inputs. SQL (as a string) and a database source name (DSN). It should return an IO action as output. The TH-function should: 1. Connect to the database using the DSN 2. Ask the database which types will be returned from the expression 3. Build an IO action which can be used to execute the SQL at run-time. The action could return the result as a (lazy) list. Due to step two we can make the returned values type-safe. Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Replacing RDMS - global lock and STM preventing retrying?
Hi Marc Weber wrote: What would be the right way to go to replace RDBMS (postgres/ mysql) etc using haskell only for small to medium sized (web)applications? I guess one way to go is using STM. But what happens if you have some tables each row represented as TVar and you'd like to do a full backup? Some occasionally occuring updates on single rows will make the atomic action get all rows and write them to disk retry again and again? Is there a way to make the update action retry in this case? And then you can implement something like: Try it 20 times, if the aciton doesn't succeed aquire global lock ! Wow. Has anyone already implemented such a RDBMS replacement? Have you looked at http://happs.org/ ? Their HappS-State seems somewhat similar to what you are proposing. Anyone interested in working on this? Marc Weber Another question is why do you want to we replace RDBMS-es? Greetings, Mads Lindstrøm One solution I came up within minutes :) I love haskell. You write it down fix error and it works :) Would you prefer another way to solve this? --packages: containers, binary, stm, mtl, random module Main where import System.IO.Unsafe import Random import Control.Concurrent import Control.Monad import Control.Concurrent.STM import Control.Monad.Trans -- running count of actions. if set to -1 a transaction has aquired global lock globalLock = unsafePerformIO $ newTVarIO (0::Int) modifyTVar tvar f = do v - readTVar tvar writeTVar tvar $ f v -- of course this should be in it's own monad to force using this function -- myAtomically: aquires global lock -- of course I don't need 5 atomically calls, but this way an action will not be retried if only the global count changes myAtomically aquireGlobalLock stmAction = if aquireGlobalLock then do atomically $ do runningCount - readTVar globalLock when (runningCount /= 0) retry writeTVar globalLock (negate 1) -- other actions should be retrying atomically $ do stmAction writeTVar globalLock 0 else do atomically $ do runningCount - readTVar globalLock when (runningCount == (negate 1)) retry modifyTVar globalLock (+1) atomically stmAction atomically $ modifyTVar globalLock (\x - x -1) -- log utility printing start / stop of an action stsp :: (MonadIO m) = String - m r - m r stsp msg act = do liftIO $ putStrLn $ start: ++ msg r - act liftIO $ putStrLn $ stop: ++ msg return r data Table rec = Table { table :: [TVar rec] } newTable rowcount = liftM Table $ mapM newTVarIO [(1::Int)..rowcount] dumpTable fn t = do dat - myAtomically True $ mapM readTVar $ table t writeFile fn $ show dat disturb t@(Table (row:_)) = do stsp disturbing $ do v - randomRIO (0,100) myAtomically False $ writeTVar row v threadDelay 100 disturb t -- loop main = do stsp application $ do table - newTable 10 forkIO $ disturb table stsp dumping $ dumpTable dump table ___ 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] Replacing RDMS - why I want this retrying?
Hi, Marc Weber wrote: Another question is why do you want to we replace RDBMS-es? a) Speed. A simple HAppS state benchmark shows that inserting records can be 10 times faster than MySQL don't know wether its' because switching processes, parsing SQL queries ? You could try using prepared statements, see http://dev.mysql.com/tech-resources/articles/4.1/prepared-statements.html . According to the article, this will save the parsing overhead but not the prepare-plan overhead. However, the article is about MySQL 4.1, so maybe newer versions of MySQL may only need to prepare the execution plan once. PostgreSQL seems to supports preparing both parse result and the prepare-plan result (see http://www.postgresql.org/docs/8.1/interactive/sql-prepare.html ). /Mads Lindstrøm b) Type safety. HaskellDB is nice.. But it's limiting because you can't optimize queries very well. Having something (maybe completeley in mem as HAppS proposes it) beeing as easy as Data.Map would be nice. Sincerly Marc Weber ___ 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] MonadMemory class
Hi Ariel J. Birnbaum wrote: Two questions came to mind while thinking of memory references in Haskell: 1. Is there a standard equivalent of the following: class (Monad m) = MonadMemory m r | m - r where new :: a - m (r a) read :: r a - m a write :: r a - a - m () I do not think you can call it standard, but TypeCompose http://hackage.haskell.org/cgi-bin/hackage-scripts/package/TypeCompose-0.5 do implement Data.RefMonad, which does what you are describing. Greetings, Mads Lindstrøm What kind of axioms should an instance of this class satisfy? 2. How would a pure instance of this class look like (obvious unsafePerformIO-based solutions aside)? Is it even possible in pure Haskell? Thanks much! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Doubting Haskell
Hi Alan I can help but feeling curious. Did some of the answers actually help you? Are you still as doubtful about Haskell as when you wrote your email? Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell wiki is searched by google.
Richard Kelsall wrote: Daniil Elovkov wrote: Hello I remember there was a problem with haskell wiki pages not being indexed and searched. Now it seems to work perfectly. Actually typing 'monomorphism restriction' in google I see the appropriate wiki page as the first result. I must have missed the moment when it was fixed. Just sharing my observations. Thanks. Hello Daniil, I think I may have started that discussion here : http://www.haskell.org/pipermail/haskell-cafe/2007-November/035127.html but sadly a search for mdo in the Search box at the top of this page http://haskell.org/haskellwiki/Haskell still gives no results. I suspect something needs adjusting in the configuration of MediaWiki for the haskellwiki. Not MediaWiki, but the underlying database. If HaskellWiki uses MySql ft_min_word_len needs to be set to something smaller than four. See http://dev.mysql.com/doc/refman/5.0/en/fulltext-fine-tuning.html . After doing this the indexes needs to be rebuild. Greetings, Mads Lindstrøm Richard. ___ 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] Simple network client
Hi Timo B. Hübel wrote: Hello, I am using the very simple interactTCP example from [1] to play around with Haskell network programming but I just can't get a simple client for that example to work (it works like a charm with my telnet client, as described in the article). This is what I am trying to do with the client: main = withSocketsDo $ do hdl - connectTo localhost (PortNumber 1234) hSetBuffering hdl NoBuffering hPutStr hdl test message res - hGetContents hdl putStrLn (show res) If you replace the `putStrLn (show res)` with this: mapM_ (\x - putStr (show x) hFlush stdout) res it works. I _think_ the problem is that `putStrLn (show res)` will wait until it has read all of res. But as the client do not know when the server is finished sending data, the client will wait forever. Greetings, Mads Lindstrøm The server looks like this: interactTCP :: Int - (String - IO String) - IO () interactTCP port f = withSocketsDo $ do servSock - listenOn $ PortNumber (fromIntegral port) waitLoop f servSock waitLoop f servSock = do bracket (fmap (\(h,_,_)-h) $ accept servSock) hClose (\h - do hSetBuffering h NoBuffering hGetContents h = f = hPutStr h) waitLoop f servSock main = interactTCP 1234 (return . map toUpper) But is seems as some deadlocking occurs. Both programs just hang around doing nothing. By inserting some debug output I was able to make sure that the client successfully connects, but the data interchange just does not start. Because the whole thing works using telnet, I suspect that I am doing something fundamentally wrong in the client ... Any hints are greatly appreciated. Thanks, Timo [1] http://stephan.walter.name/blog/computers/programming/haskell/interacttcp.html ___ 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] US Homeland Security program language security risks
Hi, Andrew Coppin wrote: Galchin Vasili wrote: Hello, https://buildsecurityin.us-cert.gov/daisy/bsi/articles/knowledge/coding/295.html I stumbled across this page. It seems that Haskell and other strongly typed functional languages like Ml/OCaml will fare much, much better, e.g. buffer overrun. Thoughts . comments. Human kind has yet to design a programming language which eliminates all possible bugs. ;-) And we never will. See http://en.wikipedia.org/wiki/Halting_problem . Greetings, Mads ___ 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] Searched for mdo on haskell.org. Found nothing.
Hi All Richard Kelsall wrote: I was reading the 'Problems with do notation' thread and Thomas Schilling suggested reading about mdo. Not knowing mdo I thought that sounds interesting and went to http://haskell.org/ which redirects you to http://haskell.org/haskellwiki/Haskell and gives you a search box. Typing mdo and clicking the Search button gives Showing below 0 results starting with #1. No page title matches No page text matches Note: unsuccessful searches are often caused by searching for common words like have and from, which are not indexed, or by specifying more than one search term (only pages containing all of the search terms will appear in the result). Maybe mdo is too common to be indexed? So I went to Google and searched for Haskell mdo and top of the list is this page : http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html which is Chapter 8. GHC Language Features 8.3. Syntactic extensions which describes mdo. Did I do something wrong when searching haskell.org? Properly not. I think the problem is that haskell.org do not index words, that have length = 3. MediaWiki (which I think haskell.org uses) do not by default index short words (length = 3 or length = 4 - can't remember which). If you search for yhc you also get zero results, which does not make sense either. Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] expanded standard lib
Brandon S. Allbery KF8NH wrote: On Nov 19, 2007, at 15:13 , Neil Mitchell wrote: - The packages seem to be of quite variable quality. Some are excellent, some are rather poor (or just not maintained any more). The problem is that only one person gets to comment on the quality of a library, the author, who is about the least objective person. The ability to vote on packages might be interesting here. If there's 4 HTML libraries and one of them gets lots of votes, it's probably the one to look at first. It occurred to me that the voting could be implicit. That is, if 10 libraries/programs use library X, then library X gets 10 votes. Kind of like Google PageRank for libraries. Greetings, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] SYB3 codebase
Hi Ian Ian Lynagh: On Fri, Oct 19, 2007 at 07:59:37PM +0200, Mads Lindstrøm wrote: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/syb-with-class-0.3 (hereafter know as HappS-SYB3). HappS-SYB3 is based on the SYB3 code you mention, but the code has been changed quite a bit compared to using the Shelarcy patch. So it will properly require some more work. Can you explain what you mean by require some more work please? As far as I can remember the API provided by the code has not changed, the changes have only been improvements to the internal code. From the original SYB3: gfoldl :: ctx () - (forall a b. Data ctx a = c (a - b) - a - c b) - (forall g. g - c g) - a - c a From Happs-SYB3: gfoldl :: Proxy ctx - (forall b c. Data ctx b = w (b - c) - b - w c) - (forall g. g - w g) - a - w a looking at the first argument you will see a slight difference. Also the original SYB3 contains the function gfoldlAccum, which the HappS version do not contain. There are other differences too. I have not been able to find any documentation for HappS-SYB3. The SYB3 paper describes how to use it, but other than that there is no documentation. Of course, if anyone wanted to write some other docs then that would be great! Yes, that would be great. Thus I have no idea of his position on my usage of HappS-SYB3. I'm not sure exactly what you're asking. syb-with-class is BSD3-licenced, and anyone is free to use it for whatever they want within the terms of that licence. I was not referring to the license. To be earnest I can see that I was not clear about what I was referring to :( I was thinking about the level of support. Was this just a library to support HappS, and people could use it but there would be no help if they ran into problems. Or would it receive the same support as the HappS project gives to there users. Thanks Ian Greetings, Mads ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Transformation sequence
Hi Alfonso Andrew Alfonso Acosta wrote: How about using a state monad as a logger? I am not a monad-expect, so I may be wrong, but wouldn't a writer monad be more appropriate? After all, it is just used for logging the intermediate results, not to keep read/write state. In other words, we just need to read the logged values when the transformation has occurred, not while it is occurring. Greetings, Mads Lindstrøm You store the transformation sequence in the state while processing the tree, then you simply retrieve the state and print it out. Your transformation function should change to import Control.Monad.State data Log = ... -- to be defined type LogMonad a = State Log a transform :: LogMonad Expression - LogMonad [Expression] On 10/20/07, Andrew Coppin [EMAIL PROTECTED] wrote: I'm writing some code where I take an expression tree and transform it into another equivilent one. Now it's moderately easy to write the code that does the transformation. But what I *really* want is to print out the transformation *sequence*. This appears to be much more awkward. What I have is a function like this: transform :: Expression - [Expression] The trouble is, if you want to apply the transformation recursively, things get very messy. Oh, it *works* and everything. It's just really messy and verbose. In Haskell, this is usually a sign that you want to start applying some ingenious trickery... but I'm having an ingeniety failure here. Suppose, for example, that in one case you want to recursively transform two subexpressions. I end up writing something like transform (...sub1...sub2...) = let sub1s = transform sub1 sub2s = transform sub2 in map (\sub1' - put sub1' back into main expression) sub1s ++ map (\sub2' - put sub2' back into main expression) sub2s After you've typed that a few times, it becomes *very* boring! But I can't think of a clean way to abstract it. :-( It's *almost* like you want to use the list monad: transform (...sub1...sub2...) = do sub1' - transform sub1 sub2' - transform sub2 return (put sub1' and sub2' back into the main expression) Except that that doesn't quite work properly. As shown above, I actually want to go through all the transformation steps for the first branch, and *then* all the steps for the second branch. Any hints? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] SYB3 codebase
Hi Greg I forgot to say, that I did not stop using the Shelarcy patch because there was something wrong with the code. On the contrary it served me well for long time. The reason for using the HappS-version was that I wanted something that was Cabalized and that I thought it was good to minimize the number of SYB3's floating around. Greetings, Mads Lindstrøm Haskellians, Does anyone know the status of SYB3 codebase? It appears that FreshLib critically depends on it, but the code downloadable from http://homepages.cwi.nl/~ralf/syb3/code.html dies in make test on the first test with lgmaclt:~/work/src/projex/biosimilarity/HS1/Process/haskell/SYB3 lgm$ make test make test1 stem=geq1 ghci -fglasgow-exts -fallow-overlapping-instances -fallow-undecidable-instances -v0 geq1.hs Main.in geq1.out geq1.hs:27:34: Inferred type is less polymorphic than expected Quantified type variable `a1' escapes Probable cause: `geq'' is applied to too few arguments In the first argument of `gzipWithQ', namely `geq'' In the first argument of `and', namely `(gzipWithQ geq' x y)' interactive:1:0: Not in scope: `main' diff -b geq1.out geq1.ref 0a1,4 True False False True make[1]: *** [test1] Error 1 make: *** [test] Error 2 lgmaclt:~/work/src/projex/biosimilarity/HS1/Process/haskell/SYB3 lgm$ Is there a newer version of this codebase? Has this functionality been folded into mainline Haskell tree somewhere? Best wishes, --greg -- L.G. Meredith Managing Partner Biosimilarity LLC 505 N 72nd St Seattle, WA 98103 +1 206.650.3740 http://biosimilarity.blogspot.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] SYB3 codebase
Hi Greg To the best of my knowledge it is not maintained anymore :( If you want to use it, you should properly make use of this patch: http://autoforms.svn.sourceforge.net/viewvc/autoforms/trunk/AForms/SYB3_Shelarcy.diff?revision=234view=markuppathrev=400 The patch was made by Kido Takahiro (aka. Shelarcy). The patch makes SYB3 compile with GHC 6.6 and GHC 6.8. However, I do not _think_ anybody else currently uses SYB3 with this patch. As far as I know, I was the only user and I have recently migrated to http://hackage.haskell.org/cgi-bin/hackage-scripts/package/syb-with-class-0.3 (hereafter know as HappS-SYB3). HappS-SYB3 is based on the SYB3 code you mention, but the code has been changed quite a bit compared to using the Shelarcy patch. So it will properly require some more work. On the other hand, I think the http://hackage.haskell.org/cgi-bin/hackage-scripts/package/syb-with-class-0.3 version is better maintained, as it is used in HappS project. I have not been able to find any documentation for HappS-SYB3. I _think_ it is because the HappS folks main focus is to use it to support the HappS project. I've have emailed the HappS maintainer about my usage of HappS-SYB3, but I am yet to receive an answer. Thus I have no idea of his position on my usage of HappS-SYB3. If I was you, I would use the Shelarcy patch first, as it will require less work. When everything is working I would migrate to HappS-SYB3, as they have an interest in maintaining their version. Greetings, Mads Lindstrøm P.s. if you decide using the Shelarcy patch then apply it with: patch -u -dSYB3 SYB3_Shelarcy.diff Greg Meredith: Haskellians, Does anyone know the status of SYB3 codebase? It appears that FreshLib critically depends on it, but the code downloadable from http://homepages.cwi.nl/~ralf/syb3/code.html dies in make test on the first test with lgmaclt:~/work/src/projex/biosimilarity/HS1/Process/haskell/SYB3 lgm$ make test make test1 stem=geq1 ghci -fglasgow-exts -fallow-overlapping-instances -fallow-undecidable-instances -v0 geq1.hs Main.in geq1.out geq1.hs:27:34: Inferred type is less polymorphic than expected Quantified type variable `a1' escapes Probable cause: `geq'' is applied to too few arguments In the first argument of `gzipWithQ', namely `geq'' In the first argument of `and', namely `(gzipWithQ geq' x y)' interactive:1:0: Not in scope: `main' diff -b geq1.out geq1.ref 0a1,4 True False False True make[1]: *** [test1] Error 1 make: *** [test] Error 2 lgmaclt:~/work/src/projex/biosimilarity/HS1/Process/haskell/SYB3 lgm$ Is there a newer version of this codebase? Has this functionality been folded into mainline Haskell tree somewhere? Best wishes, --greg -- L.G. Meredith Managing Partner Biosimilarity LLC 505 N 72nd St Seattle, WA 98103 +1 206.650.3740 http://biosimilarity.blogspot.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] On the verge of ... giving up!
Hi Vimal I didnt want to repeat that mistake, so I made sure I would learn IO in Haskell, which initially turned out to be a disaster, due to the 'Moands' which sounded like 'Go Mads' to me. Then, I set out to learn Monads + Category Theory from a Math perspective. And since I haven't been introduced to abstract math (like Groups, etc.), I found this a little difficult. However I tried my best to understand the tiniest bit and waited for the tiniest spark that would enlighten me. It didn't work out. In my opinion (other may think differently) it is not a good idea to learn IO by starting with trying to grasp the theoretical foundation for monads. In the beginning you should just view the IO monad as Haskell's way of doing imperative IO stuff. When you feel comfortable with Haskell IO, then try to learn a couple of other monads. Then maybe this article http://sigfpe.blogspot.com/2006/05/grok-haskell-monad-transformers.html about monad transformers. It is good because it do not try to explain the implementation details of monad transformers - just how you use them. When you have done all that, then you should be ready for all the details. --snip-- Okay, so you might be wondering as to whats the whole point of this mail? Well, I am almost on the verge of giving up on something I really like to learn, just because I didn't go in the right order! So, I requested my institute to buy Dr. Graham Hutton's book. I would be getting hold of that quite soon, and am willing to start from the beginning. Meanwhile, could anyone suggest if there was anything wrong in my approach to learning Haskell/the other languages? I agree that the learning methodology is something personal and I have to find out what best suits me, but I would like to hear something from you, Haskellers, too. As I wrote above, I think you are trying to understand too many details at once. Also a textbook can sometimes be helpful. But you also have a learning by doing approach, which I personally find very productive. And do not give up yet. Haskell has a lot to offer and I think it is well worth the steep learning curve. Cheers, Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Why I Love Haskell In One Simple Example
Hi John Goerzen On 2005-06-27, Mads Lindstrøm [EMAIL PROTECTED] wrote: Hi John test :: forall a. (Num a) = a test = 2 * 5 + 3 [ snip ] I had newer seen anybody use forall a. in function signatures before, and therefore was curious about its effect. This is probably do to my inexperience regarding Haskell. However, I tried to remove it and wrote this instead: If you omit it, the compiler will decide that test is some arbitrary type (Double, Integer, whatever). While rpnShow, etc. will still work, they will not show you the same thing, since the compiler will have already optimized the expression down to one set type. They show the same thing on my computer, namely 2 5 * 3 + if I do :type test I get (with or without the forall a.): rpnShow :: Num a = SymbolicManip a - String Which compiler or interpreter are you using? hugs -98 :version -- Hugs Version November 2003 I have not tried with ghc(i), as it would not load MissingH.Str. Some problem I will have to look into later. I tried to find documentation about the use of the forall keyword in respect to functions (I do know about it in with respect to existentially quantified types), but with no luck. So, if anybody has some good pointers, please let med know about it. Note that test in this example is not a function. OK, I assumed it was, as I thought all functions started with lower case and all modules, classes, and data/type constructors started with upper case. It does not take any variables as input, but that is still a function in my book (but I could be wrong there. I am no mathematician). -- John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe note that I am not using: test :: a -- this will actually not compile or not giving any type signatur, but using: test :: (Num a) = a /Mads Lindstrøm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to show a variable with show?
Hi module Main where main = do putStr (show (foo 3)) putStr \n putStr (show (foo 7)) putStr \n putStr (show y) foo x = (x + 2) / y where y = 2 * 2 And how do I see functions or variables defined inside of other functions? In example above - y Short answer -- you don't. Haskell is a purely functional langauge and functions can therefore not have side effects. Side effects can only occur in the IO monad (and maybe in some other monads) as shown above in main, which really is a IO monad with type main :: IO(). Therefore you cannot print the value of y to the screen in the middle of the foo function. This may seem like a stupid limitation, but restricting your functions to be pure eliminates a lot of errors. And in my, albeit limited Haskell experience, there is rarely a need to see the value of variables writen inside other funcitons (as shown in your example). If you really need this kind of feedback, then there are some debugging tools here: http://www.haskell.org/libraries/#tracing which may do it for you. However, I have tried none of them and do not really know what they can do. hope it helps, Mads Lindstrøm [EMAIL PROTECTED] Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html ___ 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