[clean-list] definition and propagation of class constraints

Carlos Aya carlosayam at yahoo.com.au
Thu Nov 19 00:59:31 MET 2009


Hi,

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

// creates a new 2d matrix with given initial value
make :: .Int .Int elemType -> .(UMatrix elemType)
... more stuff ...
----------------------------------------------------------------------------------------------------------

but I don't know (couldn't find) how to define the abstract type UMatrix in the definition module, annotated with corresponding class constraint.

------------------- umatrix.icl ----------------------------------------------------------------------
implementation module UMatrix

import StdArray, StdInt, StdBool, StdMisc, StdList, StdEnum


::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
                   }
= abort "invalid matrix dimension"
... more stuff ...
---------------------------------------------------------------------------------------------------------

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?
- Is that solved if I manage to annotate UMatrix in the implementation file?

kind regards
Carlos



      __________________________________________________________________________________
Get more done like never before with Yahoo!7 Mail.
Learn more: http://au.overview.mail.yahoo.com/



More information about the clean-list mailing list