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.
There is a pipe operator that works exactly that way. It's |>
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.
It would still end up being this in Roc even if we had a .
operator for composition:
Dict.empty {} . Dict.insert k v
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
there's actually an FAQ entry on this!
not having a pointfree function composition operator is an intentional design decision - more details in the FAQ entry!
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
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