Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DeepSeqDataStructures.hs
- import qualified Data.Map as DM
- import qualified Control.DeepSeq as DS
- deepseqList list otherValue =
- if length list == 0 then
- otherValue
- else
- (head list) `DS.deepseq` (tail list) `deepseqList` otherValue
- deepseqMap map otherValue =
- deepseqPairs (DM.toList map) otherValue
- where
- deepseqPair (key,value) otherValue =
- key `DS.deepseq` value `DS.deepseq` otherValue
- deepseqPairs pairs otherValue =
- if length pairs == 0 then
- otherValue
- else
- (head pairs) `deepseqPair` (tail pairs) `deepseqPairs` otherValue
- {-
- Within ghci:
- let x = [1+2,2+3,3+4]
- let m = DM.fromList [(1+2,2+3),(3+4,4+5)]
- :sprint x
- :sprint m
- m `deepseqMap` x `deepseqList` ()
- :sprint x
- :sprint m
- -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement