<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Searching for ADT patterns with elem and find</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3429" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>Hi Paul,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008><FONT face="Times New Roman" color=#000000>maybe False
(\x -> True) (find isTypeB ts)</FONT><BR></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>This can be more neatly expressed
as:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>isJust (find isTypeB ts)</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>But your entire thing can be expressed
as:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>containsTypeB ts = any isTypeB ts</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>I recommend reading through the Prelude interface and
the List interface, it has many useful functions that will
help.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>Thanks</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008>Neil</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=115162110-12112008> </DIV></SPAN></FONT><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> haskell-cafe-bounces@haskell.org
[mailto:haskell-cafe-bounces@haskell.org] <B>On Behalf Of </B>Paul
Keir<BR><B>Sent:</B> 12 November 2008 10:09 am<BR><B>To:</B>
haskell-cafe@haskell.org<BR><B>Subject:</B> [Haskell-cafe] Searching for ADT
patterns with elem and find<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/plain format -->
<P><FONT size=2>Hi All,<BR><BR>If I have an ADT, say<BR><BR>data T<BR> =
A String Integer<BR> | B Double<BR> |
C<BR> deriving(Eq)<BR><BR>and I want to find if a list (ts) of type T
contains an element of subtype "B Double", must my "containsTypeX" function
use a second "isTypeX" function as follows:<BR><BR>isTypeB :: T ->
Bool<BR>isTypeB (B _) = True<BR>isTypeB _ =
False<BR><BR>containsTypeB :: [T] -> Bool<BR>containsTypeB ts = maybe False
(\x -> True) (find isTypeB ts)<BR><BR>I understand that while something
like "find C ts" will work, "find (isTypeB _) ts" will not, but is there no
such thing as a pattern combinator(?), or lambda that could help with this
situation. I find I have many individual "isTypeB" functions
now.<BR><BR>Regards,<BR>Paul</FONT> </P></BLOCKQUOTE>
<P><pre wrap>==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================
</pre></P></BODY></HTML>