[Haskell-cafe] needsaname :: ([a] -> Maybe (b,
[a])) -> (b -> [a]) -> [a] -> [a]
Donald Bruce Stewart
dons at cse.unsw.edu.au
Fri Jul 6 23:27:08 EDT 2007
felipe.lessa:
> >I've written it to run over lists, but it would not be difficult to
> >make it run over ByteStrings instead, and exploit the 'no-copying'
> >effect on the bits of the stream which were not modified, which would
> >be very handy for programs processing large bytestrings.
>
> I wonder if there's a efficient way of writting generic code that runs
> over String or over ByteString? Or at least with Lazy and Strict
> ByteStrings?
>
>
>
> I mean, I can write something like
>
> double :: Num a => a -> a
> double x = x * 2
>
> and, e.g. if I want speed on Doubles (and am using GHC)
>
> {-# SPECIALIZE double :: Double -> Double #-}
>
> but AFAIK there isn't a way of doing so with all the string types?
>
>
> And, if we're really lacking these mechanisms, is it because of a lack
> of formulation or because it isn't possible to generalise String
> operations?
>
>
> Thanks! =)
>
The String API seems rather large, so finding a single type class to
encapsulate expected operations tends to produce big, unwieldly classes.
Smaller apis work though: Monoid, for example.
-- Don
More information about the Haskell-Cafe
mailing list