Skip to content

Commit a12c7c5

Browse files
author
Jaro Reinders
committed
Fix docs and example
1 parent 35640dd commit a12c7c5

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

bench/Quicksort.hs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,15 @@
22
module Quicksort (quicksort) where
33

44
import Fleet.Array
5-
import Data.Tuple (Solo (..))
6-
7-
-- swap :: Int -> Int -> Array a -> Array a
8-
-- swap !i !j !xs = set i (xs ! j) (set j (xs ! i) xs)
9-
10-
-- swap :: Int -> Int -> Array a -> Array a
11-
-- swap !i !j !xs =
12-
-- let
13-
-- -- using this strict matching on MkSolo we
14-
-- -- can ensure that the indexing happens
15-
-- -- before the mutation (which would slow
16-
-- -- down the indexing)
17-
-- !(MkSolo x) = index i xs
18-
-- !(MkSolo y) = index j xs
19-
-- in set i y (set j x xs)
5+
import Data.Tuple (Solo (MkSolo))
206

217
{-# INLINEABLE quicksort #-}
228
quicksort :: Ord a => Int -> Int -> Array a -> Array a
239
quicksort !l !r !xs
2410
| r - l <= 1 = xs
2511
| otherwise =
26-
let !(MkSolo x) = index (r - 1) xs in
27-
case partition l (r - 1) xs x of
12+
let x@(MkSolo x') = index (r - 1) xs in
13+
x `pseq` case partition l (r - 1) xs x' of
2814
(xs, m) -> quicksort l m (quicksort (m + 1) r (swap (r - 1) m xs))
2915

3016
{-# INLINEABLE partition #-}

src/Fleet/Array.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ toList (A v) = unsafeDupablePerformIO $ do
121121
--
122122
-- > swap !i !j !xs =
123123
-- > let
124-
-- > x = index i xs
125-
-- > y = index j xs
126-
-- > in x `pseq` y `pseq` set i (getSolo y) (set j (getSolo x) xs)
124+
-- > x@(MkSolo x') = index i xs
125+
-- > y@(MkSolo y') = index j xs
126+
-- > in x `pseq` y `pseq` set i y' (set j x' xs)
127127
--
128128
-- In the future, we hope to write a GHC plugin that can automatically detect
129129
-- when pseq is necessary in common cases.

0 commit comments

Comments
 (0)