ChrisK schrieb:
Bulat is right about making Block's fields strict.
-- | Get the offsets between entries in a list
getSizes :: [Integer] -> [Integer]
getSizes (x:y:[]) = [y - x]
getSizes (x:y:ys) = (y - x):(getSizes (y:ys))
You should change the first part to add maxSize:
> getSizes :: [Integer] -> [Integer]
> getSizes (x:y:[]) = [y - x,maxSize]
> getSizes (x:y:ys) = (y - x):(getSizes (y:ys))
This avoids the ugly use of (++) below. Note that appending to a singly
linked list is a bad "code smell":
But Chris' version changed semantics. It should be
getSizes :: [Integer] -> [Integer]
getSizes (x:y:[]) = [y-x,maxSize-y]
getSizes (x:y:ys) = (y-x):getSizes (y:ys)
instead. But
getSizes :: [Integer] -> [Integer]
getSizes [x] = [maxSize-x]
getSizes (x:y:ys) = (y-x):getSizes (y:ys)
is even better as it doesn't repeat the y-x term.
Regards,
Martin.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe