[Haskell-cafe] Using streams to clarify (?) the signature of Data.Text.replace
Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon Jun 27 00:57:06 UTC 2016
On 27/06/16 2:39 AM, Daniel Díaz wrote:
> In the "text" package, the signature of Data.Text.replace
> <http://hackage.haskell.org/package/text-1.2.2.1/docs/Data-Text.html#v: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?
Considering partial application, the order that makes the most sense is
- what to look for
- what to replace it with
- the big string to search and replace in
I've never used this function. Let's go look at the documentation.
Pats self on back: nailed it.
> 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?
Absolutely not. In fact, this crossed my personal complexity horizon
and is still accelerating towards some kind of singularity.
The more I try to imagine a problem that this might be a solution to,
the less I can understand why it would be approached this way.
To be perfectly honest, I've never found replacing one string
by another to be terribly useful. Replacing one *token sequence*
by another, yes. Replacing a (match for a) regular expression by
a derived string, yes.
More information about the Haskell-Cafe
mailing list