-, : Set Data.Set . fillTree, , :
import qualified Data.Set as Set
import Data.Set (Set)
fillSet :: Int -> Set Int -> Set Int
fillSet 10000 set = set
fillSet x set = let a = Set.insert x set
in fillSet (x + 1) a
fillSet 1 Set.empty GHCi, , , , . , , -, , .
, Data.Set.Set , , . - .. - . Data.Set.Set , .
Set:
data Set a = Tip
| Bin {-
, , , .
Data.Set ; .
, . :
toList EmptyTree = []
toList (Node x l r) = toList l ++ [x] ++ toList r
main = print . sum . toList $ fillTree 1 EmptyTree
, , , . , , , , , . :
runhaskell, GHCi:
real 1m36.055s
user 0m0.093s
sys 0m0.062s
ghc --make -O0:
real 0m3.904s
user 0m0.030s
sys 0m0.031s
ghc --make -O2:
real 0m1.765s
user 0m0.015s
sys 0m0.030s
Data.Set :
: GHCi - .