Who could, please, give me an advice on the strict fields in
constructors?
It was said long ago that these strict fields help to somewhat
increase the performance. For example, Ratio uses this (?).
Initially, i objected to this, because Ratio is applicable to the
generic data, not only to Integer. And i thought, Ratio .Polynomial
could force the unneeded strict evaluations with the polynomials
contained under Ratio.
Then it appeared that if Polynomial is made with the usual
constructors, say, data Pol a = Pol [(a,Int)],
then the strictness of Ratio fields would NOT force the strictness
inside Pol. `!' forces only one constructor level.
So, i am going to declare `!' widely - for the constructors that are
not expected to apply repeatedly. For example, it is good that
(:), (,) are lazy, because they often apply like this:
x:y:z:..., (x,(y,(z,(u,v))))
But for Ratio, `!' fits.
Because Ratio .Ratio does not make much sense,
and, say, for Ratio .Pol .Ratio .Pol .Ratio .Pol .Ratio
the strictness would stop by default at each level of Pol.
I hope that in many cases `!' would lead to the constant space
evaluation instead of the linear space size.
For example, sum ns :: Int
runs in the constant space - with the properly and simply implemented
`sum'. Then,
sum (map D ns) :: D Int
returns to the linear space size for
data D = D Int deriving(Show,Eq)
instance Num D where (D x)+(D y) = D (x+y)
And D !Int, returns it again to the constant space.
I think, this (!) would help the compiler to discover the strict -
available parts in the program.
As to the `seq' annotation, i avoid it. It complicates the program,
and i think, somewhat spoils the language.
But `!' looks better.
What the experts think recently on `!' ?
Thank you in advance for your comments.
------------------
Sergey Mechveliani
[EMAIL PROTECTED]