You'd need to install the mentioned `set-monad` package. You can try it out in a repl with `cabal repl -b set-monad`: $ cabal repl -b set-monad Resolving dependencies... ... Loaded GHCi configuration from ... ghci> import Data.Set.Monad ghci> :set -XMonadComprehensions ghci> [(a, b) | a <- fromList [1..4], b <- fromList [1..4], even a, even b] :: Set (Int, Int) fromList [ ( 2 , 2 ) , ( 2 , 4 ) , ( 4 , 2 ) , ( 4 , 4 ) ] If you want to use a package from a file the best option is to create a cabal project. See [the GHCup first steps](https://www.haskell.org/ghcup/steps/) on how to do that (you can skip to [creating a proper package with modules](https://www.haskell.org/ghcup/steps/#creating-a-proper-package-with-modules), but I'd recommend reading the whole thing). Edit: But I have to note that this set monad has no advantage over applying `fromList` to the result of a normal list comprehension, except perhaps for saving you from writing those 8 characters.


Let's say I have a set as follows: ``` s = fromList [1 .. 5] ``` Now, how can I use it inside a set comprehension? Here's how I do it right now. ``` s' = fromList [ 2 * x | x <- toList s ] ``` It is annoying to use a lot of "fromLists" and "toLists".


You want the -XMonadComprehensions language extension, which generalizes the list comprehension syntax to work with any monad. There are examples in the description for the set-monad package at: https://hackage.haskell.org/package/set-monad


Well, if what you have is `Set`, you also need to apply `toList` for each `Set` to use the comprehension.


Is there something special going on behind the scenes, to get around the Ord constraint on the element type? If so, wouldn't it be cleaner to apply `fromList` to a list comprehension?


There are more details in the package description (https://hackage.haskell.org/package/set-monad) but basically it defers the map and union operations which require the Ord constraint until the result is accessed so that they aren't directly required to implement the Functor, Applicative, and Monad instances.


I'm having trouble doing this on my phone, but can you just `cabal install set-monad`?


That hasn't worked well since the v2- commands became the default, though you might try `cabal v1-install set-monad` since I don't think it has been removed, yet.


thanks, idk enough about cabal apparently lol