<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> <BR>Yes my function operate only in a set-theory contest and your solution:<BR> <BR>subset xs ys = all (`elem` ys) xs<BR> <BR>is indeed more elegant than mine.<BR> <BR>Thanks again for your help.<BR> <BR>Luca.<BR> <BR>> From: daniel.is.fischer@web.de<BR>> To: beginners@haskell.org<BR>> Subject: Re: [Haskell-beginners] subset - a little add<BR>> Date: Fri, 29 Jan 2010 10:06:29 +0100<BR>> CC: luca_ciciriello@hotmail.com<BR>> <BR>> Am Freitag 29 Januar 2010 08:36:35 schrieb Luca Ciciriello:<BR>> > Just a little add to may previous mail.<BR>> ><BR>> > The solution I've found from myself is:<BR>> ><BR>> ><BR>> ><BR>> > subset :: [String] -> [String] -> Bool<BR>> > subset xs ys = and [elem x ys | x <- xs]<BR>> ><BR>> <BR>> Variant:<BR>> <BR>> subset xs ys = all (`elem` ys) xs<BR>> <BR>> but is that really what you want? That says subset [1,1,1,1] [1] ~> True.<BR>> If you regard your lists as representatives of sets (as the name suggests), <BR>> then that's correct, otherwise not.<BR>> <BR>> However, this is O(length xs * length ys). If you need it only for types <BR>> belonging to Ord, a much better way is<BR>> <BR>> import qualified Data.Set as Set<BR>> import Data.Set (fromList, isSubsetOf, ...)<BR>> <BR>> subset xs ys = fromList xs `isSubsetOf` fromList ys<BR>> <BR>> or, if you don't want to depend on Data.Set,<BR>> <BR>> subset xs ys = sort xs `isOrderedSublistOf` sort ys<BR>> <BR>> xxs@(x:xs) `isOrderedSublistOf` (y:ys)<BR>> | x < y = False<BR>> | x == y = xs `isOrderedSublistOf` ys<BR>> | otherwise = xxs `isOrderedSublistOf` ys<BR>> [] `isOrderedSublistOf` _ = True<BR>> _ `isOrderedSublistOf` [] = False<BR>> <BR>> ><BR>> ><BR>> > My question is if exists a more elegant way to do that.<BR>> ><BR>> ><BR>> ><BR>> > Luca.<BR>> <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>