Hi Craig,

I'm also still learning Chapel so not veryn sure whether
this is the right way, but the following seems to work (with
chapel v1.16 on my computer):

record A {
    type T;
    var val : T;
}

proc =( ref lhs: A, rhs ): void where lhs.T == rhs.type {
    lhs.val = rhs;
}

var ar: A( T = real );
ar = 1.23;
show( ar );

var ai: A( int );
ai = 100;
show( ai );

var astr: A( string );
astr = "hi";
show( astr );

proc show( arg: A ) {
    writeln( "val = ", arg.val, " T = ", arg.T:string );
}


Results:
val = 1.23 T = real(64)
val = 100 T = int(64)
val = hi T = string

But if I add the default type to 'T' as

record A {
    type T = real;
    var val : T;
}

the program gives an error:

type mismatch in assignment from int(64) to A(int(64))

I don't know why this error occurs... (and hope other people will
give more hints :)

PS. I guess asking a question on Stackoverflow may also be useful,
because other people (not subscribing to this list) can see the Q/A also.

Best,
Takeshi

2018-06-13 5:24 GMT+09:00 Craig Reese <cfre...@super.org>:

> Chapel 1.17.1 newbie question (my real effort is much more complicated,
> but this illustrates the issue):
>
> record A {
>   type T = real;
>   var val : T;
>   proc =(ref lhs: A, rhs : T) : void {
>     lhs.val = rhs;
>   }
> }
>
> yields:
>
> assign.chpl:4: warning: The left operand of '=' and '<op>=' should have
> 'ref' intent.
>
> There are a couple work arounds:
>
> 1) put the "proc =" outside the record (but then the T type is no longer
> visible).
>
> 2) 1+ move "type T" outside the "record" (though it really doesn't
> otherwise need that wider visibility).
>
> I've run into this in a number of larger cases.  Is there some magic to
> doing assignment as a member vs.
>
> non-member function?
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Chapel-users mailing list
> Chapel-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/chapel-users
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
Chapel-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to