>>12
How would you know? Have you ever even tried to write anything in Haskell? I would venture to say no because you didn't see the misuse of 'length' in the original code.
Name:
Anonymous2012-04-24 15:05
>>13
The fact that using 'length' on lists doesn't get properly optimized in a purely functional programming language really just means it's pure shit, and that you are a humongous faggot.
sight*, if you are _that_ concerned about the length, it's only
expensive the first time you call it, after that is only as
expensive as in any other language. you could pass the result
the first time, but that's an extra optimization (but it just a closure away)
OP: is ok as a mergersort. nothing to add.
also don't be afraid to use length in a sorting function, information theory tells us that every element of the data-structure must be compared against every other one, so it obvious that you data-structure needs to be finite, (try sort on [1..])
Name:
Anonymous2012-04-24 21:59
>>24
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :set +s
Prelude> let a = [1..500000]
(0.01 secs, 5983280 bytes)
Prelude> length a
500000
(0.10 secs, 43996048 bytes)
Prelude> length a
500000
(0.01 secs, 587544 bytes)
Name:
Anonymous2012-04-24 22:50
>>24 if the comparison function is cheap, merge sort with an O(n) length function being called in each recursive branch will be noticably slower than a merge sort that either uses a O(1) length function, or doesn't use the top down divide and conquer method. It is easiest to do bottom up merging, like in >>17. But the merge sort will still run in O(nlog(n)), even with the length calculation. You can afford for the merge operation to take linear time, and the length call doesn't do worse than that.
Name:
Anonymous2012-04-24 23:24
>>24 if you are _that_ concerned about the length
measure it everyday, it makes /prog/ less SEPPLES.