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

2010-02-26 Thread Thomas Hartman
I believe this might be causing problems for me with patch-tag.

me: Like mightybyte, I run my app in a shell loop that will just
restart it after a crash. But every once in a while it won't restart
because of the busy socket and I need to do a manual restart, killing
multiple processes (usually 2).

the error I get is:

bind: resource busy (Address already in use)

This sounds like what is being discussed. I have some questions.

 the server will eventually run out of file descriptors

How can I tell if I am running out of file descriptors?

 If I use the portable build of the sendfile package,  everything works fine 
 for hours and hours of this happening.

What is the portable build and how do I use it? Do you eventually have
troubles here as well? What is the reason to use the linux native
build then? speed / more connections per second?

thanks for your help!

2010/2/4 Bardur Arantsson s...@scientician.net:
 Hi all,

 I've been using the sendfile package off Hackage, but it seems to be leaking
 file descriptors when using the Linux-native build.

 What's happening in my specific case is the following:

   1) client requests a range of a file
   2) server starts sending the range
   3) client disconnects before receiving the whole file

 This happens over and over with the client requesting different ranges of
 the file (so the client does make progress).

 If I use the portable build of the sendfile package, everything works fine
 for hours and hours of this happening.

 If I use the Linux-native build of the sendfile package, the server
 will eventually run out of file descriptors. According to lsof the files
 that are being kept open are the data files being sent in 2) above.

 This is on GHC 6.10.x (Ubuntu).

 Is anyone else seeing this? Anyone got any idea what's going on?

 Cheers,

 ___
 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] Linear programming in Haskell

2010-02-26 Thread Alberto Ruiz

Louis Wasserman wrote:

Yo,

Man, I'd never used FFI before, but it's really not as scary as I'd feared.


The FFI is fantastic. We can even use C higher order functions with 
normal Haskell function arguments... :)


I've implemented a more comprehensive interface to GLPK's simplex solver 
and -- rather importantly, for my own needs -- its MIP solver.  This 
doesn't depend on hmatrix, and in fact, it doesn't require any matrix or 
vector manipulation at all -- linear functions are specified as a 
straight-up Data.Map from an arbitrary variable type to their coefficients.


I like your interface, it is very complete and user friendly.
(I used hmatrix because of (my own) laziness, to take advantage of some 
utilities, but of course it is not really required.)


Thanks for your work!
Alberto


The library is now available as glpk-hs on hackage.

Example:

import Data.LinearProgram.LPMonad
import Data.LinearProgram
import Data.LinearProgram.GLPK

objFun :: LinFunc String Int
objFun = linCombination [(10, x1), (6, x2), (4, x3)]

lp :: LP String Int
lp = execLPM $ dosetDirection Max
setObjective objFun
leqTo (varSum [x1, x2, x3]) 100
leqTo (10 *^ var x1 ^+^ 4 * x2 ^+^ 5 *^ var x3) 600
-- c *^ var v, c * v, and linCombination [(c, v)] are all equivalent.
-- ^+^ is the addition operation on linear functions.
leqTo (linCombination [(2, x1), (2, x2), (6, x3)]) 300
varGeq x1 0
varBds x2 0 50
varGeq x3 0
setVarKind x1 IntVar
setVarKind x2 ContVar

main = print = glpSolveVars mipDefaults lp

This requires GLPK to be installed, like below.

Louis Wasserman
wasserman.lo...@gmail.com mailto:wasserman.lo...@gmail.com
http://profiles.google.com/wasserman.louis


On Wed, Feb 24, 2010 at 4:07 AM, Alberto Ruiz ar...@um.es 
mailto:ar...@um.es wrote:


I have uploaded to hackage an interface to the simplex algorithm
based on GLPK. It is a very early version, it will probably have
lots of problems. In the future I would like to add support for
integer variables (MIP). Any suggestion is welcome.

This is an example taken from glpk-utils:

http://code.haskell.org/hmatrix/packages/glpk/examples/simplex3.hs

Documentation: http://perception.inf.um.es/~aruiz/hmatrix-glpk/
http://perception.inf.um.es/%7Earuiz/hmatrix-glpk/

Installation:

$ sudo apt-get install libglpk-dev
$ cabal update
$ cabal install hmatrix-glpk

If hmatrix is not installed we also need

$ sudo apt-get install libgsl0-dev liblapack-dev

I hope it is useful,
Alberto



Erik de Castro Lopo wrote:

Alberto Ruiz wrote:

I think that GSL does not include linear programming
solvers, but in the GSL home page there is a reference to
the GLPK package:

http://www.gnu.org/software/glpk/glpk.html

I have not used it, but it would be very nice to have a
simple Haskell interface to GLPK (or other similar library)
in hmatrix or as a separate package. I will take a look at this.


I used GLPK many years ago and I found it excellent.

Erik





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


Re: [Haskell-cafe] hmake and hat

2010-02-26 Thread Joachim Breitner
Hi,

Am Donnerstag, den 25.02.2010, 20:48 -0800 schrieb Jason Dusek:
 Can you provide a link to something describing the error?

Well, here are our patches to make hmake compile:
http://patch-tracker.debian.org/package/hmake/3.14-2

And building hat results in the attached buildlog.

Greetings,
Joachim


-- 
Joachim nomeata Breitner
Debian Developer
  nome...@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nome...@joachim-breitner.de | http://people.debian.org/~nomeata
 dpkg-buildpackage -rfakeroot -D -us -uc
dpkg-buildpackage: setze CFLAGS auf Standardwert: -g -O2
dpkg-buildpackage: setze CPPFLAGS auf Standardwert: 
dpkg-buildpackage: setze LDFLAGS auf Standardwert: 
dpkg-buildpackage: setze FFLAGS auf Standardwert: -g -O2
dpkg-buildpackage: setze CXXFLAGS auf Standardwert: -g -O2
dpkg-buildpackage: Quellpaket hat
dpkg-buildpackage: Quellversion 2.05+rerolled-7
dpkg-buildpackage: Quellen geÀndert durch Arjan Oosting ar...@debian.org
dpkg-buildpackage: Host-Architektur amd64
 fakeroot debian/rules clean
dh_testdir
dh_testroot
rm -f configure-stamp build-stamp
[ ! -f lib/x86_64-Linux/config ] || /usr/bin/make clean

Warning: package(s) packedstring not available (according to ghc-pkg)
MkProg: Can't find module IO in user directories
.
src/hattrans
src/compiler98
  Or in installed libraries/packages at
/usr/lib/ghc-6.10.4/base-3.0.3.1
/usr/lib/ghc-6.10.4/base-4.1.0.0
/usr/lib/ghc-6.10.4/haskell98-1.0.1.0
/home/jojo/.cabal/lib/base64-string-0.1/ghc-6.10.4
  Asked for by: src/hattrans/HatTrans.hs
  Fix using the -I, -P, or -package flags.

Stop - hmake dependency error.

Warning: package(s) packedstring not available (according to ghc-pkg)
MkProg: Can't find module IO in user directories
.
src/hattrans
src/compiler98
  Or in installed libraries/packages at
/usr/lib/ghc-6.10.4/base-3.0.3.1
/usr/lib/ghc-6.10.4/base-4.1.0.0
/usr/lib/ghc-6.10.4/haskell98-1.0.1.0
/home/jojo/.cabal/lib/base64-string-0.1/ghc-6.10.4
  Asked for by: src/hattrans/HatTrans.hs
  Fix using the -I, -P, or -package flags.

