Re: [Haskell-cafe] ST not strict enough?

2011-11-21 Thread Ryan Ingram
On Fri, Nov 18, 2011 at 4:05 AM, Yves Parès limestr...@gmail.com wrote: (Sorry for the double mail) ...so there is no way to do that inside the function passed to modifySTRef? In other words, there is no way to ensure *inside* a function that its result will be evaluated strictly?

Re: [Haskell-cafe] ST not strict enough?

2011-11-18 Thread Yves Parès
Instead of rewriting modifySTRef, why not just do : modifySTRef counter (\x - let y = x+1 in y `seq` y) Is there a problem with that? 2011/11/16 Johan Tibell johan.tib...@gmail.com On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek jason.du...@gmail.comwrote: diff --git a/Rebuild.hs

Re: [Haskell-cafe] ST not strict enough?

2011-11-18 Thread Daniel Fischer
On Friday 18 November 2011, 11:18:33, Yves Parès wrote: Instead of rewriting modifySTRef, why not just do : modifySTRef counter (\x - let y = x+1 in y `seq` y) Is there a problem with that? Yes, y `seq` y is precisely the same as y. a `seq` b means whenever evaluation of b is demanded,

Re: [Haskell-cafe] ST not strict enough?

2011-11-18 Thread Yves Parès
Okay, thanks I was pretty sure I was wrong (or else somebody would already have come up with that solution), but I wanted to know why. 2011/11/18 Daniel Fischer daniel.is.fisc...@googlemail.com On Friday 18 November 2011, 11:18:33, Yves Parès wrote: Instead of rewriting modifySTRef, why not

Re: [Haskell-cafe] ST not strict enough?

2011-11-18 Thread Yves Parès
(Sorry for the double mail) ...so there is no way to do that inside the function passed to modifySTRef? In other words, there is no way to ensure *inside* a function that its result will be evaluated strictly? 2011/11/18 Daniel Fischer daniel.is.fisc...@googlemail.com On Friday 18 November

Re: [Haskell-cafe] ST not strict enough?

2011-11-18 Thread Daniel Fischer
On Friday 18 November 2011, 13:05:06, Yves Parès wrote: ...so there is no way to do that inside the function passed to modifySTRef? In other words, there is no way to ensure inside a function that its result will be evaluated strictly? Well, modifySTRef ref fun = do val - readSTRef ref

Re: [Haskell-cafe] ST not strict enough?

2011-11-18 Thread Duncan Coutts
On 18 November 2011 13:17, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Friday 18 November 2011, 13:05:06, Yves Parès wrote: ...so there is no way to do that inside the function passed to modifySTRef? In other words, there is no way to ensure inside a function that its result will

Re: [Haskell-cafe] ST not strict enough?

2011-11-17 Thread Jason Dusek
2011/11/16 Johan Tibell johan.tib...@gmail.com: On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek jason.du...@gmail.com wrote: Tried a modifySTRef' defined this way: modifySTRef' ref f           =  do  val                       -  (f $!!) $ readSTRef ref  writeSTRef ref (val `seq` val) ...but

Re: [Haskell-cafe] ST not strict enough?

