Advertisement
jckuri

DeepSeqDataStructures.hs

May 25th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- DeepSeqDataStructures.hs
  2.  
  3. import qualified Data.Map as DM
  4. import qualified Control.DeepSeq as DS
  5.  
  6. deepseqList list otherValue =
  7.  if length list == 0 then
  8.   otherValue
  9.  else
  10.   (head list) `DS.deepseq` (tail list) `deepseqList` otherValue
  11.  
  12. deepseqMap map otherValue =
  13.  deepseqPairs (DM.toList map) otherValue
  14.  where
  15.   deepseqPair (key,value) otherValue =
  16.    key `DS.deepseq` value `DS.deepseq` otherValue
  17.   deepseqPairs pairs otherValue =
  18.    if length pairs == 0 then
  19.     otherValue
  20.    else
  21.     (head pairs) `deepseqPair` (tail pairs) `deepseqPairs` otherValue
  22.  
  23. {-
  24. Within ghci:    
  25. let x = [1+2,2+3,3+4]
  26. let m = DM.fromList [(1+2,2+3),(3+4,4+5)]
  27. :sprint x
  28. :sprint m
  29. m `deepseqMap` x `deepseqList` ()
  30. :sprint x
  31. :sprint m
  32. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement