Open johnwikman opened 4 years ago
Even though I spontaneously agreed with you when I read your post, both Haskell and OCaml actually have the list first!
(!!) :: [a] -> Int -> a
val nth : 'a list -> int -> 'a
This is less of a hassle in Haskell (heh) since you can write map (!! pos) lists
. In OCaml you would have to do what you did above, or write map (Fun.flip nth pos) lists
. My feeling is that it is probably best to follow existing practices in this case.
I can buy the reason for having the list first on !!
in haskell since it is an infix operator, but in our case it is not. To me it makes more sense to have the list second in a functional context (for the reasons explained above). Maybe I have glossed over some important detail? Looking at OCaml's List it seems as if Nth
is the lone exception that has the list first.
Some built-in functions such as
nth
are defined to be used asnth <list> <pos>
which feels a bit reversed as most languages usenth <pos> <list>
instead. Is there a reason for having the arguments in this order?An annoyance with having the list first is that it blocks many convenient partial applications. For example, if I would like to extract the nth element of all lists within a list, I would currently have to do it like this in MCore:
How I would like to do it: