std.range: Order of arguments unluckily chosen?
bearophile
bearophileHUGS at lycos.com
Sat Jun 4 15:33:52 PDT 2011
Timon Gehr:
> It is also the way functional language
> libraries handle it. It works better with currying too.
This is quite true. The order of all Haskell Prelude functions are designed to allow the most handy usage of currying:
Prelude> let a = [0..10]
Prelude> a
[0,1,2,3,4,5,6,7,8,9,10]
Prelude> take5 = take 5
Prelude> take5 a
[0,1,2,3,4]
If you program in Haskell you find that it's actually more handy to have the number of items of take as first argument.
--------------------
Andrej Mitrovic:
> I'd kill for some UFCS action. Here's my interpretation (only the
> first one works of course):
> range = take(stride(cycle([1, 2, 3, 4]), 2), 2); // :(
> range = take(stride(2, cycle(2, [1, 2, 3, 4]))); // :)
> range = cycle([1, 2, 3, 4]).stride(2).take(2); // :D
Haskell solves this problem with two really handy operators, "." and "$", example:
stride _ [] = []
stride n (x:xs) = x : stride n (drop (n-1) xs)
main = print $ take 2 $ cycle $ stride 2 [1, 2, 3, 4]
Bye,
bearophile
More information about the Digitalmars-d
mailing list