[clean-list] Internal overloading and unboxed arrays
John van Groningen
johnvg at cs.ru.nl
Wed Sep 26 12:16:18 MEST 2007
David Norris wrote:
>Why does the commented instance declaration below fail on {#} with an internal overloading error, when a similar declaration for {} succeeds?
>..
>/* This causes error: 'internal overloading of "size" could not be solved'
>instance first {#} e
>where
> first null a
> | size a == 0 = null
> | otherwise = select a 0
>*/
For {} and {!} the compiler can determine the instance of class Array without
knowing the type of the elements of the array, because for all types of
elements the same instance can be used.
For {#} this is not possible, because the representation of the array
depends on the type of the elements, for example on a 32 bit computer
an {#Int} uses 4 bytes for each element and for {#Real} 8 bytes per
element. So there is an instance of class Array for each element type
(for unboxed arrays).
Therefore use:
instance first {#} e | Array {#} e
where
first null a
| size a == 0 = null
| otherwise = select a 0
Kind regards,
John van Groningen
More information about the clean-list
mailing list