[Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-21 Thread Bardur Arantsson

Jeremy Shaw wrote:

Hello,

I think to make progress on this bug we really need a failing test case that
other people can reproduce.

I have hacked up small server that should reproduce the error (using fdWrite
instead of sendfile). And a small C client which is intended to reproduce
the error -- but doesn't.

I have attached both.

The server tries to write a whole lot of 'a' characters to the client. The
client does not consume any of them. This causes the server to block on the
threadWaitWrite.

No matter how I kill the client, threadWaitWrite always wakes up.


Are you running the client and server on different physical machines? If 
so, have you tried simply yanking the connection?


Your client isn't dropping the connection hard -- if you kill the client 
(even with a -9) your OS cleans up any open sockets it has. On 
well-behaved OS'es that cleanup usually involves properly shutting down 
the connection somehow. Different OS'es have different ideas about what 
constitutes properly shutting down the connection -- some simply don't.


My hypothesis is that the PS3 doesn't properly shut down the connection, 
but simply sends a RST (or maybe a FIN) and drops any further packets. 
I'll do a Wireshark dump after posting this to see if I can see what 
it's doing at the TCP level -- I'm not optimistic about seeing the exact 
moment when the leak occurs, but maybe the general pattern can yield 
some useful ideas.


I have no idea how to test this without using an actual PS3.

 So, we

need to figure out exactly what the PS3 is doing differently that causes
threadWaitWrite to not wakeup..


Does it matter? I can reproduce this reliably within a few minutes of 
testing.


Note that this doesn't happen *every* time the PS3 disconnects and 
reconnects, it just happens some of the time. It's enough to eat up 
MAX_FDs file descriptors in a few hours of playing media normally. If I 
do a lot of seeking (forces a disconnect+reconnect) through the movie, 
at least one file descriptor usually leaks within a few minutes.



If we don't know why it is failing, then I
don't think we can properly fix it.


I'm more pragmatic: If, after applying a fix, I cannot reproduce this 
problem within a few hours (or so) or running my media server, I'd say 
it's fixed. As long as the modifications to the sendfile library don't 
change its behavior in other ways, I don't see the problem.


P.S. Does anyone else out there have a PS3 to test with?

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


[Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-21 Thread Bardur Arantsson

Taru Karttunen wrote:

Excerpts from Bardur Arantsson's message of Wed Feb 17 21:27:07 +0200 2010:
For sendfile, a timeout of 1 second would probably be fine. The *ONLY* 
purpose of threadWaitWrite in the sendfile code is to avoid busy-waiting 
on EAGAIN from the native sendfile.


Of course this will kill connections for all clients that may have a
two second network hickup.



I'm not talking about killing the connection. I'm talking about retrying 
sendfile() if threadWaitWrite has been waiting for more than 1 second.


If the connection *has already been closed* (as detected by the OS), 
then sendfile() will fail with EBADF, and we're good.


If the connection *hasn't been closed*, there are two cases:

  a) Sendfile can send more data, in which case it does and we go back 
to sleep on a threadWaitWrite.
  b) Sendfile cannot send more data... in which case the sendfile 
library gets an EAGAIN and goes back to sleep on a threadWaitWrite.


I don't see how that would lead to anything like what you describe.

How so? As a user I expect sendfile to work and not semi-randomly block 
threads indefinitely.


If you want sending something to terminate you will add a timeout to
it. A nasty client may e.g. take one byte each minute and sending your
file may take a few years.



This can always happen. The timeout here is at the application level 
(e.g. has this connection been open too long) and sendfile shouldn't 
concern itself with such things.


The point with my proposed fix is that sendfile will be reacting to the 
OS's detection of a dropped connection ASAP (plus 1 second) rather than 
just hanging.


Cheers,

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


[Haskell-cafe] Linux ghci vs Windows ghci

2010-02-21 Thread Donghee Nah
I'm using Windows 7 32bit Host OS(ghc 6.8.3) and Virtualbox Archlinux Guest
OS(ghc 6.8.4)

I feel that ghci code executing speed in guest os is 1.5~2x faster than host
os

The code:
let t n = do {if n `mod` 10 == 0 then print n else return ()}  t (n+1)
t 1

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


[Haskell-cafe] Parsing of bytestrings with non-String errors?

2010-02-21 Thread Magnus Therning
I've looked at polyparse and attoparsec and they seem to have in common that
the error always is a String.  My current ideas for a project would be a lot
easier if I could just return some other type, something that I can pattern
match on.

Is there a parser combinator library out there that works on bytestrings and
allows using a custom error type?

Or maybe there's some very basic reason why String is so commonly used?

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linux ghci vs Windows ghci

2010-02-21 Thread Ketil Malde
Donghee Nah ppk...@gmail.com writes:

 I feel that ghci code executing speed in guest os is 1.5~2x faster than host
 os

 The code:
 let t n = do {if n `mod` 10 == 0 then print n else return ()}  t (n+1)
 t 1

 any clue?

Speed of the terminal?  Cost of syscalls (user/kernel transitions)?

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsing of bytestrings with non-String errors?

2010-02-21 Thread Malcolm Wallace
Is there a parser combinator library out there that works on  
bytestrings and

allows using a custom error type?


The HuttonMeijerWallace combinators (distributed with polyparse) have  
the custom error type, but not the bytestrings.


Or maybe there's some very basic reason why String is so commonly  
used?


I don't think there is any deep reason.  Strings are convenient, that  
is all.


My guesstimate would be that if you take (e.g.) the polyparse  
combinators, and manually rewrite String everywhere to a parameter e,  
(only when it represents an error of course), it would take you maybe  
an hour in total, including fixing up any site you missed that the  
typechecker catches for you.


Regards,
Malcolm

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


[Haskell-cafe] STArray newListArray

2010-02-21 Thread Vojtěch Knyttl
Hello,

I am trying to create STArray with newListArray like this:
la x y = newListArray ((1,1),(x,y)) [(x'+y') | x' - [1..x], y' - [1..y]]

– but it does not work:
No instance for (MArray a Field m)

I tried to define the type like this, but it would not work either:
la :: Int - Int - STArray (Int,Int) Field

It is obvious that I don't get the syntax of using it, so I will appreciate any 
suggestions.

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


[Haskell-cafe] GHC RTS question

2010-02-21 Thread Artyom Kazak
Hello everybody!
I want to write a little program, that will receive a string as command-line
argument and write it in the file. But if this string contains '+RTS', GHC
runtime won't pass the rest of the string to my program.
What can I do to avoid this?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Profiling

