Re: [Haskell-cafe] Re: Text: find

2010-10-17 Thread Luke Palmer
On Sun, Oct 17, 2010 at 4:05 PM, Bryan O'Sullivan  wrote:
> On Sun, Oct 17, 2010 at 1:51 PM, Antoine Latter  wrote:
>>
>> What would the definition of a function of the form:
>>
>> > find :: (Text -> Bool) -> Text -> Maybe Text
>>
>> look like?
>
> Can you be more specific? I assume you mean that the only sensible return
> values are Nothing or the entire Text for which the predicate first returns
> True? (In other words, that this function doesn't actually seem to have a
> useful return type.)

Presumably find has more to do with text than:

find p t = guard (p == t) (Just t)

If you are searching for a... substring(?) then the value of the
matching predicate could be very interesting.  Eg.

findName  = find (all isAlpha)

However, there are n^2 substrings in a string, so this function is
O(P(n)n^2), where P(n) is the complexity of p.  I can't say I would
use such an expensive function very often -- there is usually a more
specific algorithm that does what I need.

Or maybe it finds prefixes?  Then it should be called findPrefix probably.

Oh and what if it finds more than one?  Ordered by starting char?
What if there multiple matches at the same starting char?

So... I don't understand the specification of this function (the
documentation in Data.Text is not very elucidating).

Luke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Text: find

2010-10-17 Thread Bryan O'Sullivan
On Sun, Oct 17, 2010 at 1:51 PM, Antoine Latter  wrote:

>
> What would the definition of a function of the form:
>
> > find :: (Text -> Bool) -> Text -> Maybe Text
>
> look like?
>

Can you be more specific? I assume you mean that the only sensible return
values are Nothing or the entire Text for which the predicate first returns
True? (In other words, that this function doesn't actually seem to have a
useful return type.)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe