Proposal: Improving the IsString String instance

Sjoerd Visscher sjoerd at w3future.com
Sun Aug 25 13:20:17 CEST 2013


This is a great idea! But 'a' may not always be a char-like thing. Maybe chunk is a better name? We could make instances for other string-like types, giving the recommended way to concat a list of string-like things.

class IsStringChunk a where
  fromChunkList :: [a] -> String

instance IsStringChunk Char where
  fromChunkList = id

instance IsStringChunk a => IsString [a] where
  fromString = fromChunkList

Sjoerd

On Aug 25, 2013, at 11:48 AM, Henning Thielemann <schlepptop at henning-thielemann.de> wrote:

> Am 24.08.2013 19:52, schrieb Edward Kmett:
> 
>> I would like to replace this instance with
>> 
>> instance a ~ Char => IsString [a] where
>>   fromString = id
> 
> 
> Your complaint proves my concerns about those FlexibleInstances. The best instance is a Haskell 98 instance:
> 
> 
> class IsCharList a where
>   fromCharList :: [a] -> String
> 
> instance IsCharList Char where
>   fromCharList = id
> 
> instance IsCharList a => IsString [a] where
>   fromString = fromCharList
> 
> 
> This is both the most flexible solution and it is portable.
> 
> http://www.haskell.org/haskellwiki/List_instance
> 
> 
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries





More information about the Libraries mailing list