2010-02-21 Thread Andrew Coppin

Two small questions:

1. Is Thread Scope any use for profiling single-threaded programs?

2. I tried to compile my program with -prof, but GHC just whines at me 
that the packages I'm using haven't been compiled for profiling. Do I 
really need to go recompile every single package I'm using with 
profiling support before I can profile my program? How do I tell Cabal 
to install the necessary code? (I really hope this doesn't involve 
uninstalling and reinstalling everything...)


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


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Felipe Lessa
On Sun, Feb 21, 2010 at 05:45:22PM +0200, Artyom Kazak wrote:
 Hello everybody!
 I want to write a little program, that will receive a string as command-line
 argument and write it in the file. But if this string contains '+RTS', GHC
 runtime won't pass the rest of the string to my program.
 What can I do to avoid this?

Use -RTS, as in

$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 6.10.4

$ ghc +RTS -V
ghc: no input files
Usage: For basic information, try the `--help' option.

$ ghc +RTS -RTS -V
The Glorious Glasgow Haskell Compilation System, version 6.10.4

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


Re: [Haskell-cafe] STArray newListArray

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 16:30:00 schrieb Vojtěch Knyttl:
 Hello,

 I am trying to create STArray with newListArray like this:
 la x y = newListArray ((1,1),(x,y)) [(x'+y') | x' - [1..x], y' -
 [1..y]]

 – but it does not work:
 No instance for (MArray a Field m)

 I tried to define the type like this, but it would not work either:
 la :: Int - Int - STArray (Int,Int) Field

STArrays have a state parameter,

newListArray ((1,1),(x,y)) [(x'+y') | x' - [1 .. x], y' - [1 .. y]]

has type 

forall s. ST s (STArray s (Int,Int) Int)

So

la :: forall s. Int - Int - ST s (STArray s (Int,Int) Int)
la x y = 
newListArray ((1,1),(x,y)) [(x'+y') | x' - [1 .. x], y' - [1 .. y]]

You can use STArrays only in the ST monad, there you'd do something like

runST (do arr - la 23 25
  use arr
  return result)


 It is obvious that I don't get the syntax of using it, so I will
 appreciate any suggestions.

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


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 16:45:22 schrieb Artyom Kazak:
 Hello everybody!
 I want to write a little program, that will receive a string as
 command-line argument and write it in the file. But if this string
 contains '+RTS', GHC runtime won't pass the rest of the string to my
 program.
 What can I do to avoid this?

Enclose it in double quotes (perhaps single quotes would also work)

$ ./proggy argwith +RTS in harmlessArg otherHarmlessArg
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] STArray newListArray

2010-02-21 Thread Ben Millwood
2010/2/21 Vojtěch Knyttl kny...@gmail.com:
 Hello,

 I am trying to create STArray with newListArray like this:
 la x y = newListArray ((1,1),(x,y)) [(x'+y') | x' - [1..x], y' - [1..y]]

 – but it does not work:
 No instance for (MArray a Field m)

Notice that newListArray has a monadic return type:

newListArray :: (MArray a e m, Ix i) = (i, i) - [e] - m (a i e)

with MArray a e m requiring Monad m.
So newListArray returns your STArray in a monad. That pretty much has
to be the ST monad, but that's not in scope, so you need to import
Control.Monad.ST before the MArray (STArray s) e (ST s) instance is
usable.

 I tried to define the type like this, but it would not work either:
 la :: Int - Int - STArray (Int,Int) Field


The kind for STArray here is slightly off. STArray needs three type
parameters, not two.
This is linked to the fact that ST is not a monad, but (ST s) is - the
extra parameter is essential to ST, to ensure the mutability doesn't
leak out.
You probably want:

la :: Integer - Integer - ST s (STArray s (Integer, Integer) Field)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Patai Gergely
 I tried to compile my program with -prof, but GHC just whines at me 
 that the packages I'm using haven't been compiled for profiling. Do I 
 really need to go recompile every single package I'm using with 
 profiling support before I can profile my program? How do I tell Cabal 
 to install the necessary code? (I really hope this doesn't involve 
 uninstalling and reinstalling everything...)
Almost. You don't need to uninstall anything, just run cabal install
package --reinstall -p for every relevant package.

Gergely

-- 
http://www.fastmail.fm - mmm... Fastmail...

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


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Thomas DuBuisson
 How do I tell Cabal to install the necessary code?

set:
library-profiling: True

in your ~/.cabal/config file and never deal with this again (for any
new packages you install).  use --reinstall -p to updat existing
packages.

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


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Artyom Kazak
 Enclose it in double quotes (perhaps single quotes would also work)
No, I want my program to work the same way as UNIX echo does.
Without any double quotes.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Andrew Coppin

Patai Gergely wrote:
I tried to compile my program with -prof, but GHC just whines at me 
that the packages I'm using haven't been compiled for profiling. Do I 
really need to go recompile every single package I'm using with 
profiling support before I can profile my program? How do I tell Cabal 
to install the necessary code? (I really hope this doesn't involve 
uninstalling and reinstalling everything...)


Almost. You don't need to uninstall anything, just run cabal install
package --reinstall -p for every relevant package.
  


Oh, right. So I actually need cabal.exe to do this then?

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


Re: [Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-21 Thread Donn Cave
Quoth Bardur Arantsson s...@scientician.net,
 Taru Karttunen wrote:

 Excerpts from Bardur Arantsson's message of Wed Feb 17 21:27:07 +0200 2010:
 For sendfile, a timeout of 1 second would probably be fine. The *ONLY* 
 purpose of threadWaitWrite in the sendfile code is to avoid busy-waiting 
 on EAGAIN from the native sendfile.
 
 Of course this will kill connections for all clients that may have a
 two second network hickup.
 

 I'm not talking about killing the connection. I'm talking about retrying 
 sendfile() if threadWaitWrite has been waiting for more than 1 second.

 If the connection *has already been closed* (as detected by the OS), 
 then sendfile() will fail with EBADF, and we're good.
...
 I don't see how that would lead to anything like what you describe.

If I understand correctly, we're talking about what it means for the
OS to detect a closed connection.

The proposal I think was to change the socket options to add keepalive,
and to set a short timeout.  This will indeed allow the OS to discover
connections that didn't properly close, but are effectively closed in
the sense that they are no use any more - disconnected cable, or it
sounds like the PS3 may routinely do this out of negligence.

The problem is that this definition of `closed' is, precisely,
`failed to respond within 2 seconds.'  If there is no observable
difference between a connection that has been abandoned by the PS3,
and a connection that just suffered a momentary lapse, then there's
no way to catch the former without making connections more fragile.

Donn Cave
d...@avvanta.com

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


Re: [Haskell-cafe] Restricted categories

2010-02-21 Thread Sjoerd Visscher
Ok, I've got product categories working:

 {-# LANGUAGE TypeOperators, TypeFamilies, MultiParamTypeClasses, 
 ScopedTypeVariables, FlexibleContexts, FlexibleInstances, GADTs, RankNTypes, 
 UndecidableInstances #-}

 import Prelude hiding ((.), id, fst, snd)
 import qualified Prelude

Suitable2 could be simplified to one type argument (but it is still different 
from Data.Suitable, because m is of kind * - * - *)

 class Suitable2 m a where
data Constraints m a
constraints :: m a a - Constraints m a

 withResConstraints :: forall m a. Suitable2 m a = (Constraints m a - m a a) 
 - m a a
 withResConstraints f = f (constraints undefined :: Constraints m a)

 class RCategory (~) where
   id :: Suitable2 (~) a = a ~ a
   (.) :: (Suitable2 (~) a, Suitable2 (~) b, Suitable2 (~) c) = b ~ c - 
 a ~ b - a ~ c

 instance Suitable2 (-) a where
   data Constraints (-) a = HaskConstraints
   constraints _ = HaskConstraints
  
 instance RCategory (-) where
   id = Prelude.id
   (.) = (Prelude..)
  
 class IsProduct p where
   type Fst p :: *
   type Snd p :: *
   fst :: p - Fst p
   snd :: p - Snd p
  
 instance IsProduct (a, b) where
   type Fst (a, b) = a
   type Snd (a, b) = b
   fst = Prelude.fst
   snd = Prelude.snd

Adding the restrictions to the constructor made all further problems in the 
definition of (.) go away:

 -- Product category
 data (c1 :***: c2) a b = (IsProduct a, IsProduct b, Suitable2 c1 (Fst a), 
 Suitable2 c1 (Fst b), Suitable2 c2 (Snd a), Suitable2 c2 (Snd b)) 
   = c1 (Fst a) (Fst b) :***: c2 (Snd a) (Snd b)

 instance (IsProduct a, Suitable2 c1 (Fst a), Suitable2 c2 (Snd a)) = 
 Suitable2 (c1 :***: c2) a where
   data Constraints (c1 :***: c2) a = (IsProduct a, Suitable2 c1 (Fst a), 
 Suitable2 c2 (Snd a)) = ProdConstraints
   constraints _ = ProdConstraints

 instance (RCategory c1, RCategory c2) = RCategory (c1 :***: c2) where
   id = withResConstraints $ \ProdConstraints - id :***: id
   (f1 :***: f2) . (g1 :***: g2) = (f1 . g1) :***: (f2 . g2)

Let's test this:

 (@*) :: ((-) :***: (-)) (a, b) (c, d) - (a, b) - (c, d)
 (f :***: g) @* (x, y) = (f x, g y)
 test1 = ((+10) :***: (*2)) @* (1, 2) -- (11, 4)

So that works, but using type families Fst and Snd gives problems if you start 
to use this (see below).

Here's a functor definition. To allow to define the identity functor, the 
actual functor itself is not the instance, but a placeholder type is used. The 
type family F turns the placeholder into the actual functor. The use of type 
families also means you have to pass a type witness of the placeholder to the 
fmap function (here called (%)).

 type family F (ftag :: * - *) a :: *
 class (RCategory (Dom ftag), RCategory (Cod ftag)) = CFunctor ftag where
  type Dom ftag :: * - * - *
  type Cod ftag :: * - * - *
  (%) :: (Suitable2 (Dom ftag) a, Suitable2 (Dom ftag) b) = ftag x - Dom 
 ftag a b - Cod ftag (F ftag a) (F ftag b)

Two examples:

 data Opt a = Opt
 type instance F Opt a = Maybe a
 instance CFunctor Opt where
   type Dom Opt = (-)
   type Cod Opt = (-)
   (Opt % f) Nothing = Nothing
   (Opt % f) (Just x) = Just (f x)

So (Opt % (*2)) has type: Num a = Maybe a - Maybe a. 

 data Id ((~) :: * - * - *) a = Id
 type instance F (Id (~)) a = a
 instance (RCategory (~)) = CFunctor (Id (~)) where
   type Dom (Id (~)) = (~)
   type Cod (Id (~)) = (~)
   Id % f = f

The diagonal functor works nicely too:

 data Diag ((~) :: * - * - *) a = Diag
 type instance F (Diag (~)) a = (a, a)
 instance (RCategory (~)) = CFunctor (Diag (~)) where
  type Dom (Diag (~)) = (~)
  type Cod (Diag (~)) = (~) :***: (~)
  Diag % f = f :***: f

 test2 = (Diag % (*2)) @* (1, 5) -- (2, 10)

But with the projection functors things start to break down. They can be 
defined, but not used:

 data ProjL (c1 :: * - * - *) (c2 :: * - * - *) a = ProjL
 type instance F (ProjL c1 c2) a = Fst a
 instance (RCategory c1, RCategory c2) = CFunctor (ProjL c1 c2) where
  type Dom (ProjL c1 c2) = c1 :***: c2
  type Cod (ProjL c1 c2) = c1
  ProjL % (f :***: g) = f
  
 data ProjR (c1 :: * - * - *) (c2 :: * - * - *) a = ProjR
 type instance F (ProjR c1 c2) a = Snd a
 instance (RCategory c1, RCategory c2) = CFunctor (ProjR c1 c2) where
   type Dom (ProjR c1 c2) = c1 :***: c2
   type Cod (ProjR c1 c2) = c2
   ProjR % (f :***: g) = g

Here's an example, but GHCI does not know what a is, and so throws a bunch of 
errors about Fst a and Snd a.

test3 = (ProjL % ((+10) :***: (*2))) 1 -- Should evalutate to 11, but doesn't 
compile.

When trying to define the product functor, I run into another problem: 

data (w1 :*: w2) a = (forall x. w1 x) :*: (forall x. w2 x)
type instance F (f1 :*: f2) a = (F f1 (Fst a), F f2 (Snd a))
instance (CFunctor f1, CFunctor f2) = CFunctor (f1 :*: f2) where
  type Dom (f1 :*: f2) = Dom f1 :***: Dom f2
  type Cod (f1 :*: f2) = Cod f1 :***: Cod f2
  (w1 :*: w2) % (f1 :***: f2) = (w1 % f1) :***: (w2 % f2)

There is no proof that from a Suitable2 (Dom f) a, the functor produces a 
Suitable2 (Cod f) (F f 

Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 18:20:43 schrieb Artyom Kazak:
  Enclose it in double quotes (perhaps single quotes would also work)

 No, I want my program to work the same way as UNIX echo does.
 Without any double quotes.

Okay, what about

If you absolutely positively want all the rest of the options in a command 
line to go to the program (and not the RTS), use a ––RTS.

$ ./prog +RTS --RTS +RTS

? (BTW, enclosing in quotes doesn't work anyway if the argument consists 
*only* of +RTS, same as with echo, echo -e doesn't output '-e' either).

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


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 18:22:07 schrieb Andrew Coppin:
 Patai Gergely wrote:
  I tried to compile my program with -prof, but GHC just whines at me
  that the packages I'm using haven't been compiled for profiling. Do I
  really need to go recompile every single package I'm using with
  profiling support before I can profile my program? How do I tell
  Cabal to install the necessary code? (I really hope this doesn't
  involve uninstalling and reinstalling everything...)
 
  Almost. You don't need to uninstall anything, just run cabal install
  package --reinstall -p for every relevant package.

 Oh, right. So I actually need cabal.exe to do this then?

No, you can also

$ ./runghc ./Setup.[l]hs configure --enable-library-profiling --user --
prefix=$HOME/.cabal
$ ./runghc ./Setup.[l]hs build
$ ./runghc ./Setup.[l]hs haddock --hyperlink-source
$ ./runghc ./Setup.[l]hs install

It's just more typing [protip: create a batch file (that is the Windows 
analogue of a shell-script, isn't it?)].
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Artyom Kazak
2010/2/21 Daniel Fischer daniel.is.fisc...@web.de:
 Am Sonntag 21 Februar 2010 18:20:43 schrieb Artyom Kazak:
  Enclose it in double quotes (perhaps single quotes would also work)

 No, I want my program to work the same way as UNIX echo does.
 Without any double quotes.

 Okay, what about

 If you absolutely positively want all the rest of the options in a command
 line to go to the program (and not the RTS), use a ––RTS.

 $ ./prog +RTS --RTS +RTS

 ? (BTW, enclosing in quotes doesn't work anyway if the argument consists
 *only* of +RTS, same as with echo, echo -e doesn't output '-e' either).



So, if I type ./prog +RTS --RTS +RTS, the output will be +RTS. But
I want the output to be equal to the input IN ALL CASES, without any
quotes, additional options, etc. I want all the command line to go to
my program. How can I do it? (The only way I know now - hacking the
GHC. If there are no other ways, I'll do it.)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Max Bolingbroke
On 21 February 2010 18:58, Artyom Kazak artyom.ka...@gmail.com wrote:
 So, if I type ./prog +RTS --RTS +RTS, the output will be +RTS. But
 I want the output to be equal to the input IN ALL CASES, without any
 quotes, additional options, etc. I want all the command line to go to
 my program. How can I do it? (The only way I know now - hacking the
 GHC. If there are no other ways, I'll do it.)

You might be able to get somewhere by writing a custom main function
in C and linking it in. According to
http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
if a lib specified with the -l option during compilation contains a
main, that will be used in preference to the one from HSrts.

You could presumably just extend argv with the +RTS --RTS entries
and then call into the one from HSrts, so this might even be quite
easy.

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


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Anthony Cowley
On Sun, Feb 21, 2010 at 1:58 PM, Artyom Kazak artyom.ka...@gmail.com wrote:
 So, if I type ./prog +RTS --RTS +RTS, the output will be +RTS. But
 I want the output to be equal to the input IN ALL CASES, without any
 quotes, additional options, etc. I want all the command line to go to
 my program. How can I do it? (The only way I know now - hacking the
 GHC. If there are no other ways, I'll do it.)

How about a wrapper script? Something like,

#! /usr/bin/env bash
./prog --RTS $*

Just use that as the front-end to your Haskell program.

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


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 19:58:12 schrieb Artyom Kazak:
 2010/2/21 Daniel Fischer daniel.is.fisc...@web.de:
  Am Sonntag 21 Februar 2010 18:20:43 schrieb Artyom Kazak:
   Enclose it in double quotes (perhaps single quotes would also work)
 
  No, I want my program to work the same way as UNIX echo does.
  Without any double quotes.
 
  Okay, what about
 
  If you absolutely positively want all the rest of the options in a
  command line to go to the program (and not the RTS), use a ––RTS.
 
  $ ./prog +RTS --RTS +RTS
 
  ? (BTW, enclosing in quotes doesn't work anyway if the argument
  consists *only* of +RTS, same as with echo, echo -e doesn't output
  '-e' either).

 So, if I type ./prog +RTS --RTS +RTS, the output will be +RTS. But
 I want the output to be equal to the input IN ALL CASES, without any
 quotes, additional options, etc. I want all the command line to go to
 my program. How can I do it? (The only way I know now - hacking the
 GHC. If there are no other ways, I'll do it.)

Shell wrapper:

$ cat wopTest
./opTest +RTS --RTS $@

$ cat opTest.hs
module Main (main) where

import System.Environment (getArgs)

main = mapM_ print = getArgs

$ ./wopTest +RTS -sstderr -RTS
+RTS
-sstderr
-RTS

Other than that, hacking GHC is the only way I can think of either, since 
looking for RTS-options is a fixed (and generally necessary) part of the 
RTS.

But why do you want that behaviour so much that you'd be willing to hack 
GHC?

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


Re: [Haskell-cafe] STArray newListArray

2010-02-21 Thread Vojtěch Knyttl
Ok, the problem was the Monad, which I still don't get completely, because I 
continue like this:

data Field = W|B|H|D deriving (Eq,Show)

pas :: ST s (STArray s (Int, Int) Field) - ST s (STArray s (Int, Int) Field)
pas b = do writeArray b (1,1) W

And still getting:
Couldn't match expected type `STArray s (Int, Int) Field'
   against inferred type `Field'

Thanks.

On Feb 21, 2010, at 5:33, Ben Millwood wrote:

 2010/2/21 Vojtěch Knyttl kny...@gmail.com:
 Hello,
 
 I am trying to create STArray with newListArray like this:
 la x y = newListArray ((1,1),(x,y)) [(x'+y') | x' - [1..x], y' - [1..y]]
 
 – but it does not work:
 No instance for (MArray a Field m)
 
 Notice that newListArray has a monadic return type:
 
 newListArray :: (MArray a e m, Ix i) = (i, i) - [e] - m (a i e)
 
 with MArray a e m requiring Monad m.
 So newListArray returns your STArray in a monad. That pretty much has
 to be the ST monad, but that's not in scope, so you need to import
 Control.Monad.ST before the MArray (STArray s) e (ST s) instance is
 usable.
 
 I tried to define the type like this, but it would not work either:
 la :: Int - Int - STArray (Int,Int) Field
 
 
 The kind for STArray here is slightly off. STArray needs three type
 parameters, not two.
 This is linked to the fact that ST is not a monad, but (ST s) is - the
 extra parameter is essential to ST, to ensure the mutability doesn't
 leak out.
 You probably want:
 
 la :: Integer - Integer - ST s (STArray s (Integer, Integer) Field)

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


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Andrew Coppin

Daniel Fischer wrote:

Am Sonntag 21 Februar 2010 18:22:07 schrieb Andrew Coppin:
  

Oh, right. So I actually need cabal.exe to do this then?


No, you can also

$ ./runghc ./Setup.[l]hs configure --enable-library-profiling --user --
prefix=$HOME/.cabal
$ ./runghc ./Setup.[l]hs build
$ ./runghc ./Setup.[l]hs haddock --hyperlink-source
$ ./runghc ./Setup.[l]hs install

It's just more typing.


What does the --hyperlink-source bit do? For that matter, what do --user 
and --prefix do?



a batch file (that is the Windows analogue of a shell-script, isn't it?)].
  


If by analogue you mean thing that's similar but with approximately 
1/100th the expressive power, then yes. :-D


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


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Stephen Tetley
2010/2/21 Andrew Coppin andrewcop...@btinternet.com:
 Daniel Fischer wrote:


 What does the --hyperlink-source bit do?

Hello Andrew

It generates marked up source code via hs-colour.

Best wishes

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


[Haskell-cafe] grapefruit on windows or osX

2010-02-21 Thread gladstein
I'm unable to get grapefruit going on osx or windows because (I think) I
can't get the underlying GTK installed.

Most recently I can't install gtk2hs over 6.10.4 because the installer
tells me my haskell install isn't working and I should reinstall 6.10.1.
It invites me to continue anyway and fix the DLL path myself.

I continued and it doesn't work; cabal install grapefruit-ui-gtk still
fails because it can't find a version of 'gtk'. The gtk demo program
does work.

Is the situation impossible, or do I just have to somehow tell something
about some path?

Hope that's all clear, and thanks in advance.



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


Re: [Haskell-cafe] STArray newListArray

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 21:26:31 schrieb Vojtěch Knyttl:
 Ok, the problem was the Monad, which I still don't get completely,
 because I continue like this:

 data Field = W|B|H|D deriving (Eq,Show)

 pas :: ST s (STArray s (Int, Int) Field) - ST s (STArray s (Int, Int)
 Field) pas b = do writeArray b (1,1) W

Here, b has type (STArray s (Int,Int) Field), and writeArray has type
ghci :t writeArray
writeArray :: (MArray a e m, Ix i) = a i e - i - e - m ()
, in this case (STArray s (Int,Int) Field - (Int,Int) - Field - ST s (), 
so the signature ought to be

pas :: STArray s (Int,Int) Field - ST s ()

It's new[List]Array, readArray, writeArray etc which have a type of 
... - ST s something
the array itself doesn't.


 And still getting:
 Couldn't match expected type `STArray s (Int, Int) Field'
