"D. Tweed" wrote:
>
> On Wed, 5 May 1999, Kevin Atkinson wrote:
>
> > Normally given the class.
> >
> > class Listable c b where
> > toList :: c -> [b]
> >
> > to list will never be able to be resolved unless the signature is given
> > when toList is called because there is no way to derive the type of b
> >from the function call. However when given an instance declaration of
> >
> > instance Listable [a] a where
> > toList c = c
> >
> > the compiler should be able to resolve toList [1,2,3] however it
> > currently doesn't.
>
> Is this inference valid since you might also have somewhere in your
> script
>
> instance Listable [Int] Char where
> toList xs = map chr xs
Obviously there are complex issues with it. However, there should be
some way to get the return type with out having to explicitly store it
in the object as a bulk type.
In C++ you can get type information about an object by using speculation
of templates. For example to find out the difference type of a pointer
you can use the syntax.
iterator_traits<double *>::diffrence_type d
And the code to make this work:
// declares a generic template class with nothing in it
template <typename Itr>
class iterator_traits {};
// a speculation of iterator_traits for int *
template <>
class iterator_traits<double *> {
typedef int diffrence_type;
};
Now the type "double *" i no way stores the diffrence_type as part of
its definition. Only classes can do that, and double * is a basic type
and not a class. The line:
iterator_traits<double *>::diffrence_type d
says make a new object d that is the type diffrence_type in the class
iterator_traits<double *>.
There out to be a way to do a similar thing in haskell. So you can say
something like
class Listable c where
toList :: c -> [ContinentsType c]
type_class ContinentsType c
type_instance ContinentsType [c] where
type :: c
type_instance ContinentsType Array ix el where
type :: (ix,el)
or something to that nature.
--
Kevin Atkinson
[EMAIL PROTECTED]
http://metalab.unc.edu/kevina/