I was playing around with a simple example, where I tried to add a
default constructor to a struct, but it doesn't look like structs can
use the _ctor methods. With this module:

open module Vector3
{
  struct vector3 = { x:float; y:float; z:float; };

  fun _ctor_vector3 () => vector3(0.0f, 0.0f, 0.0f);
}

instance Str[Vector3::vector3] {
  fun str (v:Vector3::vector3) =>
    'Vector3::vector3(' +
    (f'%f, %f, %f' (double v.x, double v.y, double v.z))
    + ')';
}


This:

val v1 = Vector3::vector3 (1.0f, 2.0f, 3.0f);
println v1;


prints out:

Vector3::vector3(1.000000, 2.000000, 3.000000)

whereas this:

val v0 = Vector3::vector3 ();
println v0;

errors out with:

CLIENT ERROR
[lookup_qn_with_sig] Struct constructor for vector3 has wrong signature, got:
float<2068> * float<2068> * float<2068> -> Vector3::vector3<5144>
expected:
unit
In ./felix/vector.flx: line 3, cols 3 to 50
2: {
3:   struct vector3 = { x:float; y:float; z:float; };
     ************************************************
4:

------------------------------------------------------------------------------
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to