Zulip Chat Archive

Stream: lean4

Topic: Shorthand for function composition?


Anurudh Peduri (Dec 15 2022 at 16:30):

Hey,
Is there a point free version of the |>. notation?

For example, consider this implementation for count

def List.count (p : α  Bool) (l : List α) : Nat :=
  l.filter p |>.length

Instead, I would like to write something like:

def List.count' (p : α  Bool) : List α  Nat :=
  .filter p >>>.length

Marcus Rossel (Dec 15 2022 at 16:43):

Is either of these two what you're looking for?:

def List.count' (p : α  Bool) : List α  Nat :=
  length  filter p
def List.count' (p : α  Bool) : List α  Nat :=
  (⋅.filter p |>.length)

Anurudh Peduri (Dec 15 2022 at 16:52):

Yep! the second one. Thanks a lot!

p.s. Is there some way to avoid the parenthesis? I guess not.

Marcus Rossel (Dec 15 2022 at 17:06):

No, you need the parentheses. The notation (foo ⋅ bar ⋅ baz ⋅) is shorthand for fun a b c => foo a bar b baz c.

Trebor Huang (Dec 15 2022 at 17:20):

Practically this may be what is needed, but that is not technically pointfree though.

Mario Carneiro (Dec 15 2022 at 17:21):

sure it is, there are no variable names in sight

Mario Carneiro (Dec 15 2022 at 17:22):

TBH I think that's just a much better way to do pointfree than haskell style ascii soup


Last updated: Dec 20 2023 at 11:08 UTC