Summary and call for discussion on text proposal

Jeremy Shaw jeremy at n-heptane.com
Sun Nov 7 20:59:21 EST 2010


On Nov 7, 2010, at 6:16 PM, wren ng thornton wrote:

> On 11/7/10 12:51 PM, Edward Kmett wrote:
>> On Sun, Nov 7, 2010 at 11:56 AM, Malcolm Wallace<malcolm.wallace at me.com 
>> >wrote:
>>>
>>>  Option 3
>>>> --------
>>>>
>>>> breakStr :: Text           ->  Text ->  (Text, Text)
>>>> breakChr :: (Char ->  Bool) ->  Text ->  (Text, Text)
>
> But also -1 for the random abbreviation. At the very least *Chr  
> should be *Char. Making an abbreviation for a single character is  
> unnecessary, unhelpful, and confusing. For *Str, at least the  
> abbreviation has a meaningful effect in shortening things, but given  
> that we're talking about Text and not String, why not go for *Text  
> which is short, unabbreviated, and matches the type in question.

I would vote for breakText over breakStr because this is a useful  
variant:

 > breakStr :: String          ->  Text ->  (Text, Text)

I generally do not use OverloadedStrings and might define that locally  
to avoid having to call Text.pack a lot.

Also, if breakText has the type

 > breakText :: Text           ->  Text ->  (Text, Text)

Then I would probably expect breakChar to have the type:

 > breakChar :: Char          ->  Text ->  (Text, Text)

So I don't think that naming is really all that consistent.

If Data.List was not in the picture, option 1 certainly seems quite  
sensible.

With Data.List in the picture, option 1 is not going to result in bugs  
in your code, because the type checker will figure out that you are  
doing it wrong. So, the only downside of option 1, IMO,  is that you  
have to remember that Data.Text has a different meaning for break than  
Data.List.  Or put differently, you are going to have to look at the  
documentation to figure out what you want. But with option 3, you have  
to look at the documentation as well, because the names it uses do not  
come from Data.List either. So the gain is not really that significant.

So I vote +0 on option 3. But if it is option 3, I think I would  
rather see:

 > breakText :: Text -> Text -> (Text, Text)
 > breakBy :: (Char -> Bool) -> Text -> (Text, Text)

I would also like to vote -100 for:

Option 4
------------

class Break a where
    break :: a -> Text -> (Text, Text)

instance Break Text where
    break = breakStr

instance Break (Char -> Bool) where
   break = breakChar

Though it does have its charm..

- jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20101107/561558ba/attachment.html


More information about the Libraries mailing list