2011-11-17 Thread Jason Dusek
2011/11/16 Tristan Ravitch travi...@cs.wisc.edu: Have you tried building the vector using things besides write/ST? It might be a bit faster to use something like Vector.unfoldr or Vector.generateM and ByteString.index to build up a pure Vector. After that you could use Vector.unsafeThaw to

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Jason Dusek
2011/11/15 Roman Cheplyaka r...@ro-che.info: * Jason Dusek jason.du...@gmail.com [2011-11-15 20:08:48+] I'm having some trouble with memory usage in rebuilding a ByteString with some sequences escaped. I thought I'd try vectors. However, it seems that even a relatively simple function,

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Jason Dusek
2011/11/15 Johan Tibell johan.tib...@gmail.com: On Tue, Nov 15, 2011 at 12:08 PM, Jason Dusek jason.du...@gmail.com wrote: Should I be annotating my functions with strictness, for the vector reference, for example? Should I be using STUArrays, instead? From

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek jason.du...@gmail.com wrote: diff --git a/Rebuild.hs b/Rebuild.hs @@ -15,6 +15,7 @@ import Data.STRef import Data.String import Data.Word +import Control.DeepSeq import Data.Vector.Unboxed (Vector) import qualified Data.Vector.Unboxed as

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Tristan Ravitch
On Wed, Nov 16, 2011 at 07:58:51PM +, Jason Dusek wrote: 2011/11/15 Johan Tibell johan.tib...@gmail.com: On Tue, Nov 15, 2011 at 12:08 PM, Jason Dusek jason.du...@gmail.com wrote: Should I be annotating my functions with strictness, for the vector reference, for example? Should I be

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell johan.tib...@gmail.comwrote: On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek jason.du...@gmail.comwrote: diff --git a/Rebuild.hs b/Rebuild.hs @@ -15,6 +15,7 @@ import Data.STRef import Data.String import Data.Word +import Control.DeepSeq

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Tristan Ravitch
On Wed, Nov 16, 2011 at 12:16:34PM -0800, Johan Tibell wrote: Just double checked. modifySTRef is too lazy: -- |Mutate the contents of an 'STRef' modifySTRef :: STRef s a - (a - a) - ST s () modifySTRef ref f = writeSTRef ref . f = readSTRef ref We need Data.STRef.Strict That would be

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Antoine Latter
On Wed, Nov 16, 2011 at 2:16 PM, Johan Tibell johan.tib...@gmail.com wrote: On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell johan.tib...@gmail.com wrote: On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek jason.du...@gmail.com wrote: diff --git a/Rebuild.hs b/Rebuild.hs @@ -15,6 +15,7 @@ import

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread tomberek
I ran into a similar problem with modifySTRef causing allocation and GC. Creating my own strict version of modifySTRef got rid of all that and my program ran without any allocation at all. On Nov 16, 3:16 pm, Johan Tibell johan.tib...@gmail.com wrote: On Wed, Nov 16, 2011 at 12:07 PM, Johan

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 12:33 PM, Antoine Latter aslat...@gmail.com wrote: We already have one in base - it re-exports Data.STRef in whole :-) http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-STRef-Strict.html Then it's wrong. :( In what sense is it strict? I think it should

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Daniel Fischer
On Wednesday 16 November 2011, 22:45:16, Johan Tibell wrote: On Wed, Nov 16, 2011 at 12:33 PM, Antoine Latter aslat...@gmail.com wrote: We already have one in base - it re-exports Data.STRef in whole :-) http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-STRef-

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Jason Dusek
2011/11/16 Johan Tibell johan.tib...@gmail.com: On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell johan.tib...@gmail.com wrote: +! doesn't work unless modifySTRef is already strict in the result of the function application. You need to write modifySTRef' that seq:s the result of the function

Re: [Haskell-cafe] ST not strict enough?

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek jason.du...@gmail.com wrote: Just double checked. modifySTRef is too lazy: -- |Mutate the contents of an 'STRef' modifySTRef :: STRef s a - (a - a) - ST s () modifySTRef ref f = writeSTRef ref . f = readSTRef ref We need Data.STRef.Strict

[Haskell-cafe] ST not strict enough?

2011-11-15 Thread Jason Dusek
Hi All, I'm having some trouble with memory usage in rebuilding a ByteString with some sequences escaped. I thought I'd try vectors. However, it seems that even a relatively simple function, one that places all the bytes of a ByteString in to a vector, uses a great deal of memory. I've pulled

Re: [Haskell-cafe] ST not strict enough?

2011-11-15 Thread Roman Cheplyaka
* Jason Dusek jason.du...@gmail.com [2011-11-15 20:08:48+] I'm having some trouble with memory usage in rebuilding a ByteString with some sequences escaped. I thought I'd try vectors. However, it seems that even a relatively simple function, one that places all the bytes of a ByteString in

Re: [Haskell-cafe] ST not strict enough?

2011-11-15 Thread Johan Tibell
Hi Jason, On Tue, Nov 15, 2011 at 12:08 PM, Jason Dusek jason.du...@gmail.com wrote: Should I be annotating my functions with strictness, for the vector reference, for example? Should I be using STUArrays, instead? From