<!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 "isJust", and I'd forgotten "any". Actually I was browsing Prelude just the other day and picked up "zipWith f as bs" as a replacement for "map f $ zip as bs".<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 -> 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>
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>
Sent: 12 November 2008 10:09 am<BR>
To: haskell-cafe@haskell.org<BR>
Subject: [Haskell-cafe] Searching for ADT patterns with elem and<BR>
find<BR>
<BR>
<BR>
<BR>
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<BR>
of subtype "B Double", must my "containsTypeX" function use a second<BR>
"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,<BR>
"find (isTypeB _) ts" 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 "isTypeB" functions now.<BR>
<BR>
Regards,<BR>
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>