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 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? modifySTRef looks like thi

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

2011-11-18 Thread Duncan Coutts
On 18 November 2011 13:17, Daniel Fischer 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 be evaluated strictly? >

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 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 > On Friday 18 November 2011, 11:18:33, Yves Parès wrote: >

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 > On Friday 18 November 2011, 11:18:33, Yves Parès wrote: > > Instead of rewriting modifySTRef, why not just do : > > > > modifySTRef

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 demande

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 > On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek wrote: > >> diff --git a/Rebuild.hs b/Rebuild.hs >> @@ -15,6 +15,7 @@ import Data.STRe

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

2011-11-17 Thread Jason Dusek
2011/11/16 Tristan Ravitch : > 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 convert that pure

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

2011-11-17 Thread Jason Dusek
2011/11/16 Johan Tibell : > On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek wrote: >> Tried a modifySTRef' defined this way: >> >> modifySTRef' ref f           =  do >>  val                       <-  (f $!!) <$> readSTRef ref >>  writeSTRef ref (val `seq` val) >> >> ...but there was no change in memo

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

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 2:23 PM, Jason Dusek 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 > > Tried

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

2011-11-16 Thread Jason Dusek
2011/11/16 Johan Tibell : > On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell 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 application before calling writeSTRef. > >

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 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 > >

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

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 12:33 PM, Antoine Latter 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 be strict in th

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 wrote: > On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell wrote: > > > > > >

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

2011-11-16 Thread Antoine Latter
On Wed, Nov 16, 2011 at 2:16 PM, Johan Tibell wrote: > On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell > wrote: >> >> On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek >> wrote: >>> >>> diff --git a/Rebuild.hs b/Rebuild.hs >>> @@ -15,6 +15,7 @@ import Data.STRef >>>  import Data.String >>>  import Da

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 wo

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

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 12:07 PM, Johan Tibell wrote: > On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek 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 (Ve

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 : > > On Tue, Nov 15, 2011 at 12:08 PM, Jason Dusek wrote: > >> Should I be annotating my functions with strictness, for the > >> vector reference, for example? Should I be using STUArrays, > >> instead? > > > >

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

2011-11-16 Thread Johan Tibell
On Wed, Nov 16, 2011 at 11:58 AM, Jason Dusek 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 Vector (create,

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

2011-11-16 Thread Jason Dusek
2011/11/15 Johan Tibell : > On Tue, Nov 15, 2011 at 12:08 PM, Jason Dusek wrote: >> Should I be annotating my functions with strictness, for the >> vector reference, for example? Should I be using STUArrays, >> instead? > > From > http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.4.1.0/

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

2011-11-16 Thread Jason Dusek
2011/11/15 Roman Cheplyaka : > * Jason Dusek [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 o

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 wrote: > Should I be annotating my functions with strictness, for the > vector reference, for example? Should I be using STUArrays, > instead? > From http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.4.1.0/Control-Monad-ST-Safe.

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

2011-11-15 Thread Roman Cheplyaka
* Jason Dusek [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 to a > vector, us

[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 thi