[Haskell-cafe] stack overflow when using ST monad

Brian Hulley brianh at metamilk.com
Thu Aug 24 08:16:41 EDT 2006


Gregory Wright wrote:
> -- A structure with internal state:
> --
> data Tag s = Tag {
>         tagID :: Int,
>         state :: STRef s TagState,
>         count :: STRef s Integer
> }
>
>
> data FrozenTag = FrozenTag {
>         ft_tagID :: Int,
>         ft_state :: TagState,
>         ft_count :: Integer
> } deriving Show

I would make all the fields strict here, to be sure that no lazyness can 
creep about unseen eg:

     data Tag s = Tag {
         tagID :: !Int,
         state :: !(STRef s TagState),
         count :: !(STRef s Integer)
   }

   -- ditto for FrozenTag

(And use (writeSTRef ref $! value) as others have suggested)

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 



More information about the Haskell-Cafe mailing list