I finished a draft version of pipes-text with 
the 'lens' approach.  

    https://github.com/michaelt/text-pipes/tree/master/Pipes

I think I am following
Gabriels advice above, more or less, by 
just giving functions like 

     encodeIso8859_1 :: Monad m 
                               => Producer Text m r 
                               -> Producer ByteString m (Producer Text m r)
     decodeAscii :: Monad m 
                         => Producer ByteString m r 
                         -> Producer Text m (Producer ByteString m r)

in each direction. For utf8 there is a 
Lens of the type we wanted 

      decodeUtf8 :: Monad m 
                       => Lens' (Producer ByteString m r) 
                                    (Producer Text m (Producer ByteString m 
r))

At the moment for I am replicating
the method of the enumerator and 
conduit packages in defining  `Codecs` 
`utf16_le` ,  `utf16_be` , `utf32_le` , 
`utf32_be` and then a function that 
makes a Lens' for them

     codec :: Monad m 
               => Codec 
               -> Lens' (Producer ByteString m r) 
                            (Producer Text m (Producer ByteString m r))

(there is also such a `Codec` for utf8).

In all cases, we do without the customary 
`Text` exception system.  When decoding or 
encoding of a `Producer ByteString ...` or 
`Producer Text ...` goes wrong, we simply 
return the remaining Producer we are 
encoding or decoding. Or that is what I think
I am doing. I can't tell if it's insane or not.

I was thinking of replacing the `Codecs` with 
a series of  individual lenses later; I am for 
the moment using them to take advantage of
the presumed correctness of the code 
I am modifying. (I don't like the way 
the original code is written, but no matter for
the moment.)

I decided that all IO in the module should 
be `Pipes.Prelude` -like in character and
that this should be emphasized.
Everything is done on the basis of 
things in `Data.Text.IO` and the like; 
it all uses `Text`'s exception machinery
and is a little slow. 

So I will advertise that `Pipes.ByteString` 
and co. defines the "real" IO operations, 
which are about 3 times as fast, and 
which we textify with `encodeUtf8` 
and `decodeUtf8` and the like.

I was wondering if the 'api' of the `Pipes.Text` 
module now seems more or less what is desirable 
so I could hackage it pretty soon as version 0.0.0   
(The way some things are implemented 
is perhaps objectionable, except where I
am replicating `Pipes.ByteString`) 

yours ever, Michael

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to