Keith Wansbrough <[EMAIL PROTECTED]> writes
> Sergey writes:
>> Maybe, there exists another possibility to print the values in the
>> error message like for
>> take (-1) xs, y % 0
>>
>> The implementors declare the "internal"
>> class ServiceShow where serviceShows :: ...
>> invisible for the user,
>> make *everything* to be the instance of ServiceShow,
> The problem with this is that there is a performance penalty to be
> paid for overloading a function in this way.
> [..]
> then mytake is now implemented as a function of *three* arguments: the
> number and the list, as before, but also a `dictionary'
> [..]
> In other words, if you implement the above proposal, every invocation
> of take will be passed an extra argument, which will be only very
> rarely used. Perhaps this could be turned on with a debugging option,
> but in general it would be a Very Bad Thing performance-wise.
I somehow do not believe in this philosophy: of extra argument
slowing down the performance any essentially.
Still, let us try example:
length2 :: Show a => [a] -> Int
length2 [x,y] = error $ ("length2 "++) $ shows [x,y]
"\n Do not like lists of length 2 ! \n"
length2 xs = ln xs 0
where ln [] n = n
ln (_:xs) n = ln xs (succ n)
main = let xs = [1..999000] :: [Int]
n = length2 xs -- compare to length
in
putStr $ shows n "\n"
In the implementation I use, length2 is as fast as Prelude.length.
?
------------------
Sergey Mechveliani
[EMAIL PROTECTED]