Stream: beginners

Topic: pointfree function composition


view this post on Zulip Philippe (Mar 21 2022 at 21:32):

Might sound a bit stupid, but here I go anyway.

Haskell has a dot operator for function composition. Could Roc use it as some sort of pipe?

emptyDict . insert k v

Creates an empty map and then calls insert with the first argument being this empty map.

view this post on Zulip Derek Gustafson (Mar 21 2022 at 21:34):

There is a pipe operator that works exactly that way. It's |>

view this post on Zulip Philippe (Mar 21 2022 at 21:37):

Yes, I know :)

But if people want dot notation, give them dot notation.

After, we can't please everyone. Should we allow code to be written in two different ways or enforce / greatly suggest the Roc way.

view this post on Zulip Brendan Hansknecht (Mar 21 2022 at 21:41):

It would still end up being this in Roc even if we had a . operator for composition:
Dict.empty {} . Dict.insert k v

view this post on Zulip jan kili (Mar 21 2022 at 21:45):

Dots already mean record field access in Roc:

record = { field: "foo", other: "bar" }
transform = \r -> { r & field: "baz" }

a = transform record
b = a.field

c = (transform record).field

d = record |> transform |> .field

b == c == d

It would be very confusing if they also meant composition when followed by a space: record . transform . .field

view this post on Zulip Richard Feldman (Mar 21 2022 at 22:52):

there's actually an FAQ entry on this!

https://github.com/rtfeldman/roc/blob/5e9e7f3ad549c3ad8e5966303cfb6c4a56fea06f/FAQ.md#pointfree-function-composition

view this post on Zulip Richard Feldman (Mar 21 2022 at 22:52):

not having a pointfree function composition operator is an intentional design decision - more details in the FAQ entry!

view this post on Zulip Gabriel Pickl (Mar 22 2022 at 18:20):

I actually think (.) is one of the best omissions Elm made as a language. The number of times I had to explain to people how it works speaks to it's lack of affordance and readability in my opinion. Elm, and a lot of alternative preludes in Haskell use (<<) (and the imo more reasonable (>>)) instead, because it shows which direction the composition follows. But, to be honest, I rarely reach for point-free style in my programs because pipelines usually read cleaner than function composition

view this post on Zulip Kevin Gillette (Mar 23 2022 at 02:28):

I have found that the clearest way to use point-free function composition, ironically, is to give the resulting function a name, somewhat defeating the point of concise composition.


Last updated: Jul 05 2025 at 12:14 UTC