[Haskell-cafe] Sets and Monads and comprehensions

Graham Klyne gk at ninebynine.org
Tue Jul 20 11:42:24 EDT 2004


A few months ago, there was a discussion here about defining Set to be a 
Monad, starting with:
[1] http://www.haskell.org/pipermail/haskell-cafe/2004-March/005988.html

in response to which, SPJ pointed out that a Set cannot be a Monad:
[2] http://www.haskell.org/pipermail/haskell-cafe/2004-March/005995.html

I found myself treading a path which led me to asking the same question as 
[1].  Given the answer [2], I'd like to stand back a little and ask if 
there's another way to tackle my niggle:  what I'm interested in is a set 
comprehension expression that is analogous to a list comprehension 
expression; e.g. in:

[[
 > import Data.Set
 >
 > type AtomicConcept = String   -- named atomic concept
 > type AtomicRole    = String   -- named atomic role
 >
 > type AtomicConcepts a :: AtomicConcept -> (Set a)
 > type AtomicRoles a    :: AtomicRole    -> (Set (a,a))
 >
 > type Interpretation a :: (Set a,AtomicConcepts a,AtomicRoles a)

...

 > iAL (idom,ic,ir) (ALAll r c)  = mkSet [ a | (a,b) <- setToList (ir r)
 >                                           , b `elementOf` ir c ]
]]

is there a common or similar idiom to achieve the same effect without 
converting the set to a list and back?

I did also find myself wondering if there was a role for unfold (or 
similar) here.

#g


------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact



More information about the Haskell-Cafe mailing list