<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Thanks Daniel.<BR>&nbsp;<BR>Yes my function operate only in a set-theory contest and your solution:<BR>&nbsp;<BR>subset xs ys = all (`elem` ys) xs<BR>&nbsp;<BR>is&nbsp;indeed more elegant than mine.<BR>&nbsp;<BR>Thanks again for&nbsp;your help.<BR>&nbsp;<BR>Luca.<BR>&nbsp;<BR>&gt; From: daniel.is.fischer@web.de<BR>&gt; To: beginners@haskell.org<BR>&gt; Subject: Re: [Haskell-beginners] subset - a little add<BR>&gt; Date: Fri, 29 Jan 2010 10:06:29 +0100<BR>&gt; CC: luca_ciciriello@hotmail.com<BR>&gt; <BR>&gt; Am Freitag 29 Januar 2010 08:36:35 schrieb Luca Ciciriello:<BR>&gt; &gt; Just a little add to may previous mail.<BR>&gt; &gt;<BR>&gt; &gt; The solution I've found from myself is:<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt; subset :: [String] -&gt; [String] -&gt; Bool<BR>&gt; &gt; subset xs ys = and [elem x ys | x &lt;- xs]<BR>&gt; &gt;<BR>&gt; <BR>&gt; Variant:<BR>&gt; <BR>&gt; subset xs ys = all (`elem` ys) xs<BR>&gt; <BR>&gt; but is that really what you want? That says subset [1,1,1,1] [1] ~&gt; True.<BR>&gt; If you regard your lists as representatives of sets (as the name suggests), <BR>&gt; then that's correct, otherwise not.<BR>&gt; <BR>&gt; However, this is O(length xs * length ys). If you need it only for types <BR>&gt; belonging to Ord, a much better way is<BR>&gt; <BR>&gt; import qualified Data.Set as Set<BR>&gt; import Data.Set (fromList, isSubsetOf, ...)<BR>&gt; <BR>&gt; subset xs ys = fromList xs `isSubsetOf` fromList ys<BR>&gt; <BR>&gt; or, if you don't want to depend on Data.Set,<BR>&gt; <BR>&gt; subset xs ys = sort xs `isOrderedSublistOf` sort ys<BR>&gt; <BR>&gt; xxs@(x:xs) `isOrderedSublistOf` (y:ys)<BR>&gt; | x &lt; y = False<BR>&gt; | x == y = xs `isOrderedSublistOf` ys<BR>&gt; | otherwise = xxs `isOrderedSublistOf` ys<BR>&gt; [] `isOrderedSublistOf` _ = True<BR>&gt; _ `isOrderedSublistOf` [] = False<BR>&gt; <BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt; My question is if exists a more elegant way to do that.<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt;<BR>&gt; &gt; Luca.<BR>&gt; <BR><BR>
<HR>
Not got a Hotmail account? <A href="http://clk.atdmt.com/UKM/go/197222280/direct/01/">Sign-up now - Free</A><BR>                                               <br /><hr />Do you have a story that started on Hotmail? <a href='http://clk.atdmt.com/UKM/go/195013117/direct/01/' target='_new'>Tell us now</a></body>
</html>