against inferred type `Field'

That's puzzling. I'd expect a different error message.


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


[Haskell-cafe] Re: darcs 2.4 release candidate 2

2010-02-21 Thread Ben Franksen
And here are the numbers for record -lam:

b...@sarun[1]: .../rtems/rtems-4.9.0  darcs --version
2.3.1 (release)
b...@sarun[1]: .../rtems/rtems-4.9.0  time darcs record -lam'import release
4.9.0'
Finished recording patch 'import release 4.9.0'
darcs record -lam'import release 4.9.0'  143,33s user 6,57s system 69% cpu
3:34,22 total

vs.

b...@sarun[1]: .../rtems/rtems-4.9.0  /home/ben/.cabal/bin/darcs --version
2.3.99.2 (release candidate 2)
b...@sarun[1]: .../rtems/rtems-4.9.0  time /home/ben/.cabal/bin/darcs
record -lam'import release 4.9.0'
withSignalsHandled: Interrupted!

/home/ben/.cabal/bin/darcs record -lam'import release 4.9.0'  1549,45s user
11,81s system 94% cpu 27:40,50 total

(killed by me)

Re Petr Rockai:

No this isn't critical for us at the moment, so I don't need a workaround. I
still think regressions of such a scale should be considered a bug.

Cheers
Ben

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


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Daniel Fischer
Am Sonntag 21 Februar 2010 21:44:57 schrieb Andrew Coppin:
 Daniel Fischer wrote:
  Am Sonntag 21 Februar 2010 18:22:07 schrieb Andrew Coppin:
  Oh, right. So I actually need cabal.exe to do this then?
 
  No, you can also
 
  $ ./runghc ./Setup.[l]hs configure --enable-library-profiling --user
  -- prefix=$HOME/.cabal
  $ ./runghc ./Setup.[l]hs build
  $ ./runghc ./Setup.[l]hs haddock --hyperlink-source
  $ ./runghc ./Setup.[l]hs install
 
  It's just more typing.

 What does the --hyperlink-source bit do?

Stephen already answered that one.

 For that matter, what do --user and --prefix do?

The flag --user allows dependencies to be satisfied from the user package 
database, --prefix says where to put stuff. Of course all these options are 
optional, you can omit them (except --enable-library-profiling, because 
that's your target) and use only the global package database.

One thing, though: if you do it manually, you have to reinstall the 
packages in the correct order (if x depends on y, you can't build x for 
profiling unless y is already built for profiling), cabal takes care of all 
that for you, so the clever method is indeed using cabal.


  a batch file (that is the Windows analogue of a shell-script, isn't
  it?)].

 If by analogue you mean thing that's similar but with approximately
 1/100th the expressive power, then yes. :-D

1/100th is enough for this.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Andrew Coppin



What does the --hyperlink-source bit do?



Hello Andrew

It generates marked up source code via hs-colour.
  


I'm presuming this only works if hs-colour is installed first though? Or 
is it statically linked into the Haddock binary?


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


[Haskell-cafe] Re: darcs 2.4 release candidate 2

2010-02-21 Thread Ben Franksen
Ben Franksen wrote:
 The situation with record is similar.
 
 I admit that the huge RTEMS tree with over 7000 changes between the two
 releases is challenging. However, earlier releases can do it (though it
 takes long, much longer than with, say, mercurial).

Just for comparison, here are the numbers for mercurial:

b...@sarun[1]: .../rtems/rtems-4.9.0  hg --version
Mercurial Distributed SCM (version 0.9.5)
b...@sarun[1]: .../rtems/rtems-4.9.0  hg log
changeset:   0:8b3cbc67b25f
user:b...@sarun
date:Sun Feb 21 21:29:10 2010 +0100
summary: import release 4.8.1

b...@sarun[1]: .../rtems/rtems-4.9.0  time (hg addremove  hg
commit -m'import release 4.9.0')
# ... long output elided ...
(; hg addremove  hg commit -m'import release 4.9.0'; )  9,20s user 1,15s
system 92% cpu 11,181 total

Cheers
Ben

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


Re: [Haskell-cafe] Profiling

2010-02-21 Thread Stephen Tetley
Hi Andrew

It needs installing. Its well worth it though, an invaluable tool.
Thanks Malcolm and Bjorn!

On 21 February 2010 21:27, Andrew Coppin andrewcop...@btinternet.com wrote:
 I'm presuming this only works if hs-colour is installed first though? Or is
 it statically linked into the Haddock binary?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-21 Thread Jeremy Shaw


On Feb 21, 2010, at 11:50 AM, Donn Cave wrote:


The problem is that this definition of `closed' is, precisely,
`failed to respond within 2 seconds.'  If there is no observable
difference between a connection that has been abandoned by the PS3,
and a connection that just suffered a momentary lapse, then there's
no way to catch the former without making connections more fragile.


No. (i think)

What happens is the PS3 has closed the connection, and if you attempt  
to send any more packets the PS3 will tell you it has closed the  
connection and the write() / sendfile() call will raise SIGPIPE.


The problem is we never try to send those packets, because we are  
sitting at threadWaitWrite waiting to write -- and there is nothing  
that is going to happen that will cause that call to select () (by  
threadWaitWrite) to actually wakeup.


I believe the proposal is to add a 2 second time out to the  
threadWaitWrite call. If it wakes up and can't write (because the  
remote side has lost connections, etc) then it will just go back to  
sleep. But if it wakes up, tries to write, and then gets sigPIPE, then  
it knows the connection is actually dead and will clean up after itself.


The problem is that we have not successfully figure out what is  
causing this issue in the first place.


I wrote a haskell server and a C client to try to emulate the  
situation which causes threadWaitWrite to never wake-up.. but I could  
not actually get that to happen. So for the PS3 client is the only  
thing that causes it.


I think that applying a fix with out really understanding the problem  
is asking for trouble.


Among other things, since the problem is with threadWaitWrite (not  
sendfile), then the same issue ought to exist when we are calling  
hPutStr, etc, since they ultimately call threadWaitWrite as well. If  
hPut never has this problem, then we should understand why and use the  
same solution for sendfile. If hPut does have this problem, then  
fixing just sendfile isn't much of a solution.


So far there is:

 - no way for anyone besides Bardur to reproduce the problem
 - no sound explanation for why the PS3 client causes the error, but  
nothing else does
 - no proof that this error does or does not affect all the normal I/ 
O functions in Haskell (hPut, etc).


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


[Haskell-cafe] Re: Re[2]: Threading and FFI

2010-02-21 Thread Ben Franksen
Yves Parès wrote:
 Just one last remark: when I moved all my OpenGL calls from the main
 thread to an unbound thread. I thought it'd not work -- because I assumed
 I would have to launch it in a bound thread -- and however it went
 right...

You were just lucky the RTS accidentally delegated all your OpenGL calls to
the same OS thread. It might turn out bad next time you run the program, or
on another machine, or after adding more threads. Been there...

Cheers
Ben

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


[Haskell-cafe] Re: Parsing of bytestrings with non-String errors?

2010-02-21 Thread Permjacov Evgeniy
On 02/21/2010 11:57 PM, haskell-cafe-requ...@haskell.org wrote:
 Message: 2
 Date: Sun, 21 Feb 2010 12:36:21 +
 From: Magnus Therning mag...@therning.org
 Subject: [Haskell-cafe] Parsing of bytestrings with non-String errors?
 To: haskell-cafe haskell-cafe@haskell.org
 Message-ID: 4b8128c5.6030...@therning.org
 Content-Type: text/plain; charset=utf-8

 I've looked at polyparse and attoparsec and they seem to have in common that
 the error always is a String.  My current ideas for a project would be a lot
 easier if I could just return some other type, something that I can pattern
 match on.

 Is there a parser combinator library out there that works on bytestrings and
 allows using a custom error type?

 Or maybe there's some very basic reason why String is so commonly used?

   

You can try to play with ParsecT / ErrorT

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


Re: [Haskell-cafe] grapefruit on windows or osX

2010-02-21 Thread Yuras Shumovich
If you are using binary gtk2hs installer for windows, then you have to
install the same ghc version the installer was built for.
As I know there are no gtk2hs build for ghc-6.10.4. You can build it
manually (using msys), but it is complicated task.

2010/2/21  gladst...@gladstein.com:
 I'm unable to get grapefruit going on osx or windows because (I think) I
 can't get the underlying GTK installed.

 Most recently I can't install gtk2hs over 6.10.4 because the installer
 tells me my haskell install isn't working and I should reinstall 6.10.1.
 It invites me to continue anyway and fix the DLL path myself.

 I continued and it doesn't work; cabal install grapefruit-ui-gtk still
 fails because it can't find a version of 'gtk'. The gtk demo program
 does work.

 Is the situation impossible, or do I just have to somehow tell something
 about some path?

 Hope that's all clear, and thanks in advance.



 ___
 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] games of chance

2010-02-21 Thread Dupont Corentin
Thanks a lot Mark.
Corentin

On Sat, Feb 20, 2010 at 4:26 AM, Mark Wassell mwass...@bigpond.net.auwrote:

 Take a look at:

 http://hackage.haskell.org/package/probability

 and

 http://web.engr.oregonstate.edu/~erwig/pfp/http://web.engr.oregonstate.edu/%7Eerwig/pfp/

 Mark


 Dupont Corentin wrote:


 Hello,
 are you aware of a framework to find probabilities in a given game of
 chance, in Haskell?

 l would like to compute probabilities like:
 roll 3 dices, sum the result,  then roll 3 other dices, sum the result,
 what is the probability to obtain the same sum?

 Cheers,
 Corentin




 

 ___
 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] GHC RTS question

2010-02-21 Thread Ben Millwood
On Sun, Feb 21, 2010 at 7:10 PM, Max Bolingbroke
batterseapo...@hotmail.com wrote:

 You might be able to get somewhere by writing a custom main function
 in C and linking it in. According to
 http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
 if a lib specified with the -l option during compilation contains a
 main, that will be used in preference to the one from HSrts.


I think the neater way of doing this would be to use the FFI, with a
foreign export declaration making your haskell main available to a
wrapper C file, which would then initialise the RTS with a
slightly-modified argc and argv.
See http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html
for details on how to do that.

I also think it's strange, though, that adding RTS hooks is not
optional. GHC should support some method of disabling them, in my
opinion.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Re[2]: Threading and FFI

2010-02-21 Thread Lars Viklund

On 02/21/2010 09:51 PM, Ben Franksen wrote:

Yves Parès wrote:

Just one last remark: when I moved all my OpenGL calls from the main
thread to an unbound thread. I thought it'd not work -- because I assumed
I would have to launch it in a bound thread -- and however it went
right...


You were just lucky the RTS accidentally delegated all your OpenGL calls to
the same OS thread. It might turn out bad next time you run the program, or
on another machine, or after adding more threads. Been there...


I've been hacking on a DirectX binding recently where just about all 
calls have thread affinity as well.


The effect of running calls on the wrong thread there was (on my 
machine, running Seven) making the whole Windows GUI flicker. I wouldn't 
be surprised if it'd crash on other platforms.


Remember, undefined behaviour is not always kind enough to fail hard.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC RTS question

2010-02-21 Thread Lennart Augustsson
Supply a fix for the problem, and it will probably get included.
There has probably been little demand for this feature so far.

  -- Lennart

On Sun, Feb 21, 2010 at 10:21 PM, Ben Millwood hask...@benmachine.co.uk wrote:
 On Sun, Feb 21, 2010 at 7:10 PM, Max Bolingbroke
 batterseapo...@hotmail.com wrote:

 You might be able to get somewhere by writing a custom main function
 in C and linking it in. According to
 http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
 if a lib specified with the -l option during compilation contains a
 main, that will be used in preference to the one from HSrts.


 I think the neater way of doing this would be to use the FFI, with a
 foreign export declaration making your haskell main available to a
 wrapper C file, which would then initialise the RTS with a
 slightly-modified argc and argv.
 See http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html
 for details on how to do that.

 I also think it's strange, though, that adding RTS hooks is not
 optional. GHC should support some method of disabling them, in my
 opinion.
 ___
 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] GHC RTS question

2010-02-21 Thread Ivan Miljenovic
On 22 February 2010 10:55, Lennart Augustsson lenn...@augustsson.net wrote:
 Supply a fix for the problem, and it will probably get included.
 There has probably been little demand for this feature so far.

But it is a little bit weird where if you have an application that you
release into production (which, admittedly, I've never done), then end
users are able to fiddle with settings which they shouldnt' really
touch (though there's not really that much that I can see that they'd
be able to do wrong with just RTS settings...).


-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
Joan Crawford  - I, Joan Crawford, I believe in the dollar.
Everything I earn, I spend. -
http://www.brainyquote.com/quotes/authors/j/joan_crawford.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Category Theory woes

2010-02-21 Thread Richard O'Keefe


On Feb 21, 2010, at 8:13 AM, Nick Rudnick wrote:


Of course a basic point about language is that the association
between sounds and meanings is (for the most part) arbitrary.
I would rather like to say it is not strictly determined, as an  
evolutionary tendence towards, say ergonomy, cannot be overlooked,  
can it?


I see no evolutionary tendency towards ergonomy in the world's  
languages.

*Articulatory economy*, yes.  Bits are always eroding off words.
But as for any other kind of ergonomy, well, people have been talking
for a very long time, so such a tendency should have had *some* effect
by now, surely?  While there seem to be some deep unities, the world's
languages are a very diverse lot.  Let's face it, who really _needs_
a paucal number?  Or 12 noun classes?  Or 16 cases?  Maori manages
just fine without any of those things.


Why should the terminology of mathematics be any different?
;-) Realizing an evolutionary tendence towards ergonony, is my  
subject...


Does such a tendency exist?
If it does, why should we aid and abet a tendency which, to the
extent it exists in biology, excels in producing parasites?

Thanks for this beautiful example and, honestly, again I ask again  
whether we may regard this as «just noise»: In contrary, aren't such  
usages not paradigmatical examples of memes, which as products of  
memetic evolution, should be studied for their motivational value?


Quite possibly.  But ergonomics is *not* the driver.

The problem I see is that common maths claims an exception in  
claiming that, in it's domain, namings are no more than noise


No such thing.  Quick now, what semantics is transparently revealed
in the names birch, beech, spruce, fir, oak?  To a native speaker
of English, these things mean what they mean by convention and nothing
else.  (If we can trust the OED etymology, beech may have originally
meant a tree with edible fruit, but this is very far from transparent
to a native speaker of modern English.  And spruce trees are so called
not because they are particularly spruce but because they came from
Prussia, again, very far from transparent to a native speaker of M.E.)



And, to close in your figurative style:

Which woman gets hurt by a change of clothes?


The one whose new clothes fit her worse, of course.

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


Re: [Haskell-cafe] Re: sendfile leaking descriptors on Linux?

2010-02-21 Thread Jeremy Shaw
On Sun, Feb 21, 2010 at 6:39 PM, Donn Cave d...@avvanta.com wrote:

 Quoth Jeremy Shaw jer...@n-heptane.com,
 ...
  What happens is the PS3 has closed the connection, and if you attempt
  to send any more packets the PS3 will tell you it has closed the
  connection and the write() / sendfile() call will raise SIGPIPE.
 ...
  So far there is:
 
- no way for anyone besides Bardur to reproduce the problem
- no sound explanation for why the PS3 client causes the error,
  but nothing else does

 I think in fact this invalidates your premise.  If the PS3 really
 closed its connection in the standard fashion, then it would be trivial
 to reproduce this problem with any other peer.  Evidently it doesn't,
 at least in this particular case, and that's why people are talking
 about TCP keep-alives, which address the defunct peer problem (within
 two hours, normally.)


The PS3 does do something though. If we were doing a write *and* read select
on the socket, the read select would wakeup. So, it is trying to notify us
that something has happened, but we are not seeing it because we are only
looking at the write select().

But I can not explain what the PS3 client is doing differently than the
other clients such that it does not cause the threadWaitWrite to wakeup.

Additionally, it is not clear that setting SO_KEEPALIVE will actually fix
anything. The documentation that I have read indicates that that may only
cause the read select() to wakeup not the write select(). Well, that is no
good, because that is supposedly what is happening with the PS3 client
already.

Anyway, part of the annoyance here is that in this particular case we
shouldn't need any timeouts to 'guess' that the client is 'probably dead'.
The client seems to be telling us that it has disconnected, but we are not
looking in the right place. And if we did try to write we would get a
sigPIPE error.

It is not the case the the client is unresponsive -- it is quite responsive.
The problem is that we are not looking in the right place for that response.

But, 'looking in the right place' is tricky. How do you tell hPut that it
should wakeup from threadWaitWrite if the Handle happens to be backed by a
socket, and threadWaitRead has data available? That does not even always
indicate an error condition, it can be a perfectly valid situation.

Well, before I think about that, I want to know what the PS3 client is doing
differently such that it is the only client that seems to exhibit this
behavior at the moment. If we do not understand the real difference between
what the PS3 and the C client are doing, then I don't think we can expect to
arrive at an appropriate fix.

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


[Haskell-cafe] Some great results on fused code with the LLVM backend

2010-02-21 Thread Don Stewart
I tried out some of the vector and uvector fusion benchmarks with the
new LLVM backend


http://donsbot.wordpress.com/2010/02/21/smoking-fast-haskell-code-using-ghcs-new-llvm-codegen/

and got some great results for the tight loops generated through fusion.
Up to 2x faster than gcc -O3 in some cases.

The LLVM backend looks very promising -- considering we've not even
begun to explore the optimization pipeline at the level.

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


[Haskell-cafe] Optimizing hash array mapped tries

2010-02-21 Thread Edward Z. Yang
Hello all,

I spent this weekend attempting to impement Phil Bagwell's Hash
Array Mapped Tries in Haskell.  You can view the fruits of this work at
this repository:

http://github.com/ezyang/hamt

Unfortunately, I'm getting pretty abysmal performance out of the
implementation I wrote, so I'm hoping to get some performance tuning
insights here.

My cost centers look about like this:

 time% alloc%
i-Full-update  HAMT  29.1   31.4
lookup'HAMT  13.74.3
main   Main  12.8   19.7
subkey HAMT  11.5   10.0
i-Bitmap   HAMT   9.4   12.0
i-Full HAMT   8.1   12.9
insert'HAMT   5.10.6
popCount   PopCount   4.71.0

And my GC stats look like:

./HAMTTest 256000 +RTS -t 
275576630962922
ghc: 410718260 bytes, 788 GCs, 19646424/46880276 avg/max bytes residency 
(9 samples),
  138M in use, 0.00 INIT (0.00 elapsed), 1.14 MUT (1.13 elapsed), 1.88 GC 
(2.00 elapsed) :ghc
+ 0:03.16
./IntMapTest 256000 +RTS -t 
-710684043813
ghc: 172126372 bytes, 329 GCs, 5552955/10483896 avg/max bytes residency 
(9 samples),
  31M in use, 0.00 INIT (0.00 elapsed), 0.51 MUT (0.51 elapsed), 0.62 GC 
(0.67 elapsed) :ghc
+ 0:01.18

IntMap is included for comparison.  The HAMT does about x3-5 worse than
IntMap, and uses about x4 more memory (and gets correspondingly
penalized when garbage collection occurs).

My observations/suspicions are as such:

* i-Full-update essentially copies a 32-size vector, with a change to
  one element.  I think I am getting brutally punished for this, in
  terms of both memory usage as well as runtime.  What I'm curious is
  whether or not this is intrinsic to the algorithm, or if it's
  something special that GHC is doing.

* Bagwell suggests that each node in the Array-Mapped Trie should take
  only two words.  I think I'm losing another two words to storing
  bounds information in vector, as well as the costs of boxing (though I
  can't tell if GHC is boxing or not).  I've done some playing around
  with the data declaration, but it's current form seems to result in
  the fastest implementation.  I wonder if this is what is causing the
  x4 ballooning of memory, or if it's something else.  I haven't tried
  rewriting the code to use GHC's arrays.

* Increasing the heap size seems to generally improve the performance
  the HAMT; a 1G heap on a 512K sample set reduces the difference to
  about x1.5-2 slower.  It's hard to tell if the memory allocation
  system is working for or against me.

What bothers me is even if I could magically wave away all GC time in
HAMT, it would only barely win against IntMap.  Maybe the algorithm is
simply not as good as a good ole' Patricia Trie; but then again, maybe
not.

Comments and suggestions greatly appreciated.

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


[Haskell-cafe] Installing wx via cabal

2010-02-21 Thread Dušan Kolář

Dear all,

  Running cabal install --global wx stops very soon with the following 
error.


Building wxcore-0.12.1.2...
[ 1 of 22] Compiling Graphics.UI.WXCore.WxcObject ( 
src/haskell/Graphics/UI/WXCore/WxcObject.hs, 
dist/build/Graphics/UI/WXCore/WxcObject.o )
[ 2 of 22] Compiling Graphics.UI.WXCore.WxcDefs ( 
src/haskell/Graphics/UI/WXCore/WxcDefs.hs, 
dist/build/Graphics/UI/WXCore/WxcDefs.o )
[ 3 of 22] Compiling Graphics.UI.WXCore.WxcClassTypes ( 
src/haskell/Graphics/UI/WXCore/WxcClassTypes.hs, 
dist/build/Graphics/UI/WXCore/WxcClassTypes.o )
[ 4 of 22] Compiling Graphics.UI.WXCore.WxcTypes ( 
src/haskell/Graphics/UI/WXCore/WxcTypes.hs, 
dist/build/Graphics/UI/WXCore/WxcTypes.o )
[ 5 of 22] Compiling Graphics.UI.WXCore.WxcClassesAL ( 
src/haskell/Graphics/UI/WXCore/WxcClassesAL.hs, 
dist/build/Graphics/UI/WXCore/WxcClassesAL.o )

ghc: out of memory (requested 1048576 bytes)
cabal: Error: some packages failed to install:

It seems quite strange as the machine seems to have 16GB RAM and a free 
swap, can I somehow put options or so? I have ghc 10.4. installed.


Thanks

  Dusan

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