3 ms·
Haskell and Erlang basically go for mathematical notation. Python and Julia more or less go for how you read those notations. I personally prefer math-like not
by dmitriid 5y ago
Haskell and Erlang basically go for mathematical notation. Python and Julia more or less go for how you read those notations.
I personally prefer math-like notation because I find it much more readable and composable.
x, such as x is in xs, xs is in xss
x | x ∈ xs, xs ∈ xss # my math is rusty
[x | x <- xs, xs <- xss] # haskell, erlang is isimilar
[ x for xs in xss for x in xs ] # python, julia, order might be different
As soon as you add conditions/filters on data, math-like notation wins hands down
Edit:
Since I don't know Haskell, apparently in Haskell the order is wrong. So, only Erlang gets it right (variables are upper case in Erlang):
[ X || X <- Xs, Xs <- Xss]
- jolmg 5y ago> only Erlang gets it right... [ X || X <- Xs, Xs <- Xss] I don't have much experience with Erlang, but that also seems wrong: 1> Xss = [[1]]. [[1]] 2> [ X || X <- Xs, Xs <- Xss]. * 1:13: variable 'Xs' is unbound 3> [ X || Xs <- Xss, X <- Xs]. [1]
- dmitriid 5y agoDamnit. I haven't used Erlang in a long time, but I should've known that. So, no language does it "right".
- sundarurfriend 5y agoNote that in Julia, ∈ is a synonym of `in`, so a minor improvement towards your preferred notation can be: [ x for xs ∈ xss for x ∈ xs ]