diff options
author | David Terei <davidterei@gmail.com> | 2011-07-20 11:09:03 -0700 |
---|---|---|
committer | David Terei <davidterei@gmail.com> | 2011-07-20 11:26:35 -0700 |
commit | 16514f272fb42af6e9c7674a9bd6c9dce369231f (patch) | |
tree | e4f332b45fe65e2a7a2451be5674f887b42bf199 /testsuite/tests/perf/should_run/T2902_B_PairingSum.hs | |
parent | ebd422aed41048476aa61dd4c520d43becd78682 (diff) | |
download | haskell-16514f272fb42af6e9c7674a9bd6c9dce369231f.tar.gz |
Move tests from tests/ghc-regress/* to just tests/*
Diffstat (limited to 'testsuite/tests/perf/should_run/T2902_B_PairingSum.hs')
-rw-r--r-- | testsuite/tests/perf/should_run/T2902_B_PairingSum.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/testsuite/tests/perf/should_run/T2902_B_PairingSum.hs b/testsuite/tests/perf/should_run/T2902_B_PairingSum.hs new file mode 100644 index 0000000000..5276da818b --- /dev/null +++ b/testsuite/tests/perf/should_run/T2902_B_PairingSum.hs @@ -0,0 +1,37 @@ + +{-# LANGUAGE UnicodeSyntax, MultiParamTypeClasses, FlexibleInstances #-} + +module T2902_B_PairingSum (Sum(..), PSum) where + +import T2902_Sum + +data PSum a b = Empty | Tree a b [PSum a b] + +instance (Ord a, Num b) ⇒ Sum PSum a b where + + insert v r = union $ Tree v r [] + + union x Empty = x + union Empty x = x + union x@(Tree v r xs) y@(Tree w s ys) = + case compare v w of + LT → Tree v r (y:xs) + GT → Tree w s (x:ys) + EQ → case r + s of + 0 → z + t → insert v t z + where z = union (unions xs) (unions ys) + + unions [] = Empty + unions [x] = x + unions (x : y : zs) = union (union x y) (unions zs) + + extractMin Empty = undefined + extractMin (Tree v r xs) = ((v,r), unions xs) + + fromList [] = Empty + fromList ((v,r):xs) = insert v r $ fromList xs + + toList Empty = [] + toList x = let (y, z) = extractMin x in y : toList z + |