0

In Scala I could do this:

lines.filter(_.length < 10) // notice the _ acting as the argument

In Haskell the best I can come up with is:

filter ((< 10) . length) lines // point-free with `.` :(

So basically in Haskell there is no way to do something like

length _ < 10  // short hand for: \x -> length x < 10

?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68

1 Answers1

3

Yes, Haskell has no placeholder syntax like Scala.

Usually the problem with such syntax is that it either has some arcane rules or it is not really useful in practice. I'm trying to understand Scala's rules now, but I have a feeling it is on the arcane side (what exactly is "syntactic category Expr"?).

Noughtmare
  • 9,410
  • 1
  • 12
  • 38
  • 1
    As a _"veteran"_ **Scala** developer, I would rather prefer that syntax would have never existed, it is only useful on very small use cases and is a constant source of confusion. – Luis Miguel Mejía Suárez Jul 23 '22 at 13:12
  • 1
    @LuisMiguelMejíaSuárez I think this is kind of like "because some people use knifes to hurt others, knifes are a bad idea and should never have existed". I mean, it is very useful and makes code even easier to understand (ofc, if the other developers who read it, know about Scala) in some cases, the developers should know when to use them. – AminMal Jul 23 '22 at 15:29
  • @AminMal I understand the point but I disagree, the `_` syntax is barely useful at all, at best it reduces 7 characters per lambda over doing `it => it.foo`, and that only applies if the name is meaningless which, IMHO, is almost never the case. - Moreover my problem with `_` is that it doesn't scale, like you can do `map(_.foo)` and you can `map(bar(_))` but then you can't do `map(bar(baz(_))` nor you can `map(s"Bar ${_}")` – Luis Miguel Mejía Suárez Jul 23 '22 at 15:42
  • I don't know if it can be improved, see [this reddit post of mine](https://reddit.com/r/ProgrammingLanguages/comments/p1pgk1/other_languages_with_partial_application_%C3%A0_la/). There are a bunch of languages with similar functionality, but none seem completely satisfying. – Noughtmare Jul 23 '22 at 17:57