What’s in a find function?

Posted in haskell
9 comments on “What’s in a find function?
  1. increpare says:

    that looks significantly more straight-forward to me type- and behaviour- wise : )

  2. Conor says:

    It’s the right functionality, and at the list level it’s the right interface. Go for it.

    How the differential calculus ends up in the prelude is destined to be a longer story.

  3. Karl says:

    Don’t you mean:
    find :: Text -> Text -> [(Text,Text,Text)]

  4. Since the middle element is always going to be the same, and identical to whatever the user passed in, is there any reason to include it in the output? Apart from the symmetry reasons I suppose. But returning a list of 3-tuples means we can’t use the standard `fst` and `snd` functions for extracting results.

  5. jtra says:

    > Since the middle element is always going to be the same, and identical to whatever the user passed in, is there any reason to include it in the output?

    Once you start to do pattern matching instead of just substring search, the actually matched part may be different.

  6. Alessandro Stamatto says:

    Yes, i ‘find’ the new version of ‘find’ a lot more intuitive!

  7. Dan P says:

    I’ve used a version of this function when computing symbolic derivatives. D(fgh) = D(f) g h + f D(g) h + f g D(h) etc. It’s curious (but not completely surprising) that computing derivatives of functions makes use of one of the standard functions attached to derivatives of types.

  8. Duncan Coutts says:

    Yes, we discussed revising find yet again on the #ghc channel a month or so ago. Despite having pushed you towards the one with type Text -> Text -> (Text, [(Text, Text)]), I realised I still was not happy with it either.

    The one we discussed more recently is similar to what you are proposing now. I think the difference was that in what I suggested, the middle component of the tuple went to the end of the text, i.e. it was a prefix of the last component.

    I think the rationale for that was that you already know what you searched for and we can save time and space by providing the full tail rather than making new texts by recomposing the search term with the trailing string.

  9. Zemyla says:

    This post seems to have vanished utterly.

Leave a Reply

Your email address will not be published. Required fields are marked *

*