It so happens that you can make a set data type that is a Monad, but it&#39;s not exactly the best possible sets.<div><br></div><div><div>module SetMonad where</div><div><br></div><div>newtype Set a = Set { unSet :: [a] }</div>
<div><br></div><div>singleton :: a -&gt; Set a</div><div>singleton x = Set [x]</div><div><br></div><div>unions :: [Set a] -&gt; Set a</div><div>unions ss = Set $ concatMap unSet ss</div><div><br></div><div>member :: (Eq a) =&gt; a -&gt; Set a -&gt; Bool</div>
<div>member x s = x `elem` unSet s</div><div><br></div><div>instance Monad Set where</div><div>    return = singleton</div><div>    x &gt;&gt;= f = unions (map f (unSet x))</div><div><br></div><br><div class="gmail_quote">
On Sat, Jan 8, 2011 at 9:28 PM, Peter Padawitz <span dir="ltr">&lt;<a href="mailto:peter.padawitz@udo.edu">peter.padawitz@udo.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
is there any way to instantiate m in Monad m with a set datatype in order to implement the usual powerset monad?<br>
<br>
My straightforward attempt failed because the bind operator of this instance requires the Eq constraint on the argument types of m.<br>
<br>
Peter<br>
<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>