Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit d74c278

Browse files
committed
Fix some compile errors
1 parent 74c05d4 commit d74c278

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"package.json"
2323
],
2424
"dependencies": {
25-
"purescript-maps": "^0.5.0"
25+
"purescript-maps": "^0.5.0",
26+
"purescript-tailrec": "^0.3.1"
2627
},
2728
"devDependencies": {
2829
"purescript-assert": "~0.1.1",

docs/Data/Set.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,30 @@ difference :: forall a. (Ord a) => Set a -> Set a -> Set a
139139

140140
Form the set difference
141141

142+
#### `subset`
143+
144+
``` purescript
145+
subset :: forall a. (Ord a) => Set a -> Set a -> Boolean
146+
```
147+
148+
True if and only if every element in the first set
149+
is an element of the second set
150+
151+
#### `properSubset`
152+
153+
``` purescript
154+
properSubset :: forall a. (Ord a) => Set a -> Set a -> Boolean
155+
```
156+
157+
True if and only if the first set is a subset of the second set
158+
and the sets are not equal
159+
160+
#### `intersection`
161+
162+
``` purescript
163+
intersection :: forall a. (Ord a) => Set a -> Set a -> Set a
164+
```
165+
166+
The set of elements which are in both the first and second set
167+
142168

src/Data/Set.purs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ import qualified Data.Map as M
3535
import Control.Monad.Eff (runPure, Eff())
3636
import Control.Monad.ST (ST())
3737
import Control.Monad.Rec.Class (tailRecM2)
38-
import Data.Array (map, nub, length)
38+
import Data.Array (nub, length)
3939
import Data.Array.ST
40+
import Data.Array.Unsafe (unsafeIndex)
41+
import qualified Data.List as List
4042
import Data.Either
4143
import Data.Maybe
4244
import Data.Tuple
4345
import Data.Foldable (foldl)
44-
import Prelude.Unsafe (unsafeIndex)
4546

4647
-- | `Set a` represents a set of values of type `a`
4748
data Set a = Set (M.Map a Unit)
@@ -138,9 +139,9 @@ properSubset s1 s2 = subset s1 s2 && (s1 /= s2)
138139

139140
-- | The set of elements which are in both the first and second set
140141
intersection :: forall a. (Ord a) => Set a -> Set a -> Set a
141-
intersection s1 s2 = fromList $ runPure (runSTArray (emptySTArray >>= intersect)) where
142-
ls = toList s1
143-
rs = toList s2
142+
intersection s1 s2 = fromArray $ runPure (runSTArray (emptySTArray >>= intersect)) where
143+
ls = toArray s1
144+
rs = toArray s2
144145
ll = length ls
145146
rl = length rs
146147
intersect :: forall h r. STArray h a -> Eff (st :: ST h | r) (STArray h a)
@@ -154,3 +155,9 @@ intersection s1 s2 = fromList $ runPure (runSTArray (emptySTArray >>= intersect)
154155
LT -> pure $ Left {a: l + 1, b: r}
155156
GT -> pure $ Left {a: l, b: r + 1}
156157
else pure $ Right acc
158+
159+
toArray :: forall a. (Ord a) => Set a -> Array a
160+
toArray = List.fromList <<< toList
161+
162+
fromArray :: forall a. (Ord a) => Array a -> Set a
163+
fromArray = fromList <<< List.toList

0 commit comments

Comments
 (0)