The standard library provides a convenient alias:

val x1 : complex[float] = fcomplex(2.2f, 1.0f);

which corresponds to std::complex. However this alias cannot
be used as the name of a constructor:

        complex[float] (2.2f, 1.0f)

gives an error. Constructors CAN be polymorphic:

        ctor int[t in ints] : t = "(int)$1";

but the type variables are only allowed for the arguments,
not the result type. In fact the syntax above was changed recently
by me, probably incorrectly, from:

        ctor [t in ints] int : t = "(int)$1";

which is required for class constructors. These kinds of
constructors are really just hacks for functions otherwise
declared as

        fun _ctor_int ...

However, for polymorphic constructors we'd need:

        ctor [r in ints, t in ints] integer[r] : t = "(?2)$1";

Here the name of the function is

        _ctor_integer

and it is polymorphic in r and t. Since r cannot be deduced in this
case it would have to be specified, and we'd like

        integer[long] 1

to work, with t = int and r = long .. after all, C++ allows polymorphic
classes .. :)

When the lookup routine finds a type name when it expects a function,
it looks up _ctor_<name> instead, except if the type is a struct,
in which case a compiler generated constructor is used. Note the lookup
is name based: you can provide distinct constructors for the same type
simply by making a typedef:

        typedef polar = dcomplex;
        ctor polar : double * double = ...

Anyhow, it would be nice if polymorphic constructors worked:
I hate saying 'fcomplex' where 'complex[float]' should work,
this makes the language look non-orthogonal.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to