[Haskell-cafe] Using streams to clarify (?) the signature of Data.Text.replace

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sun Jun 26 21:53:26 UTC 2016


(Apologies if you receive this twice, but it seems my previous attempt
was sent to a non-existent Google Group rather than Cafe :s)

On 27 June 2016 at 00:39, Daniel Díaz <diaz.carrete at gmail.com> wrote:
> In the "text" package, the signature of Data.Text.replace always sends me
> looking into the haddocks:
>
>> replace :: Text -> Text -> Text -> Text
>
>
> Which argument is the text to replace, which is the replacement and which is
> the text that should be scanned?
>
> Imagine a generalized version of replace that 1) works on streams, and 2)
> allows replacing a sequence of texts (like, say, chapter headers) instead of
> replacing the same text repeatedly. It could have the following signature:
>
>> replace' :: Stream (Stream (Of Text) m) m ()
>>             -> Stream (Stream (Of Text) m) m Void
>>             -> Stream (Of Text) m r
>>             -> Stream (Of Text) m r
>
>
> Do you find easy to intuit, just by looking at that signature, which is the
> function of each argument?

Whilst this type signature is easier to intuit which is the actual
text in which the replacement is occurring, it gives me no clues as to
which of the first two arguments is the text to search for and which
is the replacement.

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list