Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Ketil Malde
Daniel Fischer <[EMAIL PROTECTED]> writes:

> Maybe I've misused the word segfault.

I think so.  A segfault is the operating-system complaining about an
illegal memory access.  If you get them from Haskell, it is likely a
bug in the compiler or run-time system (or you were using unsafeAt, or
FFI). 

> The programme consumed more and more memory (according to top),
> kswapd started to have a higher CPU-percentage than my programme,
> programme died, system yelling 'Speicherzugriffsfehler', top displays 
> 'kswapd'.

I find that swapping the GHC heap is not productive, so I tend to
limit memory to available RAM.  You can do that either by limiting
available memory to process in the shell (ulimit or limit), or by
specifying RTS options to the haskell program (typically +RTS -Mxxx,
where xxx is 80-90% of physical RAM).

>From the GHC docs (6.4.2):

   -Msize

[Default: unlimited] Set the maximum heap size to size bytes. The

I thought the default was set according to limits? 

heap normally grows and shrinks according to the memory
requirements of the program. The only reason for having this
option is to stop the heap growing without bound and filling up
all the available swap space, which at the least will result in
the program being summarily killed by the operating system. 

In my experience, a program which thrashes severely without heap
limits can run fine if you just limit the heap.  So it's not as much
an issue of 'filling up swap' vs. 'killed by the OS', but 'takes
forever, making the system unresponsive in the process' vs. 'tries
hard to complete in a timely fashion, or halts with an error'.  I much
prefer the latter.

> However the problem might be too little lazyness, because if I explicitly 
> read 
> the file line by line, memory usage remains low enough -- but ByteString is 
> *much* faster anyway.

Right.  You should still try to consume the file lazily, and make sure
the data can get discarded and GC'ed when you have no further use for
it.  But a String is something like 8 or 12 bytes per character, a
ByteString gets you down to 1.

-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] Serialising types with existential data constructors

2006-09-12 Thread Einar Karttunen
On 12.09 15:28, Misha Aizatulin wrote:
>   I've been using existentially quantified data constructors like
> 
> > data Box = forall a. Cxt a => Box a

If you can include Typeable into the mix then serializing works.

Serialize the value as " ".

When deserializing use a Map  
and get the appropriate decoder from there for the type in question.

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