Stop - hmake dependency error.
make[1]: Entering directory `/tmp/hat-2.05+rerolled'
cd src/hattrans;   /usr/bin/make clean
make[2]: Entering directory `/tmp/hat-2.05+rerolled/src/hattrans'
rm -f /tmp/hat-2.05+rerolled/targets/x86_64-Linux/obj/hattrans/*. *. *.hi *.hc
make[2]: Leaving directory `/tmp/hat-2.05+rerolled/src/hattrans'
cd src/hatlib; /usr/bin/make clean
make[2]: Entering directory `/tmp/hat-2.05+rerolled/src/hatlib'
rm -rf /tmp/hat-2.05+rerolled/targets/x86_64-Linux/obj/hatlib/ghc6  
Hat/PreludeBuiltin.hs  Hat/PreludeBasic.hs  Hat/IOBuiltinTypes.hs  
Hat/SystemBuiltinTypes.hs  Hat/TimeBuiltinTypes.hs  
Hat/DirectoryBuiltinTypes.hs  Hat/Char.hs  Hat/Ratio.hs  Hat/List.hs  
Hat/Complex.hs  Hat/Numeric.hs  Hat/Maybe.hs  Hat/Monad.hs  Hat/Ix.hs  
Hat/Array.hs  Hat/IO.hs  Hat/System.hs  Hat/Locale.hs  Hat/CPUTime.hs  
Hat/Time.hs  Hat/Random.hs  Hat/Directory.hs  Hat/Data/IORef.hs  
Hat/Data/Bool.hs  Hat/Data/Char.hs  Hat/Data/Complex.hs  Hat/Data/Ix.hs  
Hat/Data/Array.hs  Hat/Data/Bits.hs  Hat/Data/Either.hs  Hat/Data/Maybe.hs  
Hat/Data/FiniteMap.hs  Hat/Data/List.hs  Hat/Data/Ratio.hs  Hat/Data/Set.hs  
Hat/Data/Tuple.hs  Hat/Data/PackedString.hs  Hat/Data/Monoid.hs  
Hat/Data/Word.hs  Hat/Control/Monad.hs  Hat/Control/Monad/Fix.hs  
Hat/Control/Arrow.hs  Hat/Control/Monad/Identity.hs  Hat/Control/Monad/Trans.hs 
 Hat/System/CPUTime.hs  Hat/System/Cmd.hs  Hat/System/Random.hs  
Hat/System/Directory.hs  Hat/System/Environment.hs  Hat/System/Exit.hs  
Hat/System/Locale.hs  Hat/System/Time.hs  Hat/System/IO/Unsafe.hs  
Hat/System/IO.hs  Hat/System/IO/Error.hs  Hat/System/Console/GetOpt.hs  
Hat/Debug/Trace.hs  Hat/Test/QuickCheck.hs  Hat/Text/Show.hs  Hat/Text/Read.hs  
Hat/Text/PrettyPrint/HughesPJ.hs  Hat/Text/PrettyPrint.hs  
Hat/Text/ParserCombinators/Parsec/Char.hs  
Hat/Text/ParserCombinators/Parsec/Combinator.hs  
Hat/Text/ParserCombinators/Parsec/Error.hs  
Hat/Text/ParserCombinators/Parsec/Expr.hs  
Hat/Text/ParserCombinators/Parsec/Pos.hs  
Hat/Text/ParserCombinators/Parsec/Prim.hs  Hat/Text/ParserCombinators/Parsec.hs 
 Hat/Foreign/Ptr.hs  Hat/Foreign/StablePtr.hs  Hat/Foreign/ForeignPtr.hs  
Hat/Foreign/Storable.hs  Hat/Foreign/Marshal/Error.hs  
Hat/Text/ParserCombinators/Parsec/Perm.hs  Hat/Control/Monad/Reader.hs  
Hat/Control/Monad/Writer.hs  Hat/Control/Monad/State.hs  
Hat/Control/Monad/RWS.hs  Hat/Control/Monad/Cont.hs  Hat/Control/Monad/Error.hs 
 Hat/Control/Monad/List.hs  Hat/Prelude.hs Hat/*.hi Hat/Hat.hx \
 PreludeBuiltin.hx  PreludeBasic.hx  IOBuiltinTypes.hx  
SystemBuiltinTypes.hx  TimeBuiltinTypes.hx  DirectoryBuiltinTypes.hx  Char.hx  
Ratio.hx  List.hx  Complex.hx  Numeric.hx  Maybe.hx  Monad.hx  Ix.hx  Array.hx  
IO.hx  System.hx  Locale.hx  CPUTime.hx  Time.hx  Random.hx  Directory.hx  
Data/IORef.hx  Data/Bool.hx  Data/Char.hx  

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

2010-02-26 Thread Brandon S. Allbery KF8NH

On Feb 26, 2010, at 04:28 , Thomas Hartman wrote:

me: Like mightybyte, I run my app in a shell loop that will just
restart it after a crash. But every once in a while it won't restart
because of the busy socket and I need to do a manual restart, killing
multiple processes (usually 2).

the error I get is:

bind: resource busy (Address already in use)


This is on application restart?  It's not out of file descriptors,  
it's just the system keeping the socket around (netstat will show it  
in TIME_WAIT, or possibly in a shutdown negotiation state such as  
LAST_ACK, FIN_WAIT, etc.  TCP lacks *reliable* socket shutdown  
negotiation).


You want to configure the socket with SO_REUSEADDR before trying to  
bind it (setSocketOption socket ReuseAddr 1).


As to the portable version of sendfile, it's because not all systems  
offer a sendfile() system call.  Linux and *BSD do, and can use the  
native implementation; the portable version emulates sendfile() when  
it doesn't exist, at the price of additional CPU usage/system load  
(sendfile() having been created specifically to reduce system load in  
the common case for web servers).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
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] problem loading package unix-2.3.2.0 while installing hackages on OpenSuse

2010-02-26 Thread gmi

I have OpenSuse 11.2 running on VMWare and I have recently installed ghc
6.10.4 from the RPM from OpenSuse. Now I want to install cabal. I have
downloaded the required packages from hackage and I try to run: runhaskell
Setup configure on any of these packages. With option -v I can see an error
while linking unix-2.3.2.0. I am no expert on OpenSuse yet. Does anyone know
what's happening here?


linux-nrvh:/home/gmi/Download/cabal/zlib-0.5.2.0 # runhaskell -f
/usr/bin/ghc -v Setup configure --with-compiler=ghc-6.10.4
...
Loading package filepath-1.1.0.2 ... linking ... done.
Loading package unix-2.3.2.0 ... Setup: command line: can't load .so/.DLL
for: dl (libdl.so: cannot open shared object file: No such file or
directory)
-- 
View this message in context: 
http://old.nabble.com/problem-loading-package-unix-2.3.2.0-while-installing-hackages-on-OpenSuse-tp27717114p27717114.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-26 Thread Christian Maeder
Andy Gimblett schrieb:
 Hi Christian,
[...]
 It may make sense to use something like readMaybe (which is missing in
 the Prelude) instead of read to allow the parser to fail more nicely.
 
 It seems to be kicking up reasonable errors as it is, e.g.:
 
 *Main parse aFloat  2e-h
 Left (line 1, column 4):
 unexpected h
 expecting digit

yes, this is fine, because you reject -h, but suppose it was passed to
read (due to a programming error).

 I haven't seen any uncaught exceptions propagating, if that's what
 you're worried about...?

Yes, read will always work for you. But you could use a parser
*almost* as simple as
  many1 $ oneOf NaInfity+-.eE0123456789
and ask readMaybe if the parsed String can be read as Double.

 So here's what I have now:
 
 float' :: TokenParser st - GenParser Char st Double
 float' t =
   do n - maybeChar -
  spaces
  fs - choice [symbol t NaN,
symbol t Infinity,
do whole - many1 digit
   frac - option  $ do char '.'
  ds - many1 digit
  return $ '.' : ds
   ex - option  $ do choice [char 'e', char 'E']
s - maybeChar +-
ds - many1 digit
return $ concat [e, s, ds]
   return $ concat [whole, frac, ex]
   ]
  whiteSpace t
  return $ read $ n ++ fs
   where maybeChar :: String - GenParser Char st String
 maybeChar as = option  (choice (map char as) = \a - return
 [a])

I would omit handling of spaces (that's a separate lexing step). It's
enough to be able to parse those numbers, that are possible results of
show (for round-trip).

symbol t could be replaced by (try . string) in order to get rid of
the TokenParser (that I don't like).

Spaces following an initial minus sign are quite unusual and rather
indicate that the sign does not belong to number, but that the sign is a
separate operation.

 You can also break it immediately before do, which I think is
 sometimes more clear.

 If not an extra space is added following do this leads to an odd
 indentation of at least one line.
 
 I'm curious: which line in the above is indented oddly?  Oh, wait: you
 don't mean odd as in strange, do you?  You mean odd as in not even? 
 So, e.g. the spaces line starts at column 5?  What's wrong with that?

Right, again a matter of taste.

Cheers Christian

P.S. below is my parser for tptp numbers (as comparison).
It rejects leading zeros, but allows an initial + sign.

fmap read real would work if the input does not start with +
(or is NaN or Infinity).

-- | does not allow leading zeros
natural :: Parser String
natural = string 0 | many1 digit

decimal :: Parser String
decimal = do
  s - option  $ string + | string -
  ds - natural
  return $ s ++ ds

real :: Parser String
real = do
  d - decimal
  f - option  $ do
p - char '.'
n - many1 digit
return $ p : n
  e - option  $ do
x - char 'e' | char 'E'
g - decimal
return $ x : g
  return $ d ++ f ++ e


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


Re: [Haskell-cafe] problem loading package unix-2.3.2.0 while installing hackages on OpenSuse

2010-02-26 Thread Daniel Fischer
Am Freitag 26 Februar 2010 12:52:36 schrieb gmi:
 I have OpenSuse 11.2 running on VMWare and I have recently installed ghc
 6.10.4 from the RPM from OpenSuse. Now I want to install cabal. I have
 downloaded the required packages from hackage and I try to run:

In principle, just unpacking the cabal-install package and running 
bootstrap.sh is far far easier.

 runhaskell Setup configure on any of these packages. With option -v I
 can see an error while linking unix-2.3.2.0. I am no expert on OpenSuse
 yet. Does anyone know what's happening here?


 linux-nrvh:/home/gmi/Download/cabal/zlib-0.5.2.0 # runhaskell -f
 /usr/bin/ghc -v Setup configure --with-compiler=ghc-6.10.4
 ...
 Loading package filepath-1.1.0.2 ... linking ... done.
 Loading package unix-2.3.2.0 ... Setup: command line: can't load
 .so/.DLL for: dl (libdl.so: cannot open shared object file: No such file
 or directory)

You seem to not have libdl.so, which is needed by the unix package.
Can you confirm this by running

$ locate libdl

(or

$ ls /usr/lib | grep libdl
$ ls /lib | grep libdl

if you don't have [the rights to run] locate)?
If that doesn't show something like

/lib/libdl-2.9.so
/lib/libdl.so.2
/usr/lib/libdl.a
/usr/lib/libdl.so

, you'll have to install glibc-devel, which provides /usr/lib/libdl.a and 
/usr/lib/libdl.so (the others are provided by glibc, but I can't imagine 
that you haven't that installed).
And while you're in YaST, installing software, grab almost every *-devel 
package you see, unless you're sufficiently sure that you will not need 
that one - installing one more devel-package a week becomes annoying pretty 
soon.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: do we need types?

2010-02-26 Thread Johannes Waldmann
A type is, well, a type.
A type class is a relation between types.

The confusion probably comes from OO programming 
where (interfaces) describe unary relations (= one parameter type classes).

(begin rant) I wouldn't easily give up algebraic data types 
just because OO programmers don't seem know about them -
so the re-invent them and call it composite pattern...



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


Re: [Haskell-cafe] do we need types?

2010-02-26 Thread Miguel Mitrofanov

I'd say we don't really need subclasses. I mean, what's the difference:

class Eq a where (==) :: a - a - Bool
instance Eq a = Eq (Maybe a) where
  Nothing == Nothing = True
  Just x == Just y = x == y
  _ == _ = False
sort :: Eq a = [a] - [a]

or

data Eq a = Eq {eq :: a - a - Bool}
eqMaybe :: Eq a - Eq (Maybe a)
eqMaybe e = Eq {eq = eqM} where
  eqM Nothing Nothing = True
  eqM (Just x) (Just y) = eq e x y
  eqM _ _ = False
sort :: Eq a - [a] - [a]

Replacing classes with types, we only lose one thing: the compiler won't deduce 
the right instances for us. I'll trade it for the ability to abstract over 
them. After all, we CAN deduce the right
instances by hand, it's just a finite amount of work (not very big, in my 
experience).

Pasqualino Titto Assini wrote:

Hi, just a silly question (or maybe more than one):


In Haskell we have data types (Integer,[a],...) as well as type
classes (Num, Ord...).

But, if we have type classes do we still need types?


Why shouldn't the objects that we process be defined only by their
'interfaces' (assuming that a type class is a kind of interface)?


Maybe the real question is: are type classes a more primitive concept
than data types?

And if so, in a language that had only type classes what would a data
declaration like the following map to:

data List a = Cons a (List a) | Nil

And what about pattern matching? Would that still be possible, and
what form would it take?


And finally, would having only type classes make the type system any simpler?


Thanks,

 titto
___
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] do we need types?

2010-02-26 Thread Miguel Mitrofanov

s/subclasses/classes/
Sorry for the confusion.

Miguel Mitrofanov wrote:

I'd say we don't really need subclasses. I mean, what's the difference:

class Eq a where (==) :: a - a - Bool
instance Eq a = Eq (Maybe a) where
  Nothing == Nothing = True
  Just x == Just y = x == y
  _ == _ = False
sort :: Eq a = [a] - [a]

or

data Eq a = Eq {eq :: a - a - Bool}
eqMaybe :: Eq a - Eq (Maybe a)
eqMaybe e = Eq {eq = eqM} where
  eqM Nothing Nothing = True
  eqM (Just x) (Just y) = eq e x y
  eqM _ _ = False
sort :: Eq a - [a] - [a]

Replacing classes with types, we only lose one thing: the compiler won't 
deduce the right instances for us. I'll trade it for the ability to 
abstract over them. After all, we CAN deduce the right
instances by hand, it's just a finite amount of work (not very big, in 
my experience).


Pasqualino Titto Assini wrote:

Hi, just a silly question (or maybe more than one):


In Haskell we have data types (Integer,[a],...) as well as type
classes (Num, Ord...).

But, if we have type classes do we still need types?


Why shouldn't the objects that we process be defined only by their
'interfaces' (assuming that a type class is a kind of interface)?


Maybe the real question is: are type classes a more primitive concept
than data types?

And if so, in a language that had only type classes what would a data
declaration like the following map to:

data List a = Cons a (List a) | Nil

And what about pattern matching? Would that still be possible, and
what form would it take?


And finally, would having only type classes make the type system any 
simpler?



Thanks,

 titto
___
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] problem loading package unix-2.3.2.0 while installing hackages on OpenSuse

2010-02-26 Thread gmi

Thanks a lot. It was all about installing *-devel things.
-- 
View this message in context: 
http://old.nabble.com/problem-loading-package-unix-2.3.2.0-while-installing-hackages-on-OpenSuse-tp27717114p27718263.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


[Haskell-cafe] Re: do we need types?

2010-02-26 Thread Maurí­cio CA

A type class is a relation between types.


Yes, but not officially, just de facto:

http://hackage.haskell.org/trac/haskell-prime/ticket/90

Best,

Maurício

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


Re: GUI (was: Re: [Haskell-cafe] DLL on Windows)

2010-02-26 Thread Daniel Fischer
Am Mittwoch 17 Februar 2010 12:17:10 schrieb Jeremy O'Donoghue:
 You're probably correct about the dependencies. I have never tried to
 compile wxHaskell against GHC 6.12.1

 I'm waiting for Haskell Platform to be released to make the required
 changes since (working primarily on Windows) I just don't have time to
 create a complete GHC 6.12 installation with most of the HP libraries
 (some of which are a pain to get working on Windows).

 wxHaskell will support GHC 6.12.x within a couple of days of release of
 a suitable Haskell Platform.

 Regards
 Jeremy

Beating a dead horse, but today I decided to see whether I could install 
wxHaskell, all it took was a few edits in some .cabal files and one in 
wxcore's Setup to make it all build with 6.12.1.
Still, it's annoying because you have to unpack everything, edit and cabal 
install in the unpacked directories.

Now since I did that, I could upload new verxions of wxdirect, wxcore and 
wx to hackage, so others could do a simple cabal install wx.

But I would only do that if I get a go-ahead from somebody authorised 
(since Jeremy uploaded the previous versions, he'd be qualified, I think).

Or I could send the edits to Jeremy and let him do the uploading, whatever 
is preferred.


 On Tue, 16 Feb 2010 17:55 -0800, Thomas DuBuisson

 thomas.dubuis...@gmail.com wrote:
  On Tue, Feb 16, 2010 at 3:48 PM, Henk-Jan van Tuyl hjgt...@chello.nl
 
  wrote:
   On Tue, 16 Feb 2010 18:57:20 +0100, Neil Mitchell
   ndmitch...@gmail.com
  
   wrote:
   I used to recommend Gtk2hs over wxHaskell for GUI development as
   there was always a version that worked on Windows with the latest
   GHC release. I think I might have to switch back to recommending C#
   for GUI development...
  
   The latest revision of wxHaskell can be compiled relatively easy, so
   that wxHaskell can be used immediately for the latest version of
   GHC.
 
  Exciting allegation, but it doesn't quite check out with GHC 6.12.1 +
  cabal 1.8.0.2 and cabal-install 0.8 (see below).  I would expect this
  issue to be easily resolved by specifying containers = 0.3.* in the
  wxdirect package, but cabal is misbehaving (for me) and stating
  wxdirect needs reinstalled with a supposedly newer version of
  containers, 0.2.0.1.
 
  Thomas
 
  [to...@mavlo ~]$ cabal install wx
  Resolving dependencies...
  Downloading containers-0.2.0.1...
  Configuring containers-0.2.0.1...
  Preprocessing library containers-0.2.0.1...
  Building containers-0.2.0.1...
 
  Data/IntMap.hs:182:7:
  Could not find module `Data.Data':
It is a member of the hidden package `base'.
Perhaps you need to add `base' to the build-depends in your
  .cabal file.
Use -v to see a list of the files searched for.
  cabal: Error: some packages failed to install:
  containers-0.2.0.1 failed during the building phase. The exception
  was: ExitFailure 1
  wx-0.12.1.2 depends on containers-0.2.0.1 which failed to install.
  wxcore-0.12.1.2 depends on containers-0.2.0.1 which failed to install.
  wxdirect-0.12.1.1 depends on containers-0.2.0.1 which failed to
  install.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Generalizing nested list comprehensions

2010-02-26 Thread Ishaaq Chandy

Hi all,
If this question sounds a bit noob-ish, that would be because I am one - so
apologies in advance!

I have functions that look something like these:

f1 :: [a] - [b]
f1 xs = [foo [x1, x2] |
 x1 - xs,
 x2 - bar x1,
 baz x1 /= baz x2]

f2 :: [a] - [b]
f2 xs = [foo [x1, x2, x3] | 
 x1 - xs,
 x2 - bar x1,
 x3 - bar x2, 
 baz x1 /= baz x2,
 baz x1 /= baz x3,
 baz x2 /= baz x3]

f3 :: [a] - [b]
f3 xs = [foo [x1, x2, x3, x4] |
 x1 - xs,
 x2 - bar x1,
 x3 - bar x2, 
 x4 - bar x3, 
 baz x1 /= baz x2,
 baz x1 /= baz x3,
 baz x1 /= baz x4,
 baz x2 /= baz x3,
 baz x1 /= baz x4]

Note that for the purposes of this discussion it does not matter what foo,
bar and baz do.

Now what I want to do is write a generalized function fn based on the
pattern set by f1, f2 and f3 such that:
fn :: Int - [a] - [b]
and:
(fn 1 xs) == f1 xs
(fn 2 xs) == f2 xs
(fn 3 xs) == f3 xs
(fn 25 xs) == f25 xs

- obviously if I were to implement f25 as nested list comprehensions it
would be ridiculously tedious!

Any ideas how I can implement fn?

Thanks,
Ishaaq 

-- 
View this message in context: 
http://old.nabble.com/Generalizing-nested-list-comprehensions-tp27719199p27719199.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Generalizing nested list comprehensions

2010-02-26 Thread Daniel Fischer
Am Freitag 26 Februar 2010 15:52:15 schrieb Ishaaq Chandy:
 Hi all,
 If this question sounds a bit noob-ish, that would be because I am one -
 so apologies in advance!

 I have functions that look something like these:

 f1 :: [a] - [b]
 f1 xs = [foo [x1, x2] |
  x1 - xs,
  x2 - bar x1,
  baz x1 /= baz x2]

 f2 :: [a] - [b]
 f2 xs = [foo [x1, x2, x3] |
  x1 - xs,
  x2 - bar x1,
  x3 - bar x2,
  baz x1 /= baz x2,
  baz x1 /= baz x3,
  baz x2 /= baz x3]

 f3 :: [a] - [b]
 f3 xs = [foo [x1, x2, x3, x4] |
  x1 - xs,
  x2 - bar x1,
  x3 - bar x2,
  x4 - bar x3,
  baz x1 /= baz x2,
  baz x1 /= baz x3,
  baz x1 /= baz x4,
  baz x2 /= baz x3,
  baz x1 /= baz x4]

 Note that for the purposes of this discussion it does not matter what
 foo, bar and baz do.

 Now what I want to do is write a generalized function fn based on the
 pattern set by f1, f2 and f3 such that:
 fn :: Int - [a] - [b]
 and:
 (fn 1 xs) == f1 xs
 (fn 2 xs) == f2 xs
 (fn 3 xs) == f3 xs
 (fn 25 xs) == f25 xs

 - obviously if I were to implement f25 as nested list comprehensions it
 would be ridiculously tedious!

 Any ideas how I can implement fn?

The easy way is recursion:

import Control.Monad (guard)

fn n xs = do
x1 - xs
let b1 = baz x1
contFn n [] [b1] x1

contFn 0 acc _ xn = [foo (reverse (xn:acc)]
contFn n acc bs xi = do
xj - bar xi
let bj = baz xj
guard (all (/= bj) bs)
contFn (n-1) (xi:acc) (bj:bs) xj

Now, there is probably a frighteningly elegant way to do it with foldM or 
somesuch, but I don't see it at the moment :(


 Thanks,
 Ishaaq

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


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-26 Thread Ketil Malde

| Am Freitag 26 Februar 2010 00:57:48 schrieb Rafael Gustavo da Cunha Pereira 
| Pinto:
|
| There is a single 10 digit number that:
|
| 1) uses all ten digits [0..9], with no repetitions
| 2) the number formed by the first digit (right to left, most
| significant) is divisible by one
| 3) the number formed by the first 2 digits (again right to left) is
| divisible by two
| 4) the number formed by the first 3 digits is divisible by three
|  and so on, until:
| 11) the number formed by the first 10 digits (all!) is by 10

Since Ishaaq Chandy just posted about how to generalize nested list
comprehensions, I thought this was an interesting way to approach this.

First a couple of simple helper functions:

 val = foldl (\x y - x*10+y) 0
 divides d n = n `mod` d == 0

So you could solve it using a set of list comprehensions:

 solutions = [[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
   | x1 - [0..9]
   , x2 - [0..9], divides 2 $ val [x1,x2]
   , x3 - [0..9], divides 3 $ val [x1,x2,x3]
   , x4 - [0..9], divides 4 $ val [x1,x2,x3,x4]
   , x5 - [0..9], divides 5 $ val [x1,x2,x3,x4,x5]
   , x6 - [0..9], divides 6 $ val [x1,x2,x3,x4,x5,x6]
   , x7 - [0..9], divides 7 $ val [x1,x2,x3,x4,x5,x6,x7]
   , x8 - [0..9], divides 8 $ val [x1,x2,x3,x4,x5,x6,x7,x8]
   , x9 - [0..9], divides 9 $ val [x1,x2,x3,x4,x5,x6,x7,x8,x9]
   , x10 - [0]
   , length (nub [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]) == 10
   ]

This is a nicely declarative way to do it, and a pretty clear way to
formulate the original problem statement.  But it's a bit tedious with
all the repetitions, so you would rather recurse to make it more
general.  Since list comprehensions are just a different way to work in
the list monad (where | becomes 'guard'), I managed to come up with this:

 solve :: [Int] - [[Int]]
 solve prefix = do 
   let l = length prefix
   if l == 10 
 then return prefix
 else do
   x - [0..9]
   let r = prefix++[x]
   guard (divides (l+1) (val r)  nub r == r)
   solve r

-k

(PS: I'm happy to hear any comments regarding style or other issues)
-- 
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: GUI (was: Re: [Haskell-cafe] DLL on Windows)

2010-02-26 Thread Jeremy O'Donoghue
Hi Daniel,

On Fri, 26 Feb 2010 15:31 +0100, Daniel Fischer
daniel.is.fisc...@web.de wrote:
 Am Mittwoch 17 Februar 2010 12:17:10 schrieb Jeremy O'Donoghue:
  You're probably correct about the dependencies. I have never tried to
  compile wxHaskell against GHC 6.12.1
[snip]
 
 Beating a dead horse, but today I decided to see whether I could install 
 wxHaskell, all it took was a few edits in some .cabal files and one in 
 wxcore's Setup to make it all build with 6.12.1.
 Still, it's annoying because you have to unpack everything, edit and
 cabal install in the unpacked directories.
 
 Now since I did that, I could upload new verxions of wxdirect, wxcore and 
 wx to hackage, so others could do a simple cabal install wx.

Thanks for doing this: it's great news for everyone who is on GHC
6.12.x.

 But I would only do that if I get a go-ahead from somebody authorised 
 (since Jeremy uploaded the previous versions, he'd be qualified, I
 think).

You're right - I'm probably as qualified as anyone! I've found that
if a Cabal build works for one person, it's pretty reliable for all
(this
is one of the joys of Cabal and (to a lesser extent) the Haskell
Platform.

I'm quite happy for you to upload updates to Cabal. I'll pull them next
week and make sure that they get merged to the wxHaskell darcs repo. If
there are any reports of issues with the uploaded version (which I
doubt)
I'll look into them, so you're not taking on any long-term support
burden.

 Or I could send the edits to Jeremy and let him do the uploading,
 whatever is preferred.

I have no strong preference - the only thing I want to be sure of is
that the 
darcs repo stays closely in sync with whatever is in Cabal. If you are
OK with
doing the upload, that's great. Otherwise I'll be very happy to do it
based on
your patches.

Best regards
Jeremy
-- 
  Jeremy O'Donoghue
  jeremy.odonog...@gmail.com

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


Re: [Haskell-cafe] do we need types?

2010-02-26 Thread Jason Dusek
  This reminds me of an email posted to this list long ago
  by Luke Palmer, describing a use of records-as-interfaces
  in Agda.

--
Jason Dusek


-- Forwarded message --
From: Luke Palmer lrpal...@gmail.com
Date: 2009/12/29
Subject: Re: [Haskell-cafe] Alternatives to type classes.
To: Jason Dusek jason.du...@gmail.com
Cc: haskell haskell-cafe@haskell.org


On Tue, Dec 29, 2009 at 6:22 PM, Jason Dusek jason.du...@gmail.com wrote:
  Consider the real numbers. They are a group. We have an
  identity element `0', inverses and closure under the associative
  operation `+'.

Group+ = (+, 0, -1 * _)

  They are another group, too -- the group with `*':

Group* = (*, 1, 1 / _)

Ignoring 0 for sake of discussion.

  This seems like a real problem with the whole notion of
  typeclasses -- we can't really say a set/type is its
  extension with some new operations.

  One road to go on this is to make every extension of the set
  with new ops a different type; but that seems really horribly
  inconvenient. I wonder what approaches have been tried here?

I consider typeclasses a happy notational medium.  They are not
perfect, they miss some cases, but they are pretty good.

For full generality at the expense of some verbosity, I like Agda's
solution pretty well.  Agda allows you to open a record into a
scope.

record Group (a : Set) where
 field
   _+_ : a - a - a
   -_ : a - a
   0 : a

conj : {a : Set} - Group a - a - a - a
conj g x y = x + y + (-x)
   where open g

Maybe I even got the syntax right :-P

The cool thing is that you can use this for the invariant-keeping
property of typeclasses, too.  Eg. Data.Map relies on the fact that
there is at most one Ord instance per type.  By parameterizing the
module over the Ord record, we can do the same:

record Ord (a : Set) where ...

module MapMod (a : Set) (ord : Ord a) where
 Map : b - Set
 Map = ...
 insert : {b : Set} - a - b - Map b - Map b
 insert = ...
 ...

So we have the liberty of being able to use different Ord instances,
but different Ord instances give rise to different Map types, so we
can not violate any invariants.

You can do something similar in Haskell using an existential type,
although it is very inconvenient:

data Ord a = ...
data MapMod map a b = MapMod { empty :: map a b, insert :: a - b -
map a b - map a b, ... }

withMap :: Ord a - (forall map. MapMod map a b - z) - z
withMap ord f = f ( {- implement MapMod here, using ord for ordering }- )

Then you could use maps on different Ords for the same type, but they
could not talk to each other.

Some syntax sugar could help the Haskell situation quite a lot.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Testing and module export lists

2010-02-26 Thread Brandon S. Allbery KF8NH

On Feb 24, 2010, at 20:51 , Ivan Miljenovic wrote:

On 25 February 2010 11:24, Don Stewart d...@galois.com wrote:

Seriously?? Doesn't that break the module system?


Maybe I misunderstood it; all I know is that Curt Sampson says he uses
this kind of stuff for testing purposes by not having to export
functions.

See the -fwarn-unused-binds section at
http://www.haskell.org/ghc/docs/latest/html/users_guide/options-sanity.html


As I read that, the leading underscore doesn't export anything; it  
just suppresses any unused warning for the symbol (which is  
consistent with the other uses of leading underscore in warnings; it's  
also consistent with binding to _ to throw a result away).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
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] ErrorT instance of MonadPlus

2010-02-26 Thread Dmitry Olshansky
Hello,

ErrorT instance of MonadPlus define that in case of fail both arguments of
mplus a value of Error will be the Error of second computation:

m `mplus` n = ErrorT $ doa - runErrorT mcase a of
   Left  _ - runErrorT nRight r - return (Right
r)

Could it be changed in this way:

m `mplus` n = ErrorT $ doa - runErrorT mcase a of
   Left  e - do

  b - runErrorT n

  case b of

  Left e' - return $ Left (e `eplus` e')

  r - return r

r - return r

where `eplus` could be placed in class Error a:

eplus :: a - a - a

eplus x y = y -- default implementation


In this case we could combine Errors more flexible.


Best regards,

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


Re: [Haskell-cafe] Re: Proper round-trip HughesPJ/Parsec for Doubles?

2010-02-26 Thread Evan Laforge
 real :: Parser String
 real = do
  d - decimal
  f - option  $ do
    p - char '.'
    n - many1 digit
    return $ p : n

Just to throw two bits in here, this is the only style that doesn't
require leaning on the space bar and squinting to line things up,
doesn't require any fancy editor support, and looks fine with
proportional fonts.  It also allows you to move lines around with 'dd'
and 'p' in vi :)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] vector to uvector and back again

2010-02-26 Thread Bryan O'Sullivan
Great, thanks!

On Thu, Feb 25, 2010 at 10:29 PM, Dan Doel dan.d...@gmail.com wrote:

 On Friday 26 February 2010 12:13:56 am Bryan O'Sullivan wrote:
  Dan, do you think you might be releasing your port of uvector-algorithms
 to
  vector any time soon? I've ported mwc-random to use vector, and I'd like
 to
  move statistics (which needs uvector-algorithms) and criterion (ditto)
 too.

 I don't want to hold anything up, so I've released the port to vector. It's
 available on hackage as vector-algorithms 0.3:

  http://hackage.haskell.org/package/vector-algorithms

 It's mostly a straight port, so not much new to learn.

 - There's no .Array in the module names anymore.

 - The Schwartzian transform combinators are gone from
  Data.Vector.Algorithms.Combinators, because I haven't decided on the best
  way to handle those yet (the existing implementation won't work on all
  vectors in the MVector class). Hope that isn't a problem.

 - There's also a new module D.V.A.Search, which so far implements a couple
  variations on binary search. It was something I was starting before the
  switch to vector, so it isn't complete yet.

 There are some moderate performance regressions on some of the algorithms,
 but
 nothing major. Also, the optimizer in 6.12 seems to get very confused when
 working with IO as the PrimMonad in question, resulting in significantly
 worse
 performance. So, I'd recommend sticking with ST, or at least making sure
 the
 algorithms are called in ST, with stToIO. HEAD is better on both these
 fronts,
 so things should get better in the future.

 Let me know if there are any issues.*

 -- Dan

 * P.S. I just noticed I left the .cabal recommending -O2 and -fvia-c
 -optc-O3.
 That's obviously not current since the .cabal is set to compile with -Odph
 and
 with the NCG. I'll amend that in a later version. :)

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


Re: [Haskell-cafe] do we need types?

2010-02-26 Thread John Meacham
On Fri, Feb 26, 2010 at 04:23:52PM +0300, Miguel Mitrofanov wrote:
 I'd say we don't really need subclasses. I mean, what's the difference:

 class Eq a where (==) :: a - a - Bool
 instance Eq a = Eq (Maybe a) where
   Nothing == Nothing = True
   Just x == Just y = x == y
   _ == _ = False
 sort :: Eq a = [a] - [a]

 or

 data Eq a = Eq {eq :: a - a - Bool}
 eqMaybe :: Eq a - Eq (Maybe a)
 eqMaybe e = Eq {eq = eqM} where
   eqM Nothing Nothing = True
   eqM (Just x) (Just y) = eq e x y
   eqM _ _ = False
 sort :: Eq a - [a] - [a]

 Replacing classes with types, we only lose one thing: the compiler won't 
 deduce the right instances for us. I'll trade it for the ability to abstract 
 over them. After all, we CAN deduce the right
 instances by hand, it's just a finite amount of work (not very big, in my 
 experience).

But then we would lose the invarient that there is a unique pairing
between a type and a given class. for instance, you would no longer be
able to implement things like Set and Map,

For instance if you called the two following functions with different
ord arguments, you would suddenly break all the invarients of what 'Set'
means.

insert :: Ord a - a - Set a - Set a
member :: Ord a - a - Set a - Bool

The unique correspondence between types and classes (i.e. no local
instances) is a main _feature_ of type classes. Often when people think
they need local instances, they are just applying type classes when they
should be using a different idiom, such as the one you mention.

John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-02-26 Thread Thomas Hartman
Thanks, I altered my top level request handler as follows

mysmartserver conf h stateProxy = do
  socket - bindPort conf

   I added (setSocketOption socket ReuseAddr 1) here
   Should this be added in a comment, or even in function code,
in Happstack.Server.SimpleHTTP? What are the tradeoffs, when would you
*not* want ot use ReuseAddr?)

  webserverTid - forkIO $ simpleHTTPWithSocket socket conf h
  putStrLn . ( starting happs server ++ ) = time

  control - startSystemState stateProxy -- start the HAppS state
system
  putStrLn . ( happs state started ++ ) = time

  waitForTermination
  killThread webserverTid
  stateShutdown control

I can't replicate the error reliably so I won't know if it actually
fixed the problem for a while, therefore just leaving this cookie
crumb trail in case others may find it helpful.

2010/2/26 Brandon S. Allbery KF8NH allb...@ece.cmu.edu:
 On Feb 26, 2010, at 04:28 , Thomas Hartman wrote:

 me: Like mightybyte, I run my app in a shell loop that will just
 restart it after a crash. But every once in a while it won't restart
 because of the busy socket and I need to do a manual restart, killing
 multiple processes (usually 2).

 the error I get is:

 bind: resource busy (Address already in use)

 This is on application restart?  It's not out of file descriptors, it's just
 the system keeping the socket around (netstat will show it in TIME_WAIT, or
 possibly in a shutdown negotiation state such as LAST_ACK, FIN_WAIT, etc.
  TCP lacks *reliable* socket shutdown negotiation).

 You want to configure the socket with SO_REUSEADDR before trying to bind it
 (setSocketOption socket ReuseAddr 1).

 As to the portable version of sendfile, it's because not all systems offer a
 sendfile() system call.  Linux and *BSD do, and can use the native
 implementation; the portable version emulates sendfile() when it doesn't
 exist, at the price of additional CPU usage/system load (sendfile() having
 been created specifically to reduce system load in the common case for web
 servers).

 --
 brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
 system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
 electrical and computer engineering, carnegie mellon university    KF8NH



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


[Haskell-cafe] Redirecting output

2010-02-26 Thread Louis Wasserman
Is there any way I can temporarily reassign stdout?  In particular, will
this be handled well by the FFI?  I'm hoping there's maybe something like
PHP's output buffering thingy http://php.net/manual/en/book.outcontrol.php.
I'm *binding* (not doing a process call) to an external library which
outputs directly to stdout, but whose output I'd like to use...
Louis Wasserman
wasserman.lo...@gmail.com
http://profiles.google.com/wasserman.louis
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-02-26 Thread Brandon S. Allbery KF8NH

On Feb 26, 2010, at 14:43 , Thomas Hartman wrote:

in Happstack.Server.SimpleHTTP? What are the tradeoffs, when would you
*not* want ot use ReuseAddr?)


In the modern world, any server socket probably should use  
SO_REUSEADDR.  About the only modern use for the default would involve  
servers launched as a result of a port-knock or similar.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
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] ANNOUNCE: wxHaskell for ghc-6.12.1

2010-02-26 Thread Daniel Fischer
Hi all,

there's a new suite of wxHaskell on hackage,

http://hackage.haskell.org/package/wxdirect-0.12.1.2
http://hackage.haskell.org/package/wxcore-0.12.1.3
http://hackage.haskell.org/package/wx-0.12.1.3

If you have ghc-6.12.1 and wxWidgets-2.8, a simple

cabal install wx

should give you wx GUI goodness. It built fine on my openSUSE, and I don't 
see any dependencies which look like they weren't unproblematically cross-
platform.

Unfortunately I was a little too restrictive with the constraints on 
containers, so it doesn't work with ghc-6.10, sorry.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] EDSL's using Filet-O-Fish of Barrelfish project

2010-02-26 Thread Pierre-Evariste Dagand
Hi Kashyap,

 What would be your recommendation on how to get a grasp of FoF

Well, you can read the PLOS paper first. Also, FoF is a literate code,
so hopefully the learning curve will be less steeper. You should also
take a look at the Fugu compiler literate code and, in less extend,
the Hamlet compiler. They are sitting in ./tools/.

 would the tic-tac-toe sample help - could you share that please?

Tic-tac-toe in the caps system was really nothing but a hack (for a
demo). There is no pedagogical value in staring at it: it is just the
file ./capabilities/caps.hl extended with approx. 4800 capabilities!
Reading the official caps.hl is much more interesting, and, if you
really want to, you will quickly see how you can implement your
favorite board game in there. But don't! :-)


Regards,

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


Re: [Haskell-cafe] Redirecting output

2010-02-26 Thread Brandon S. Allbery KF8NH

On Feb 26, 2010, at 14:44 , Louis Wasserman wrote:
Is there any way I can temporarily reassign stdout?  In particular,  
will this be handled well by the FFI?  I'm hoping there's maybe  
something like PHP's output buffering thingy.  I'm *binding* (not  
doing a process call) to an external library which outputs directly  
to stdout, but whose output I'd like to use...


That way lies pain.  It can be done, but if it breaks it will break  
rather thoroughly and leave you stranded.  Untested (aside from  
compilation), no warranty, etc.:


  module Redirect (withRedirectedStdout) where

  import System.IO
  import System.Posix.IO

  -- usage: withRedirectedStdout destinationFileName $ yourIOActionHere
  -- this might work with Haskell I/O, if you're lucky; don't bet on it
  -- stick to FFI calls that use raw I/O
  withRedirectedStdout :: FilePath - IO a - IO a
  withRedirectedStdout f io= do
hFlush stdout
-- style note: should be stdOutput but that doesn't work for the  
binds
-- and I'm not sure it's worth doing those right.  maybe if  
someone wants this

-- for the library I'll clean it up
old - dup 1
closeFd 1
-- this will pattern-match fail if we don't get stdout back; if  
you manage to trigger it,
-- you get to keep both pieces.  (you probably closed stdin,  
which is usually a

-- recipe for disaster, or at minimum extreme confusion)
1 - openFd f WriteOnly (Just 0600) (defaultFileFlags {noctty =  
True, trunc = True, nonBlock = False})

res - io
closeFd 1
1 - dup old
closeFd old
return res

Actually, I bet this fails because your FFI function uses C/C++ stdio  
and doesn't flush it.  That will probably require bringing in C  
stdio's fflush(stdout), which will be even more painful.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
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: Function to detect duplicates

2010-02-26 Thread Daniel Fischer
Am Freitag 26 Februar 2010 16:50:42 schrieb Ketil Malde:
 | Am Freitag 26 Februar 2010 00:57:48 schrieb Rafael Gustavo da Cunha
 | Pereira
 |
 | Pinto:
 | There is a single 10 digit number that:
 |
 | 1) uses all ten digits [0..9], with no repetitions
 | 2) the number formed by the first digit (right to left, most
 | significant) is divisible by one
 | 3) the number formed by the first 2 digits (again right to left) is
 | divisible by two
 | 4) the number formed by the first 3 digits is divisible by three
 |  and so on, until:
 | 11) the number formed by the first 10 digits (all!) is by 10

 Since Ishaaq Chandy just posted about how to generalize nested list
 comprehensions, I thought this was an interesting way to approach this.

Yes. But it approaches the border, for 20 digits it would become annoying 
to type.


 First a couple of simple helper functions:
  val = foldl (\x y - x*10+y) 0
  divides d n = n `mod` d == 0

 So you could solve it using a set of list comprehensions:
  solutions = [[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
 
| x1 - [0..9]

First digit can't be 0, so make it [1 .. 9].
Since you use the fact that the last digit must be the 0, pull all others 
from [1 .. 9].

 
, x2 - [0..9], divides 2 $ val [x1,x2]
, x1 /= x2
, x3 - [0..9], divides 3 $ val [x1,x2,x3]
, x3 `notElem` [x1,x2] -- etc.
, x4 - [0..9], divides 4 $ val [x1,x2,x3,x4]
, x5 - [0..9], divides 5 $ val [x1,x2,x3,x4,x5]
, x6 - [0..9], divides 6 $ val [x1,x2,x3,x4,x5,x6]
, x7 - [0..9], divides 7 $ val [x1,x2,x3,x4,x5,x6,x7]
, x8 - [0..9], divides 8 $ val [x1,x2,x3,x4,x5,x6,x7,x8]
, x9 - [0..9], divides 9 $ val [x1,x2,x3,x4,x5,x6,x7,x8,x9]
, x10 - [0]
, length (nub [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]) == 10
]

Doesn't look as nice, but early pruning saves a lot of work (in this case, 
for very small values of a lot).


 This is a nicely declarative way to do it, and a pretty clear way to
 formulate the original problem statement.

A very direct translation :)

 But it's a bit tedious with
 all the repetitions, so you would rather recurse to make it more
 general.  Since list comprehensions are just a different way to work in

 the list monad (where | becomes 'guard'), I managed to come up with this:
  solve :: [Int] - [[Int]]

Not on a 32-bit system. Word would suffice there, but you don't know that 
in advance, so it'd be Int64 or Integer

  solve prefix = do
let l = length prefix
if l == 10
  then return prefix
  else do
x - [0..9]

You can

   guard (x `notElem` prefix)

here, or use x `notElem` prefix below, but don't use nub r == r when you 
know that only the new element may be duplicated.

let r = prefix++[x]
guard (divides (l+1) (val r)  nub r == r)
solve r

 -k

 (PS: I'm happy to hear any comments regarding style or other issues)

I would make the length of the prefix a parameter of solve.
It's admittedly less elegant, but all those calls to length hurt me :)
Regarding style, I think I prefer

solve prefix =
  case length prefix of
10 - return prefix
l - do
   x - [0 .. 9]
...

over the if-then-else.

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


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-26 Thread Ketil Malde
Daniel Fischer daniel.is.fisc...@web.de skrev:

 Am Freitag 26 Februar 2010 16:50:42 schrieb Ketil Malde:
 solutions = [[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
   | x1 - [0..9]

 First digit can't be 0, so make it [1 .. 9].
 Since you use the fact that the last digit must be the 0, pull all others 
 from [1 .. 9].

Originally, I pulled from alternating odds (x1 - [1,3..9] etc) and
evens, since this is fairly easy to deduce...  I reverted this since the
point was to use brute force.

 solve :: [Int] - [[Int]]

 Not on a 32-bit system. Word would suffice there, but you don't know that 
 in advance, so it'd be Int64 or Integer

Hm?  The Ints are just individual digits here.

 I would make the length of the prefix a parameter of solve.

I thought about generating a list with solutions for increasing lenghts,
so that e.g. 'solve [] !! 10' would solve this particular problem.

 solve prefix =
   case length prefix of
 10 - return prefix
 l - do
x - [0 .. 9]
 ...

 over the if-then-else.

Yes, much nicer.  Thanks for the feedback!

-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] Re: Function to detect duplicates

2010-02-26 Thread Daniel Fischer
Am Freitag 26 Februar 2010 21:34:28 schrieb Ketil Malde:
 Daniel Fischer daniel.is.fisc...@web.de skrev:
  Am Freitag 26 Februar 2010 16:50:42 schrieb Ketil Malde:
  solutions = [[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
 
| x1 - [0..9]
 
  First digit can't be 0, so make it [1 .. 9].
  Since you use the fact that the last digit must be the 0, pull all
  others from [1 .. 9].

 Originally, I pulled from alternating odds (x1 - [1,3..9] etc) and
 evens, since this is fairly easy to deduce...  I reverted this since the
 point was to use brute force.

Yes, but did you forget x10 or did you think that one was too obvious?


  solve :: [Int] - [[Int]]
 
  Not on a 32-bit system. Word would suffice there, but you don't know
  that in advance, so it'd be Int64 or Integer

 Hm?  The Ints are just individual digits here.


Yup. I didn't realise that you don't call val for the 10-digit number(s). 
If you also did x10 - [0 .. 9] and checked 
val [x1, x2, ..., x10] `mod` 10 == 0, it would overflow, that's what I was 
thinking of.

  I would make the length of the prefix a parameter of solve.

 I thought about generating a list with solutions for increasing lenghts,
 so that e.g. 'solve [] !! 10' would solve this particular problem.


That's nice, but I think it'd be ugly with a DFS, much nicer with a BFS, 
like Rafael did.

  solve prefix =
case length prefix of
  10 - return prefix
  l - do
 x - [0 .. 9]
  ...
 
  over the if-then-else.

 Yes, much nicer.  Thanks for the feedback!

 -k

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


Re: [Haskell-cafe] Redirecting output

2010-02-26 Thread Louis Wasserman
Okay, okay, I'm convinced that trying to mess with it in C is easier than in
Haskell.  =P

Louis Wasserman
wasserman.lo...@gmail.com
http://profiles.google.com/wasserman.louis


On Fri, Feb 26, 2010 at 2:14 PM, Brandon S. Allbery KF8NH 
allb...@ece.cmu.edu wrote:

 On Feb 26, 2010, at 14:44 , Louis Wasserman wrote:

 Is there any way I can temporarily reassign stdout?  In particular, will
 this be handled well by the FFI?  I'm hoping there's maybe something like
 PHP's output buffering thingyhttp://php.net/manual/en/book.outcontrol.php.
 I'm *binding* (not doing a process call) to an external library which
 outputs directly to stdout, but whose output I'd like to use...


 That way lies pain.  It can be done, but if it breaks it will break rather
 thoroughly and leave you stranded.  Untested (aside from compilation), no
 warranty, etc.:

   module Redirect (withRedirectedStdout) where

   import System.IO
   import System.Posix.IO

   -- usage: withRedirectedStdout destinationFileName $ yourIOActionHere
   -- this might work with Haskell I/O, if you're lucky; don't bet on it
   -- stick to FFI calls that use raw I/O
   withRedirectedStdout :: FilePath - IO a - IO a
   withRedirectedStdout f io= do
 hFlush stdout
 -- style note: should be stdOutput but that doesn't work for the binds
 -- and I'm not sure it's worth doing those right.  maybe if someone
 wants this
 -- for the library I'll clean it up
 old - dup 1
 closeFd 1
 -- this will pattern-match fail if we don't get stdout back; if you
 manage to trigger it,
 -- you get to keep both pieces.  (you probably closed stdin, which is
 usually a
 -- recipe for disaster, or at minimum extreme confusion)
 1 - openFd f WriteOnly (Just 0600) (defaultFileFlags {noctty = True,
 trunc = True, nonBlock = False})
 res - io
 closeFd 1
 1 - dup old
 closeFd old
 return res

 Actually, I bet this fails because your FFI function uses C/C++ stdio and
 doesn't flush it.  That will probably require bringing in C stdio's
 fflush(stdout), which will be even more painful.

  --
 brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
 system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
 electrical and computer engineering, carnegie mellon universityKF8NH



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


[Haskell-cafe] Re: do we need types?

2010-02-26 Thread Pasqualino Titto Assini
This seems quite relevant:

http://lambda-the-ultimate.org/node/3837

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


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

2010-02-26 Thread Jeremy Shaw
Hello,

It will be interesting to see if that makes any difference -- it shouldn't.
In happstack-server we use 'listenOn'. According to the documentation
listenOn already sets ReuseAddr:

http://hackage.haskell.org/packages/archive/network/2.2.1.7/doc/html/Network.html#v%3AlistenOn

A quick look at the source code confirms it is calling:

setSocketOption sock ReuseAddr 1

It sounds to be like you are getting the socket in use error because you
have 2 processes running. Seems like the first one hasn't really died, but
the second one is started anyway. How is it that your loop starts a second
server when the first one has not finished?

- jeremy

On Fri, Feb 26, 2010 at 1:43 PM, Thomas Hartman tphya...@gmail.com wrote:

 Thanks, I altered my top level request handler as follows

 mysmartserver conf h stateProxy = do
  socket - bindPort conf

   I added (setSocketOption socket ReuseAddr 1) here
   Should this be added in a comment, or even in function code,
 in Happstack.Server.SimpleHTTP? What are the tradeoffs, when would you
 *not* want ot use ReuseAddr?)

  webserverTid - forkIO $ simpleHTTPWithSocket socket conf h
  putStrLn . ( starting happs server ++ ) = time

  control - startSystemState stateProxy -- start the HAppS state
 system
  putStrLn . ( happs state started ++ ) = time

  waitForTermination
  killThread webserverTid
  stateShutdown control

 I can't replicate the error reliably so I won't know if it actually
 fixed the problem for a while, therefore just leaving this cookie
 crumb trail in case others may find it helpful.

 2010/2/26 Brandon S. Allbery KF8NH allb...@ece.cmu.edu:
  On Feb 26, 2010, at 04:28 , Thomas Hartman wrote:
 
  me: Like mightybyte, I run my app in a shell loop that will just
  restart it after a crash. But every once in a while it won't restart
  because of the busy socket and I need to do a manual restart, killing
  multiple processes (usually 2).
 
  the error I get is:
 
  bind: resource busy (Address already in use)
 
  This is on application restart?  It's not out of file descriptors, it's
 just
  the system keeping the socket around (netstat will show it in TIME_WAIT,
 or
  possibly in a shutdown negotiation state such as LAST_ACK, FIN_WAIT, etc.
   TCP lacks *reliable* socket shutdown negotiation).
 
  You want to configure the socket with SO_REUSEADDR before trying to bind
 it
  (setSocketOption socket ReuseAddr 1).
 
  As to the portable version of sendfile, it's because not all systems
 offer a
  sendfile() system call.  Linux and *BSD do, and can use the native
  implementation; the portable version emulates sendfile() when it doesn't
  exist, at the price of additional CPU usage/system load (sendfile()
 having
  been created specifically to reduce system load in the common case for
 web
  servers).
 
  --
  brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
  system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
  electrical and computer engineering, carnegie mellon universityKF8NH
 
 
 

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


[Haskell-cafe] Hackage statistics

2010-02-26 Thread Andrew Coppin
Is there a simple way to discover the answer to questions like how many 
packages are on Hackage? or how many downloads per day does Hackage 
serve? Or is this information not posted anywhere?


(I know there was a blog article a while back with some stats in it, but 
what about the statistics today?)


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


Re: [Haskell-cafe] Hackage statistics

2010-02-26 Thread Don Stewart
andrewcoppin:
 Is there a simple way to discover the answer to questions like how many  
 packages are on Hackage? or how many downloads per day does Hackage  
 serve? Or is this information not posted anywhere?

 (I know there was a blog article a while back with some stats in it, but  
 what about the statistics today?)

501 users have uploaded 7202 versions of 1870 packages.

http://hackage.haskell.org/cgi-bin/hackage-scripts/stats

The download stats are computed occasionally, but I've not had time
since Hackage moved to the new server.

The last edition is here:

   In November, there were 287 package released on Hackage, bringing
   the total number of Haskell packages to 1720. We had a record 143
   thousand downloads from Hackage in November, breaking the previous
   monthly record of 95 thousand set in October 2009, and bringing the
   total downloads from Hackage to 1.53M. 

   
http://haskellwebnews.wordpress.com/2009/12/05/whats-new-in-haskell-december-2009/

We average about 100k downloads a month (e.g. via cabal-install). Or 2-3
thousand downloads a day.

More updates soon.

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


Re: [Haskell-cafe] Re: do we need types?

2010-02-26 Thread Daniel Fischer
Am Freitag 26 Februar 2010 14:07:07 schrieb Johannes Waldmann:
 I wouldn't easily give up algebraic data types

Nor I. Without easily defined ADTs, Haskell wouldn't be nearly so awesome.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage statistics

2010-02-26 Thread Daniel Fischer
Am Freitag 26 Februar 2010 23:57:05 schrieb Don Stewart:

 501 users have uploaded 7202 versions of 1870 packages.

 http://hackage.haskell.org/cgi-bin/hackage-scripts/stats

 The download stats are computed occasionally, but I've not had time
 since Hackage moved to the new server.

Would it be possible to automate that, add that info to the stats page and 
link to it from the front page?


 We average about 100k downloads a month (e.g. via cabal-install).

I'm pretty sure cabal-install plays a BIG role in that. I wouldn't have 
half - what do I say, probably not a quarter - as many packages installed 
without it.

A propos, a big thank you to all who contributed to it.

 Or 2-3 thousand downloads a day.

 More updates soon.

 -- Don

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


[Haskell-cafe] Hackage redirect loop

2010-02-26 Thread Daniel Fischer
Trying to access http://hackage.haskell.org/trac/hackage I land in a 
redirection loop no matter which page or which browser I try. It worked 
earlier today. Has anybody an idea what the heck might be going on?
Is it just me?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage redirect loop

2010-02-26 Thread Felipe Lessa
On Sat, Feb 27, 2010 at 01:56:34AM +0100, Daniel Fischer wrote:
 Trying to access http://hackage.haskell.org/trac/hackage I land in a
 redirection loop no matter which page or which browser I try. It worked
 earlier today. Has anybody an idea what the heck might be going on?
 Is it just me?

Works fine for me.

Good luck,

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


Re: [Haskell-cafe] Hackage redirect loop

2010-02-26 Thread Daniel Fischer
Am Samstag 27 Februar 2010 02:15:17 schrieb Felipe Lessa:
 On Sat, Feb 27, 2010 at 01:56:34AM +0100, Daniel Fischer wrote:
  Trying to access http://hackage.haskell.org/trac/hackage I land in a
  redirection loop no matter which page or which browser I try. It
  worked earlier today. Has anybody an idea what the heck might be going
  on? Is it just me?

 Works fine for me.

Dang!

Oddly, it's only hackage, hackage.haskell.org/trac/ghc works fine, as does 
.../trac/hugs, haskell-prime, gtk2hs, the package database, all work 
flawlessly. Only the hackage trac doesn't.


 Good luck,

 --
 Felipe.

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


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

2010-02-26 Thread Thomas Hartman
Indeed, the error occurs when two processes are running at the same
time. One process isn't serving anything, and the other is just
looping, reported that it can't stop because the port is taken, and
repeating ad infinitum.

The loop I have is

ulimit -v 15
while true; do
  echo starting patchtag: `date`
./dist/build/patchtagserver/patchtagserver --port=80 --
  echo patchtag exited: `date`
  echo patchtag exited: `date`  patch-tag.log
  rm -f _local/patchtagserver_state.lock

The ulimit is so that it will die after consuming a reasonable amount
of memory. (I seem to have a memory leak somewhere, but it takes many
hours to get up to 150M.)

Everything else looks pretty standard to me. It seems to work as
designed most of the time, but occasionally will result in two
processes. I'm baffled as to how this happens.

If anybody has any idea, I would love to hear them.

2010/2/26 Jeremy Shaw jer...@n-heptane.com:
 Hello,
 It will be interesting to see if that makes any difference -- it shouldn't.
 In happstack-server we use 'listenOn'. According to the documentation
 listenOn already sets ReuseAddr:
 http://hackage.haskell.org/packages/archive/network/2.2.1.7/doc/html/Network.html#v%3AlistenOn
 A quick look at the source code confirms it is calling:
    setSocketOption sock ReuseAddr 1
 It sounds to be like you are getting the socket in use error because you
 have 2 processes running. Seems like the first one hasn't really died, but
 the second one is started anyway. How is it that your loop starts a second
 server when the first one has not finished?
 - jeremy
 On Fri, Feb 26, 2010 at 1:43 PM, Thomas Hartman tphya...@gmail.com wrote:

 Thanks, I altered my top level request handler as follows

 mysmartserver conf h stateProxy = do
      socket - bindPort conf

       I added (setSocketOption socket ReuseAddr 1) here
       Should this be added in a comment, or even in function code,
 in Happstack.Server.SimpleHTTP? What are the tradeoffs, when would you
 *not* want ot use ReuseAddr?)

      webserverTid - forkIO $ simpleHTTPWithSocket socket conf h
      putStrLn . ( starting happs server ++ ) = time

      control - startSystemState stateProxy -- start the HAppS state
 system
      putStrLn . ( happs state started ++ ) = time

      waitForTermination
      killThread webserverTid
      stateShutdown control

 I can't replicate the error reliably so I won't know if it actually
 fixed the problem for a while, therefore just leaving this cookie
 crumb trail in case others may find it helpful.

 2010/2/26 Brandon S. Allbery KF8NH allb...@ece.cmu.edu:
  On Feb 26, 2010, at 04:28 , Thomas Hartman wrote:
 
  me: Like mightybyte, I run my app in a shell loop that will just
  restart it after a crash. But every once in a while it won't restart
  because of the busy socket and I need to do a manual restart, killing
  multiple processes (usually 2).
 
  the error I get is:
 
  bind: resource busy (Address already in use)
 
  This is on application restart?  It's not out of file descriptors, it's
  just
  the system keeping the socket around (netstat will show it in TIME_WAIT,
  or
  possibly in a shutdown negotiation state such as LAST_ACK, FIN_WAIT,
  etc.
   TCP lacks *reliable* socket shutdown negotiation).
 
  You want to configure the socket with SO_REUSEADDR before trying to bind
  it
  (setSocketOption socket ReuseAddr 1).
 
  As to the portable version of sendfile, it's because not all systems
  offer a
  sendfile() system call.  Linux and *BSD do, and can use the native
  implementation; the portable version emulates sendfile() when it doesn't
  exist, at the price of additional CPU usage/system load (sendfile()
  having
  been created specifically to reduce system load in the common case for
  web
  servers).
 
  --
  brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
  system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
  electrical and computer engineering, carnegie mellon university    KF8NH
 
 
 


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