No, the entire point of the operator is to be left associative. If you really need complex expressions, just use parentheses. Elm format will take care of the rest for you.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/-PLj_eamKVQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
Whoops, I mixed up left and right! The whole point of the operator is that (f <| x <| y ) == (f (x y) ).
The goal is to avoid complex nested expressions, so that Elm doesn't end up looking like Lisp.
Consider where you are adding 4 elements to a dict:
insert wk w <| insert xk x <| insert yk y <| insert zk z myDict.
Without a right-associative operator, this becomes:
insert wk w (insert xk x (insert yk y (insert zk z myDict)))
In my mind, this is harder to read, and you get a huge collection of parentheses at the end.
In your case, you can always take this:
and write it as this:
functionThere are brackets, but they're not nested, so there isn't a readability issue.
The idea is that function application is left-associative by default, just by placing two things next to each other. We define <| to be right-associative for the cases when the default isn't what you need.
In F#, <| is left-associative; you use it to avoid brackets or naming things with let-bindings when you have to do multi-line computation to arrive at function arguments. I find this very compelling.
The "myDict" example in Joey's post does not adequately explain why <| is right-associative in Elm since, as the post says, that is example is more naturally written with |>.
So what is a good example?
clutter is clutter
However, I'm still hoping to see an example of how to properly use the right-associative pipe-operator <| in Elm, since I apparently want to use it non-idomatically. What is that example?
> t5 x = cos(5*acos(x))
<function> : Float -> Float
> t5 0.2
0.8451200000000004 : Float
> t5 x = cos <| (*) 5 <| acos x
<function> : Float -> Float
> t5 0.2
0.8451200000000004 : Float
> t5 x = (cos <| (*) 5) <| acos x
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm
The right argument of (<|) is causing a type mismatch.
4│ cos <| (*) 5)
^^^^^
(<|) is expecting the right argument to be a:
Float
But the right argument is:
number -> number
Hint: I always figure out the type of the left argument first and if it is
acceptable on its own, I assume it is "correct" in subsequent checks. So the
problem may actually be in how the left and right arguments interact.
> t5 x = x |> acos |> (*) 5 |> cos
<function> : Float -> Float
> t5 0.2
0.8451200000000004 : Float