Re: [Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Jason Dagit

On 9/12/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

G'day all.

Quoting Henning Thielemann <[EMAIL PROTECTED]>:

> More precisely: Can you tell me the difference between numbers and "more
> complex mathematical objects"?

Yes.  A Num is anything which supports the common mathematically-
significant operations which are supported by the basic built-in machine
types such as Int and Double.  It need not _be_ a built-in machine type,
but it must support those operations.


And as an example of something which is useful as an instance of num
but isn't a number I have a recent experience I can share.

I was making an embedded domain specific language for excel
spreadsheet formulas recently and found that making my formula
datatype an instance of Num had huge pay offs.  You write formulas in
haskell code and then to turn them into something excel can chew on
you only need to show them.  I can even use things like Prelude.sum to
add up cells.  All I really needed was to define Show and Num
correctly,  neither of which took much mental effort or coding tricks.
Now I get tons for free.

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


Re: [Haskell-cafe] foreach

2006-09-12 Thread Donald Bruce Stewart
lemmih:
> On 9/13/06, Tim Newsham <[EMAIL PROTECTED]> wrote:
> >I was rewriting some non-haskell code in haskell and came up with this
> >construct:
> >
> >   foreach l f = mapM_ f l
> >
> >   main = do
> >   args <- getArgs
> >   foreach args (\arg -> do
> >   foreach [1..3] (\n -> do
> >   putStrLn ((show n) ++ ") " ++ arg)
> >)
> >)
> >
> >which is reminiscent of foreach in other languages.  Seems fairly
> >useful and I was wondering how hard it would be to add some syntactic
> >sugar to the "do" construct to make it a little prettier (ie.
> >not require the parenthesis, binding and nested do, as:
> >
> >   main = do
> >   args <- getArgs
> >   foreach args arg
> >   foreach [1..3] n
> >   putStrLn ((show n) ++ ") " ++ arg)
> >
> >would this type of transformation be possible with template haskell
> >or does this need stronger support from the parser to pull off?
> 
> How about:
> 
>  main = do
>args <- getArgs
>flip mapM_ args $ \arg ->
>  flip mapM_ [1..3] $ \n ->
>putStrLn $ show n ++ ") " ++ arg
> 

Which is, with current Control.Monad:

   main = do
 args <- getArgs
 forM_ args $ \arg ->
   forM_ [1..3] $ \n ->
 putStrLn $ show n ++ ") " ++ arg

I think Tim is looking for an if-then-else "real syntax" feel to his
`foreach' though. I.e. TH or some small preprocessor.
  
-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] foreach

2006-09-12 Thread Lemmih

On 9/13/06, Tim Newsham <[EMAIL PROTECTED]> wrote:

I was rewriting some non-haskell code in haskell and came up with this
construct:

   foreach l f = mapM_ f l

   main = do
   args <- getArgs
   foreach args (\arg -> do
   foreach [1..3] (\n -> do
   putStrLn ((show n) ++ ") " ++ arg)
)
)

which is reminiscent of foreach in other languages.  Seems fairly
useful and I was wondering how hard it would be to add some syntactic
sugar to the "do" construct to make it a little prettier (ie.
not require the parenthesis, binding and nested do, as:

   main = do
   args <- getArgs
   foreach args arg
   foreach [1..3] n
   putStrLn ((show n) ++ ") " ++ arg)

would this type of transformation be possible with template haskell
or does this need stronger support from the parser to pull off?


How about:

 main = do
   args <- getArgs
   flip mapM_ args $ \arg ->
 flip mapM_ [1..3] $ \n ->
   putStrLn $ show n ++ ") " ++ arg

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


[Haskell-cafe] foreach

2006-09-12 Thread Tim Newsham
I was rewriting some non-haskell code in haskell and came up with this 
construct:


  foreach l f = mapM_ f l

  main = do
  args <- getArgs
  foreach args (\arg -> do
  foreach [1..3] (\n -> do
  putStrLn ((show n) ++ ") " ++ arg)
   )
   )

which is reminiscent of foreach in other languages.  Seems fairly
useful and I was wondering how hard it would be to add some syntactic
sugar to the "do" construct to make it a little prettier (ie.
not require the parenthesis, binding and nested do, as:

  main = do
  args <- getArgs
  foreach args arg
  foreach [1..3] n
  putStrLn ((show n) ++ ") " ++ arg)

would this type of transformation be possible with template haskell
or does this need stronger support from the parser to pull off?

Tim Newsham
http://www.thenewsh.com/~newsham/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Retainer Profiling

2006-09-12 Thread Mark Goldman

Ok, so I've done a biographical profile and gotten what (I think) are
the top offenders in creating objects that never get used.  (+RTS -hc
-hbvoid)  The GHC user's guide suggests that the next step is retainer
profiling to see why things are being retained instead of trashed.

Is anyone out there able to explain retainer profiling in more detail
than the GHC user's guide because I've been guessing on both what I've
been seeing and what it all means.  Any response would be appreciated.

-mdg

--
Our problems are mostly behind us, now all we have to do is fight the solutions.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread ajb
G'day all.

Quoting Henning Thielemann <[EMAIL PROTECTED]>:

> It seems we are at a point, where we have to define what is a 'number'.

For backwards compatibility, I'd say a Num is what it is at the
moment.

One of the proposals that comes up every so often is to allow the
declaration of a typeclass instance to automatically declare instances
for all superclasses.  So, for example:

class (Functor m) => Monad m where
fmap f m = m >>= return . f

instance Monad Foo where
return a = {- ... -}
m >>= k = {- ... -}
fail s = {- ... -}

This will automatically declare an instance of Functor Foo.

Similarly, a finer-grained collection of numeric typeclasses could
simply make Num a synonym for (Show a, Ord a, Ring a, Signum a).
Declaring an instance for (Num Bar) declares all of the other
instances that don't yet have a declaration.

> More precisely: Can you tell me the difference between numbers and "more
> complex mathematical objects"?

Yes.  A Num is anything which supports the common mathematically-
significant operations which are supported by the basic built-in machine
types such as Int and Double.  It need not _be_ a built-in machine type,
but it must support those operations.

(Yes, some architectures support vector operations.  This doesn't count
as "basic".  No, some architectures don't support Double or Word64
natively.  I don't care.)

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


Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Donald Bruce Stewart
daniel.is.fischer:
> Am Dienstag, 12. September 2006 22:26 schrieben Sie:
> > Daniel Fischer wrote:
> > > The programme consumed more and more memory (according to top),
> > > kswapd started to have a higher CPU-percentage than my programme,
> > > programme died, system yelling 'Speicherzugriffsfehler', top displays
> > > 'kswapd'.
> > > I believe that means my programme demanded more memory than I have
> > > available (only 256MB RAM + 800MB swap). Is that a segfault or what is
> > > the correct term?
> > >
> > > That is probably due to (apart from the stupidity of my IO-code) the
> > > large overhead of Haskell lists.
> >
> > Most certainly not.  I'm pretty sure this is to a bug in your code.
> > Something retains a data structure which is actually unneeded.  Probably
> 
> Apparently. And my money is on a load of lines from the file (of which I need 
> only the first and last Char).
> 
> > a case of "foldl" where "foldl'" should be used or a "try" in Parsec
> > code where it should be left out or a lot of "updateWiths" to a Map,
> > etc.  Or it could be a bad choice of data structure.  I bet, it's the
> > map you're using to represent the graph (which you don't even need to
> > represent at all, btw).
> 
> No foldl nor parsec around. I represent the graph as a
> 
> UArray (Char,Char) Int 
> 
> (I've switched to Int for the index type, too, when tuning the code), so that 
> shouldn't use much memory (array size is 676).
> The array is built via accumArray, I hope that's sufficiently efficient
> (though now I use unsafeAccumArrayUArray, that's faster).
> 
> How could I solve the problem without representing the graph in some way?
> Possibly that could be done more efficiently than I do it, but I can't 
> imagine 
> how to do it without representing the graph in some data structure.
> >
> > > So the chunk of the file which easily fits into my
> > > RAM in ByteString form is too large as a list of ordinary Strings.
> >
> > The chunk of file should never need to fit into RAM.  If that's a
> > problem, you also forgot to prime a crucial "foldl".
> >
> 
> Forgive the stupid question, but where if not RAM would the chunk currently 
> processed reside?

I agree. Some problems simply require you to hold large strings in
memory. And for those, [Char] conks out around 5-10M (try reversing a
10M [Char]).

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


Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Daniel Fischer
Am Dienstag, 12. September 2006 22:26 schrieben Sie:
> Daniel Fischer wrote:
> > The programme consumed more and more memory (according to top),
> > kswapd started to have a higher CPU-percentage than my programme,
> > programme died, system yelling 'Speicherzugriffsfehler', top displays
> > 'kswapd'.
> > I believe that means my programme demanded more memory than I have
> > available (only 256MB RAM + 800MB swap). Is that a segfault or what is
> > the correct term?
> >
> > That is probably due to (apart from the stupidity of my IO-code) the
> > large overhead of Haskell lists.
>
> Most certainly not.  I'm pretty sure this is to a bug in your code.
> Something retains a data structure which is actually unneeded.  Probably

Apparently. And my money is on a load of lines from the file (of which I need 
only the first and last Char).

> a case of "foldl" where "foldl'" should be used or a "try" in Parsec
> code where it should be left out or a lot of "updateWiths" to a Map,
> etc.  Or it could be a bad choice of data structure.  I bet, it's the
> map you're using to represent the graph (which you don't even need to
> represent at all, btw).

No foldl nor parsec around. I represent the graph as a

UArray (Char,Char) Int 

(I've switched to Int for the index type, too, when tuning the code), so that 
shouldn't use much memory (array size is 676).
The array is built via accumArray, I hope that's sufficiently efficient
(though now I use unsafeAccumArrayUArray, that's faster).

How could I solve the problem without representing the graph in some way?
Possibly that could be done more efficiently than I do it, but I can't imagine 
how to do it without representing the graph in some data structure.
>
> > So the chunk of the file which easily fits into my
> > RAM in ByteString form is too large as a list of ordinary Strings.
>
> The chunk of file should never need to fit into RAM.  If that's a
> problem, you also forgot to prime a crucial "foldl".
>

Forgive the stupid question, but where if not RAM would the chunk currently 
processed reside?

>
> Udo.

Cheers,
Daniel

-- 

"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton

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


Re: [Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Brian Hulley

Bryan Burgers wrote:

That being said, I'll have to play the other side of the coin: it
would probably be a little bit of a pain to have to define instances
of each data declaration (Integer, Int, Float, Matrix, Complex, etc.)
on each of these seperate classes--especially when being in a certain
class usually implies being in another (ie, the definition of a set
being a field requires that that set is a group, right?)


Aaron Denney wrote:

On 2006-09-12, Bryan Burgers <[EMAIL PROTECTED]> wrote:

And another problem I can see is that, for example, the Integers are
a group over addition, and also a group over multiplication;


Not over multiplication, no, because there is no inverse.

I know of no good way to express that a given data type obeys the
same interface two (or more) ways.  Some OO languages try to handle
the case of of an abstract base class being inherited twice through
two different intermediate classes, but none of them do it well.


How about:

   data Multiply = Multiply
   data Add = Add

   class Group c e where
   group :: c -> e -> e -> e
   identity :: c -> e
   inverse :: c -> e -> e

   instance Group Multiply Rational where
   group Multiply x y = ...
   identity Multiply = 1
   inverse Multiply x = ...

   instance Group Add Rational where
   group Add x y = ...
   identity Add = 0
   inverse Add x = ...

   (+) :: Group Add a => a -> a -> a
   (+) = group Add

   (*) = group Multiply

   class (Group Multiply a, Group Add a) => Field a where ...

Regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

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


Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Udo Stenzel
Daniel Fischer wrote:
> The programme consumed more and more memory (according to top),
> kswapd started to have a higher CPU-percentage than my programme,
> programme died, system yelling 'Speicherzugriffsfehler', top displays 
> 'kswapd'.
> I believe that means my programme demanded more memory than I have available 
> (only 256MB RAM + 800MB swap). Is that a segfault or what is the correct 
> term?
> 
> That is probably due to (apart from the stupidity of my IO-code) the large 
> overhead of Haskell lists.

Most certainly not.  I'm pretty sure this is to a bug in your code.
Something retains a data structure which is actually unneeded.  Probably
a case of "foldl" where "foldl'" should be used or a "try" in Parsec
code where it should be left out or a lot of "updateWiths" to a Map,
etc.  Or it could be a bad choice of data structure.  I bet, it's the
map you're using to represent the graph (which you don't even need to
represent at all, btw).


> So the chunk of the file which easily fits into my 
> RAM in ByteString form is too large as a list of ordinary Strings.

The chunk of file should never need to fit into RAM.  If that's a
problem, you also forgot to prime a crucial "foldl".


Udo.
-- 
"Proof by analogy is fraud." -- Bjarne Stroustrup


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


Re: [Haskell-cafe] Weak pointers and referential transparency???

2006-09-12 Thread Brian Hulley

[EMAIL PROTECTED] wrote:

Brian Hulley wrote:
[...]

Ref.write proxiesRef $! (weakProxy : proxies)


(This is nothing to do with your main question, but the
strict application looks unnecessary there.  Its right hand
side is already a constructor cell.)


Yes, thanks for pointing this out.



[...]

In other words, if the entry for the proxy
in the table stored in the Model dies, can
I be absolutely 100% sure that this means
the proxy no longer exists in any shape or
form in the running program?


My reading of the semantics
(http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#4)
is that you can be sure the proxy *object* is gone.


My problem is that I don't know what to make of the word "object" in the 
context of Haskell ie when can I be sure that a value is actually being 
represented as a pointer to a block of memory and not stored in registers or 
optimized out? Or is the compiler clever enough to preserve the concept of 
"object" despite such optimizations? I had been designing my Model/Proxy 
data types with the Java notion of "everything is a pointer to an object" 
but is this always correct relative to Haskell as a language or is it just a 
consequence of the current GHC implementation?




As for referential transparency...

Fan-in:
If you create equivalent proxies in different calls to
createProxy, it's possible that they'll end up referring to
the same object (e.g. if the compiler or RTS does something
fancy, or you use a memoised smart constructor).  So then a
single live proxy object *could* protect many elements of
your Weak Proxy list from scavenging.

Fan-out:
It would seem perverse to cry "referential transparency!"
and spontaneously clone one of your proxy objects.  That
*could* lead to deRefWeak returning Nothing while an
*equivalent* Proxy object is still alive.  Might you run
your program on an avant-garde distributed RTS?  ;-)


Someone else might even if I don't! ;-)

In the meantime I found a better solution to my original problem without 
needing to use weak pointers: I now make the proxy pull the changes from the 
model instead of making the model push them to all registered proxies, so 
there is no longer any need to have a table of registered proxies hence no 
need for weak pointers.


Thanks,
Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 


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


Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Jared Updike

Maybe I've misused the word segfault.
What happened is:
The programme consumed more and more memory (according to top),
kswapd started to have a higher CPU-percentage than my programme,
programme died, system yelling 'Speicherzugriffsfehler', top displays
'kswapd'.
I believe that means my programme demanded more memory than I have available
(only 256MB RAM + 800MB swap). Is that a segfault or what is the correct
term?


I thought a segfault was when a program reads or writes to protected
memory (for example, out of bounds on an array, or dereferencing a
null pointer, etc. things mostly avoided in Haskell). Luckily there
are lots of fun ways to crash computers! I've heard your "heap
overflow" called "exploding" because of how the process rapdily
expands its memory usage, filling all available space, causing system
collapse.

 Jared.
--
http://www.updike.org/~jared/
reverse ")-:"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Jacques Carette

First, as already pointed out in
http://www.haskell.org/pipermail/haskell-cafe/2006-April/015404.html
there is a lot of relevant previous work in this area.

Aaron Denney wrote:

I know of no good way to express that a given data type obeys the
same interface two (or more) ways.  Some OO languages try to handle the
case of of an abstract base class being inherited twice through two
different intermediate classes, but none of them do it well.
  
This is very easy to do in 'raw' category theory, as concepts are not 
_nominal_, so a functor from one type to another can explicitly do a 
renaming if necessary.  Various algebraic specification languages have 
thus adopted this too, so that you are not forced to give unique names 
to all your concepts, you can in fact give them meaningful names 'in 
context', and use a remapping when you want to say that you obey a 
particular interface.


This is an old conversation, see
http://www.haskell.org/pipermail/haskell/2005-October/016621.html
for example.

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


Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Daniel Fischer
Am Montag, 11. September 2006 18:22 schrieben Sie:
> On 9/11/06, Daniel Fischer <[EMAIL PROTECTED]> wrote:
> > The problem spec states that the input file contains about 500 test
> > cases, each given by between 1 and 100,000 lines, each line containing a
> > single word of between 2 and 1000 letters.
> > So the file should be about 12.5G on average.
>
> I don't think that that necessarily follows. Although I've never seen
Not necessarily of course. But as the problem contains a warning about large 
input/output data, I assumed the worst reasonable case (uniform 
distribution).

> the input file, of course, I imagine that many cases are fairly small,
> but designed to test the accuracy of your algorithm. A few are large
> (in one way or another) to test the extremes of your algorithm. But
> the overall size of the input file is probably much, much smaller than
> that estimate. (Maybe 1MB? Maybe 10MB?)

That'd be peanuts with ByteString, 1MB even without.
>
> > A time limit of 7s is given.
>
> That's CPU time, and thus not including I/O, right? I couldn't find

Doesn't IO use the CPU? But seriously, I would have thought that's 
what 'time' lists under user and that includes IO-time as far as I can tell.

> the answer on the SPOJ site. Their FAQ is a forum, but I don't see it
> there:
>
>
> http://www.spoj.pl/forum/viewforum.php?f=6&sid=6c8fb9c3216c3abd1e720f8b4b56
>82b3
>
> In any case, the problem can't be too large; the top twenty programs
> all finished in under 0.35 (CPU seconds?). Even if yours is a tenth as
> fast as the C and C++ programs, that would be 3.5s -- twice as fast as
> it needs to be.
>
> http://www.spoj.pl/ranks/WORDS1/
>
> Of course, you don't have access to these other programs for
> comparison; but I hope that this gives you a better idea of the size
> (and manageability) of the task.
>
> Good luck with it!
>
> --Tom Phoenix

-- 

"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton

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


Re: [Haskell-cafe] Slow IO

2006-09-12 Thread Daniel Fischer
Am Montag, 11. September 2006 17:44 schrieben Sie:
> Daniel Fischer wrote:
> > >   Try Don Stewart's ByteString library
> >
> > -- and some data that made the programme segfault before now run in a
> > couple of seconds.
>
> But that shouldn't happen!  Segfaults aren't performance problems, but
> errors.  So your program contained a bug (lazyness where it isn't
> useful, I suspect), and ByString is hiding it.

Maybe I've misused the word segfault.
What happened is:
The programme consumed more and more memory (according to top),
kswapd started to have a higher CPU-percentage than my programme,
programme died, system yelling 'Speicherzugriffsfehler', top displays 
'kswapd'.
I believe that means my programme demanded more memory than I have available 
(only 256MB RAM + 800MB swap). Is that a segfault or what is the correct 
term?

That is probably due to (apart from the stupidity of my IO-code) the large 
overhead of Haskell lists. So the chunk of the file which easily fits into my 
RAM in ByteString form is too large as a list of ordinary Strings.
However the problem might be too little lazyness, because if I explicitly read 
the file line by line, memory usage remains low enough -- but ByteString is 
*much* faster anyway.

>
> > So even if we just counted newlines, we would have to scan 1,700 million
> > (1.7*10^9) chars per second.
> > Could any ordinary computer of today do that, using whatever language?
>
> That rate should be no problem for a 2GHz machine.  However, a 200MHz 64
> bit wide bus won't deliver the data fast enough and it is 50x as much as
> the best hard disks could deliver in optimal circumstances.  I guess,
> most of the test cases are a lot smaller than your guesstimate.
>

I suppose so, too, but not knowing the test data, I assumed a bad case 
(uniform distribution of line-lengths and test-case-size in the specified 
range).

>
> Udo.


Bulat:
> are you mean arithmetic or geometric average? ;)
I meant 'expected value'.
If X_i are independent random variables uniformly distributed on [0 .. k],
Y is a random variable (independent from the X_i) uniformly distributed on
[1 .. n] and Z is the sum of the first Y of the X_i, then the expected value 
of Z is (n+1)*k/4.
So we might call that a weighted arithmetic average, I suppose.

Cheers,
Daniel

-- 

"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton

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


Re: [Haskell-cafe] Re: evaluate vs seq

2006-09-12 Thread Michael Shulman

On 9/11/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> * (a `seq` return a) = evaluate a *right now*, then produce an IO action
>  which, when executed, returns the result of evaluating a.  Thus, if
>  a is undefined, throws an exception right now.

is a bit misleading as there is no evaluation "right now". It's better
to say that (a `seq` return a) is _|_ ("bottom", i.e. undefined) when a
== _|_.


Sure... but what about when a is not _|_?  I would also like to
understand the difference between `seq' and `evaluate' for arguments
that are defined.  How would you describe that without talking about
"when" expressions are evaluated?


For a more detailed semantics of exceptions in Haskell, see
   " Tackling the awkward squad: monadic input/output, concurrency,
exceptions, and foreign-language calls in Haskell"
   http://research.microsoft.com/%7Esimonpj/Papers/marktoberdorf/


Thanks; I will take a look at it!

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


[Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Aaron Denney
On 2006-09-12, Bryan Burgers <[EMAIL PROTECTED]> wrote:
> And another problem I can see is that, for example, the Integers are a
> group over addition, and also a group over multiplication;

Not over multiplication, no, because there is no inverse.

I know of no good way to express that a given data type obeys the
same interface two (or more) ways.  Some OO languages try to handle the
case of of an abstract base class being inherited twice through two
different intermediate classes, but none of them do it well.

-- 
Aaron Denney
-><-

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


Re: [Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Tim Walkenhorst

Bryan Burgers schrieb:

[...] it would probably be a little bit of a pain to have to define 
instances

of each data declaration (Integer, Int, Float, Matrix, Complex, etc.)
on each of these seperate classes--especially when being in a certain
class usually implies being in another [...]


Something like John Meacham's class alias proposal might help here:
http://repetae.net/john/recent/out/classalias.html


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


Re: [Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Bryan Burgers

It seems we are at a point, where we have to define what is a 'number'.
More precisely: Can you tell me the difference between numbers and "more
complex mathematical objects"? Is a complex number a number? Is a
quaternion a number? Is a residue class a number? We can calculate with
integers modulo some other integer like with integers - is that considered
computation with numbers? Shall we distinguish between matrices of numbers
and matrices of more complex mathematical objects? In signal theory
matrices of polynomials are very common.


My question would be why is it so important to determine what is or
isn't a number? Whether something is a number or not does not
determine what operations and properties it has. Rather, we should try
to determine what is a field, a ring, a group, etc. If we know that
matrices of polynomials form a group, then we can perform the
operations of the group on those objects.

That being said, I'll have to play the other side of the coin: it
would probably be a little bit of a pain to have to define instances
of each data declaration (Integer, Int, Float, Matrix, Complex, etc.)
on each of these seperate classes--especially when being in a certain
class usually implies being in another (ie, the definition of a set
being a field requires that that set is a group, right?) And another
problem I can see is that, for example, the Integers are a group over
addition, and also a group over multiplication; and in my small bit of
thinking about this, it seems that having to keep track of all of this
might get a bit unruly.

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


[Haskell-cafe] Re: Numeric type classes

2006-09-12 Thread Henning Thielemann

On Mon, 11 Sep 2006, Ross Paterson wrote:

> On Mon, Sep 11, 2006 at 04:26:30PM +0200, Henning Thielemann wrote:
> > On Sat, 9 Sep 2006, Ross Paterson wrote:
> > > I think that a finer grain numeric hierarchy, while retaining Num, etc,
> > > is feasible without changing the language: unlike the case of monads,
> > > the people who will be defining instances of numeric classes are the
> > > very ones who are inconvenienced by the current hierarchy.  The main
> > > impact on clients of the classes is that some functions would have
> > > more general types.
> > 
> > There are many Num instances around in libraries where people wrap to
> > external libraries: functionalMetapost, CSound wrapper in Haskore,
> > SuperCollider (GSL too?). What about Num (algebraically Ring) instances of
> > polynomials, residue classes and other such advanced mathematical objects?
> 
> And what do abs and signum mean for Haskore's orchestra expressions,
> polynomials, residue classes, vectors, matrices, functions, etc?

For clarification: Haskore does not define any arithmetic for music, but
CSound provides some arithmetic and Haskell wraps it with Num instances.

> The people who define those wish they were defining Ring, but they must
> define Num.

It seems we are at a point, where we have to define what is a 'number'.  
More precisely: Can you tell me the difference between numbers and "more
complex mathematical objects"? Is a complex number a number? Is a
quaternion a number? Is a residue class a number? We can calculate with
integers modulo some other integer like with integers - is that considered
computation with numbers? Shall we distinguish between matrices of numbers
and matrices of more complex mathematical objects? In signal theory
matrices of polynomials are very common.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] haskell toolchain for slackware

2006-09-12 Thread Andrea Rossato
Hello!

Since there seems to be very little support for haskell in Slackware
Linux, I'm putting together a repository with the most useful (for me)
hasekll utilities.

For the time being there are:
1. ghc-6.4.2 (precompiled binaries packaged for slackware)
2. haddock
3. darsc
4. hscurses
5. HaXml-1.13.2
6. HXT-6.1 with HTTP-20060707

I'm planning to add, very soon, Hugs, hs-plugins and fps-0.7.

The repository should be accessible with slapt-get and swaret. I hope
dependency checking is working with slapt-get.

Here's the repo:
http://gorgias.mine.nu/slack/

You can also grab the SlackBuild scripts (I started using Cabal with
HaXml, HXT and HTTP) here:
http://gorgias.mine.nu/repos/slackBuild/
or
darcs get http://gorgias.mine.nu/repos/slackBuild/

I build my stuff in an almost current slack.

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


Re: [Haskell-cafe] Serialising types with existential data constructors

2006-09-12 Thread Misha Aizatulin
Bulat Ziganshin wrote:

>> data Box = forall a. Cxt a => Box a
>>   quite successfully for a while. But now I am trying to implement the
>> Load/Save mechanism and getting stuck with that. It's not hard to write
>> a Box into a file, but how do I get it back?
> 
> gshow/gread provided by module Data.Generics.Text

  I am afraid this won't do it. For gread to work I still need to know
the result type before I call it, but the problem with the Box is
exactly that you don't know the type it will contain in advance.

  Maybe there is a way to dump the binary representation of the whole
box and then read it back (using unsafeCoerce or similar stuff on the way)?

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


Re: [Haskell-cafe] Serialising types with existential data constructors

2006-09-12 Thread Bulat Ziganshin
Hello Misha,

Tuesday, September 12, 2006, 4:28:28 PM, you wrote:

>   quite successfully for a while. But now I am trying to implement the
> Load/Save mechanism and getting stuck with that. It's not hard to write
> a Box into a file, but how do I get it back?

gshow/gread provided by module Data.Generics.Text

someone once asked me to write binary-format gput/gget, but i don't
done it


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Newbied question on IO Monad

2006-09-12 Thread Andrea Rossato
Il Tue, Sep 12, 2006 at 09:00:19AM -0400, Sara Kenedy ebbe a scrivere:
> Hello,
> 
> Maybe what I talk is not clear.
> 
> I want to take the input string sss of "update" to use in: writeFile
> "myFile.txt" sss of function "main" and get the value zzz from "main"
> to assign for the value return of "update". I think I need to change
> the way to declare two functions to get what I want, but I do not know
> how.
> 
> update :: String -> String
> update sss = zzz
> 
> main = do writeFile "myFile.txt" sss
>x <- callSystem "myFile.txt"
>y <- openFile "result.txt" ReadMode
>zzz <- hGetContents y
>return zzz
> 
> S.

this is what you are trying to do with this code:
1. open a file and write to it an undefined  string called "sss"
2. binding x with the value of a function name callSystem that takes a
string (we do not know what it returns because it's undefined in this
piece of code, but it must be a string).
3. open a file, "result.txt", read its content and put it in the IO
Monad.

Instead you would like to insert into the file myFile.txt a string,
sss, that is the result of applying a function to the content of
"result.txt". Am I right?

If yes, here some code:

update :: String -> String
update sss = "This is the content of result.txt:\n" ++ sss

main = do y <- openFile "result.txt" ReadMode
  zzz <- hGetContents y
  writeFile "myFile.txt" $ update zzz
  putStrLn "Done!"
  return ()

Ciao
Andrea

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


[Haskell-cafe] Re: Newbied question on IO Monad

2006-09-12 Thread Stephane Bortzmeyer
On Tue, Sep 12, 2006 at 09:00:19AM -0400,
 Sara Kenedy <[EMAIL PROTECTED]> wrote 
 a message of 68 lines which said:

> Maybe what I talk is not clear.

Do not worry, not all the haskell-cafe readers speak english. (I'm
french, for instance.)

> I want to take the input string sss of "update" to use in: writeFile
> "myFile.txt" sss of function "main" and get the value zzz from
> "main" to assign for the value return of "update".

>From a newbie to another newbie: I do not think it is possible. "There
is no way out of the IO monad, once you're in it."

See the explanations in the page indicated by Henning Thielemann :

http://haskell.org/hawiki/ThatAnnoyingIoType

This should work (not tested):

update :: String -> IO String
update sss = do 
   writeFile "myFile.txt" sss
   x <- callSystem "myFile.txt"
   y <- openFile "result.txt" ReadMode
   zzz <- hGetContents y
   return zzz

main = update "Foobar"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbied question on IO Monad

2006-09-12 Thread Stefan Holdermans

Sara,


I want to take the input string sss of "update" to use in: writeFile
"myFile.txt" sss of function "main" and get the value zzz from "main"
to assign for the value return of "update". I think I need to change
the way to declare two functions to get what I want, but I do not know
how.

update :: String -> String
update sss = zzz

main = do writeFile "myFile.txt" sss
   x <- callSystem "myFile.txt"
   y <- openFile "result.txt" ReadMode
   zzz <- hGetContents y
   return zzz


I do not quite get what you want to accomplish. Is it something like  
this?


  update   :: String -> IO String
  update s =  do
writeFile "myFile.txt" sss
callSystem "myFile.txt"
z <- readFile "result.txt"
return z

Note that update produces a value of type IO String now: in Haskell  
98, there is no escape from the IO monad.


Chances are that the above is not what you want. Can you then please  
explain one more time what it is what you're after?


Cheers,

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


Re: [Haskell-cafe] Newbied question on IO Monad

2006-09-12 Thread Sara Kenedy

Hello,

Maybe what I talk is not clear.

I want to take the input string sss of "update" to use in: writeFile
"myFile.txt" sss of function "main" and get the value zzz from "main"
to assign for the value return of "update". I think I need to change
the way to declare two functions to get what I want, but I do not know
how.

update :: String -> String
update sss = zzz

main = do writeFile "myFile.txt" sss
   x <- callSystem "myFile.txt"
   y <- openFile "result.txt" ReadMode
   zzz <- hGetContents y
   return zzz

S.

On 9/12/06, Andrea Rossato <[EMAIL PROTECTED]> wrote:

Il Tue, Sep 12, 2006 at 08:05:42AM -0400, Sara Kenedy ebbe a scrivere:
> Hello all,
>
> update :: String -> String
> update sss = ...
>
>
> main = do writeFile "myFile.txt" sss
>x <- callSystem "myFile.txt"
>y <- openFile "result.txt" ReadMode
>zzz <- hGetContents y
>return zzz
>
>
> I know that function main returns IO String, function update returns
> String. And my purpose is to get the string zzz from main for the
> value return of function update. But I do not know which way I can do.

Did you mean something like this?

update :: String -> String
update sss = "Hi! " ++ sss

main = do writeFile "myFile.txt" $ update "What are you trying to do?"
  x <- callSystem "myFile.txt"
  y <- openFile "result.txt" ReadMode
  zzz <- hGetContents y
  return zzz

In this case main :: IO String so you will not see any output (quite
useless).
I'd suggest you to have a look at this tutorial that explain quite
well the IO Monad:
http://haskell.org/haskellwiki/IO_inside

Ciao
Andrea
___
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] Newbied question on IO Monad

2006-09-12 Thread Andrea Rossato
Il Tue, Sep 12, 2006 at 08:05:42AM -0400, Sara Kenedy ebbe a scrivere:
> Hello all,
> 
> update :: String -> String
> update sss = ...
> 
> 
> main = do writeFile "myFile.txt" sss
>x <- callSystem "myFile.txt"
>y <- openFile "result.txt" ReadMode
>zzz <- hGetContents y
>return zzz
> 
> 
> I know that function main returns IO String, function update returns
> String. And my purpose is to get the string zzz from main for the
> value return of function update. But I do not know which way I can do.

Did you mean something like this?

update :: String -> String
update sss = "Hi! " ++ sss

main = do writeFile "myFile.txt" $ update "What are you trying to do?"
  x <- callSystem "myFile.txt"
  y <- openFile "result.txt" ReadMode
  zzz <- hGetContents y
  return zzz

In this case main :: IO String so you will not see any output (quite
useless).
I'd suggest you to have a look at this tutorial that explain quite
well the IO Monad:
http://haskell.org/haskellwiki/IO_inside

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


[Haskell-cafe] Serialising types with existential data constructors

2006-09-12 Thread Misha Aizatulin
hello all,

  I've been using existentially quantified data constructors like

> data Box = forall a. Cxt a => Box a

  quite successfully for a while. But now I am trying to implement the
Load/Save mechanism and getting stuck with that. It's not hard to write
a Box into a file, but how do I get it back?

  Has anyone solved the same problem before? I would be very thankful
for any suggestions!

  If Template Haskell would support finding out all instances of a given
class, I could generate a function that would map Names of types to
appropriate Box readers. In the file I would write entries like
 : 

  But sadly, TH doesn't allow that yet.

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


Re: [Haskell-cafe] Newbied question on IO Monad

2006-09-12 Thread Henning Thielemann

On Tue, 12 Sep 2006, Sara Kenedy wrote:

> update :: String -> String
> update sss = ...
> 
> 
> main = do writeFile "myFile.txt" sss
>x <- callSystem "myFile.txt"
>y <- openFile "result.txt" ReadMode
>zzz <- hGetContents y
>return zzz
> 
> 
> I know that function main returns IO String, function update returns
> String. And my purpose is to get the string zzz from main for the
> value return of function update. But I do not know which way I can do.

http://haskell.org/hawiki/ThatAnnoyingIoType

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


Re: [Haskell-cafe] Newbied question on IO Monad

2006-09-12 Thread Neil Mitchell

Hi


I know that function main returns IO String

Nope, main must return IO ().

Perhaps you want a putStrLn zzz so you can see the result?

Thanks

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


[Haskell-cafe] Newbied question on IO Monad

2006-09-12 Thread Sara Kenedy

Hello all,

update :: String -> String
update sss = ...


main = do writeFile "myFile.txt" sss
   x <- callSystem "myFile.txt"
   y <- openFile "result.txt" ReadMode
   zzz <- hGetContents y
   return zzz


I know that function main returns IO String, function update returns
String. And my purpose is to get the string zzz from main for the
value return of function update. But I do not know which way I can do.

Sorry if the question seems ridiculous. Thanks for any help.

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


[Haskell-cafe] RE: [Haskell] Re: H/Direct (HaskellDirect) still maintained?

2006-09-12 Thread Simon Marlow
On 08 September 2006 17:35, Andreas Marth wrote:

> Now that I used a more recent ghc (6.4.2 which has cabal-1.1.4
> installed) I did install comlib with it.
> But I am a bit surprised because it did not generate a ihc. So how do
> I get a Proxy from an idl-file now?
>
> If I look at the files in vsHaskell they state "Automatically
> generated by HaskellDirect (ihc.exe) ".
> Does anybody know how to generate ihc.exe?

comlib is just the COM interface library, it doesn't include ihc (the
IDL compiler, which is part of H/Direct).

Some of the the Visual Haskell sources were originally generated by ihc,
but since then we have modified the sources by hand, and we're no longer
using ihc.  You should be able to use these files as example code to see
how to write your COM interface code.  It's a lot of tedious
boilerplate, unfortunately.  Maybe someone will resurrect or write a
replacement for ihc someday.

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


[Haskell-cafe] Weak pointers and referential transparency???

2006-09-12 Thread tpledger
Brian Hulley wrote:
[...]
> Ref.write proxiesRef $! (weakProxy : proxies)

(This is nothing to do with your main question, but the
strict application looks unnecessary there.  Its right hand
side is already a constructor cell.)

[...]
> In other words, if the entry for the proxy
> in the table stored in the Model dies, can
> I be absolutely 100% sure that this means
> the proxy no longer exists in any shape or
> form in the running program?

My reading of the semantics
(http://haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#4)
is that you can be sure the proxy *object* is gone.

As for referential transparency...

Fan-in:
If you create equivalent proxies in different calls to
createProxy, it's possible that they'll end up referring to
the same object (e.g. if the compiler or RTS does something
fancy, or you use a memoised smart constructor).  So then a
single live proxy object *could* protect many elements of
your Weak Proxy list from scavenging.

Fan-out:
It would seem perverse to cry "referential transparency!"
and spontaneously clone one of your proxy objects.  That
*could* lead to deRefWeak returning Nothing while an
*equivalent* Proxy object is still alive.  Might you run
your program on an avant-garde distributed RTS?  ;-)

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