[clean-list] definition and propagation of class constraints
John van Groningen
johnvg at cs.ru.nl
Fri Nov 20 17:52:13 MET 2009
Carlos Aya wrote:
>I want to to this:
>------------------ umatrix.dcl ---------------------------------------------------------------------
>definition module UMatrix
>
>import StdArray
>// UMatrix : Unboxed matrix, elemType must be one of the available unboxed types
>::UMatrix elemType | Array {#} elemType
>..
>
>but I don't know (couldn't find) how to define the abstract type UMatrix in the definition module, annotated with corresponding class constraint.
Class constraints cannot be used in type definitions (synonym, algebraic,
record or abstract).
>..
>::UMatrix elemType = { rows :: Int
> , cols :: Int
> , vals :: {#} elemType
> }
>
>make :: .Int .Int elemType -> .(UMatrix elemType)
>make n m v
>| n > 0 && m > 0 = { rows = n
> , cols = m
> , vals = createArray (n*m) v
> }
>..
>therefore the compiler complains that "internal overloading of createArray" cannot be solved.
>
>My questions
>- if UMatrix e is annotated with Array {#} e, why do I need to especify that in make if e appears in the return type? Isn't this inferred?
You cannot annotate UMatrix e with Array {#} e, therefore you have to
add the context Array {#} e at the end of the type of make.
Kind regards,
John van Groningen
More information about the clean-list
mailing list