<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7653.38">
<TITLE>RE: [Haskell-cafe] Searching for ADT patterns with elem and find</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Thanks Neil,<BR>
<BR>
Great. I hadn't noticed &quot;isJust&quot;, and I'd forgotten &quot;any&quot;. Actually I was browsing Prelude just the other day and picked up &quot;zipWith f as bs&quot; as a replacement for &quot;map f $ zip as bs&quot;.<BR>
<BR>
Cheers, Paul<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: Mitchell, Neil [<A HREF="mailto:neil.mitchell.2@credit-suisse.com">mailto:neil.mitchell.2@credit-suisse.com</A>]<BR>
Sent: Wed 12/11/2008 10:23<BR>
To: Paul Keir; haskell-cafe@haskell.org<BR>
Subject: RE: [Haskell-cafe] Searching for ADT patterns with elem and find<BR>
<BR>
Hi Paul,<BR>
<BR>
maybe False (\x -&gt; True) (find isTypeB ts)<BR>
<BR>
This can be more neatly expressed as:<BR>
<BR>
isJust (find isTypeB ts)<BR>
<BR>
But your entire thing can be expressed as:<BR>
<BR>
containsTypeB ts = any isTypeB ts<BR>
<BR>
I recommend reading through the Prelude interface and the List<BR>
interface, it has many useful functions that will help.<BR>
<BR>
Thanks<BR>
<BR>
Neil<BR>
<BR>
<BR>
<BR>
________________________________<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; From: haskell-cafe-bounces@haskell.org<BR>
[<A HREF="mailto:haskell-cafe-bounces@haskell.org">mailto:haskell-cafe-bounces@haskell.org</A>] On Behalf Of Paul Keir<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sent: 12 November 2008 10:09 am<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To: haskell-cafe@haskell.org<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Subject: [Haskell-cafe] Searching for ADT patterns with elem and<BR>
find<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hi All,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If I have an ADT, say<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data T<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = A String Integer<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | B Double<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | C<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deriving(Eq)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and I want to find if a list (ts) of type T contains an element<BR>
of subtype &quot;B Double&quot;, must my &quot;containsTypeX&quot; function use a second<BR>
&quot;isTypeX&quot; function as follows:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isTypeB :: T -&gt; Bool<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isTypeB (B _) = True<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isTypeB _&nbsp;&nbsp;&nbsp;&nbsp; = False<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; containsTypeB :: [T] -&gt; Bool<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; containsTypeB ts = maybe False (\x -&gt; True) (find isTypeB ts)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I understand that while something like &quot;find C ts&quot; will work,<BR>
&quot;find (isTypeB _) ts&quot; will not, but is there no such thing as a pattern<BR>
combinator(?), or lambda that could help with this situation. I find I<BR>
have many individual &quot;isTypeB&quot; functions now.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Regards,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Paul<BR>
<BR>
<BR>
==============================================================================<BR>
Please access the attached hyperlink for an important electronic communications disclaimer:<BR>
<BR>
<A HREF="http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html">http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html</A><BR>
==============================================================================<BR>
<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>