Re:Comparison of Haskell and Julia List Comprehensions
by jolmg on Wednesday July 07, 2021 @05:34PM
(#27765974)
> 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]
Re:Comparison of Haskell and Julia List Comprehensions
by dmitriid on Wednesday July 07, 2021 @06:04PM
(#27766233)
Damnit. I haven't used Erlang in a long time, but I should've known that.
So, no language does it "right".
Re:Comparison of Haskell and Julia List Comprehensions
by sundarurfriend on Wednesday July 07, 2021 @11:24PM
(#27768173)
Note 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 ]
I personally prefer math-like notation because I find it much more readable and composable.
As soon as you add conditions/filters on data, math-like notation wins hands downEdit:
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):