
Ah, I'm talking nonsense. Ignore me.
On 28 February 2015 at 20:56, Christopher Done
You could have class IsWord8 a instance IsWord8 Word8 instance (IsWord8 a) => Functor (ByteString a) where ...
It would be a legitimate instance.
On 28 February 2015 at 20:41, David Feuer
wrote: This is impossible. The type of fmap is
fmap :: Functor f => (a->b) -> f a -> f b
You can use a GADT to effectively restrict what a is, because the caller won't be able to provide a non-bottom f a if a has the wrong type. But the caller can choose absolutely any type for b, and there's nothing you can do about that.
David
On Sat, Feb 28, 2015 at 2:11 PM, silvio
wrote: I have recently heard that some people want to burn bridges (introducing Foldable and Traversable to Prelude) and I've been wondering if it was possible somehow allow Text and Bytestring like containers to make use of those functions. Something along the lines of
import qualified Data.ByteString as BS
newtype ByteString' a = ByteString' BS.ByteString
type ByteString = ByteString' Word8
instance (ByteString' a ~ ByteString' Word8) => Functor (ByteString') where fmap f (ByteString' bs) = ByteString' $ BS.map f bs
Or if DataContexts worked as you would expect.
newtype (Word8 ~ a) => ByteString' a = ByteString' BS.ByteString
However I couldn't find a solution and I was just wondering if it is possible.
P.S. Using GADTS it does actually work for Foldable, but only because it doesn't have to output any ByteStrings. It doesn't work for Functor for instance.
data ByteString' a where ByteString' :: BS.ByteString -> ByteString' Word8
type ByteString = ByteString' Word8
instance Foldable ByteString' where foldr f ini (ByteString' bs) = BS.foldr f ini bs
Silvio _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe