Page 1 of 1
Value of Type Parameter not captured from Context
Posted: 1 Aug 2014 11:18
by Martin Meyer
Hi Thomas,
below code compiles in build 7402 but throws
error c353 : Free parameter 'LocalType' is used in type expression in build 7500.
Code: Select all
interface refTerm{@Type}
domains
refTermValue =
nil;
atm(@Type Value);
cmp(symbol FunctorName, refTerm{@Type}* ArgumentRtList);
var(refTerm{@Type} Rt).
end interface refTerm
class refVar{@Type} : refTerm{@Type}
predicates
convertFromBaseType : (LocalType Value)
-> refTerm{LocalType} RefTerm.
constructors
new : (refTermValue RtValue).
end class refVar
implement refVar{@Type}
clauses
convertFromBaseType(Val) = new(refVar{LocalType}::atm(Val)).
clauses
new(_).
end implement refVar
If the change is intended, please explain, for what reason it has been made, resp. what's wrong about the above construction.
Regards,
Martin
Posted: 1 Aug 2014 12:23
by Martin Meyer
The parameter
LocalType is unused in
Code: Select all
clauses
convertFromBaseType(Val) = new(refVar{LocalType}::atm(Val)).
because it appears there only once. So I just tried replacing it by
_. However on that the compiler issued
error c504 : The expression has type 'refTerm::refTermValue{_}', which is incompatible with the type 'refTerm::refTermValue{LocalType}'.
Regards,
Martin
Posted: 1 Aug 2014 12:28
by Thomas Linder Puls
That is unfortunately a bug, and will be investigated as such.
I assume the example is an extract of your real problem, and therefore this workaround may be too painful:
Code: Select all
interface refTerm{@Type}
domains
refTermValue{LocalType} =
nil;
atm(LocalType Value);
cmp(symbol FunctorName, refTerm{LocalType}* ArgumentRtList);
var(refTerm{LocalType} Rt).
predicates
p : (refTermValue{@Type}).
end interface refTerm
class refVar{@Type} : refTerm{@Type}
predicates
convertFromBaseType : (LocalType Value)
-> refTerm{LocalType} RefTerm.
constructors
new : (refTermValue{@Type} RtValue).
end class refVar
implement refVar{@Type}
clauses
convertFromBaseType(Val) = new(refTerm{_}::atm(Val)).
clauses
new(_).
clauses
p(_).
end implement refVar
I.e. where
refTermValue uses a local type parameter instead of the global one.
Posted: 1 Aug 2014 13:05
by Martin Meyer
I just found out, that the compiler error disappears, when replacing in my code
Code: Select all
convertFromBaseType(Val) = new(refVar{LocalType}::atm(Val)).
by
Code: Select all
convertFromBaseType(Val) = new(refVar::atm(Val)).
or even better by
Code: Select all
convertFromBaseType(Val) = new(refTerm::atm(Val)).
Thanx Thomas for supporting me!
Martin
Posted: 17 Aug 2014 16:24
by Martin Meyer
Maybe it stems from same issue, that the compiler build 7500 throws
fatal error c098 : getTypeVariableTerm name(03822B00,"atm","Atm",false) on this code. Can you provide a fix for the issue?
Code: Select all
interface refTerm{@Atom}
constants
fct_cons : symbol = "cons".
domains
refTermValue =
nil;
atm(@Atom Value);
cmp(symbol FunctorName, refTerm{@Atom}* ArgumentRtList);
var(refTerm{@Atom} Rt).
properties
value : refTermValue (o).
predicates
tryToValueList : (refTermValue RtValueTail [out])
-> refTermValue* RtValueFront
determ.
end interface refTerm
% ---
class refTerm{@Atom} : refTerm{@Atom}
end class refTerm
% ---
implement refTerm{@Atom}
facts
value : refTermValue := nil.
clauses
tryToValueList(RtValTail) = tryToValueList_0(value, RtValTail).
class predicates
tryToValueList_0 : (
refTerm{Atm}::refTermValue RtValue,
refTerm{Atm}::refTermValue RtValueTail [out])
-> refTerm{Atm}::refTermValue* RtValueFront
determ.
clauses
tryToValueList_0(refTerm::cmp(refTerm::fct_cons, [HeadRt, RestFrontRt]), RtValTail) =
[HeadRt:value | RestFrontRt:tryToValueList(RtValTail)].
tryToValueList_0(refTerm::nil, refTerm::nil) = [].
tryToValueList_0(refTerm::var(FreeRt), refTerm::var(FreeRt)) = [].
end implement refTerm
Regards,
Martin
Posted: 17 Aug 2014 19:30
by Thomas Linder Puls
This is more or less the same bug.
And you can solve the problem in the same way as advised above:
Code: Select all
interface refTerm{@Atom}
constants
fct_cons : symbol = "cons".
domains
refTermValue{Atm} =
nil;
atm(Atm Value);
cmp(symbol FunctorName, refTerm{Atm}* ArgumentRtList);
var(refTerm{Atm} Rt).
properties
value : refTermValue{@Atom} (o).
predicates
tryToValueList : (refTermValue{@Atom} RtValueTail [out])
-> refTermValue{@Atom}* RtValueFront
determ.
end interface refTerm
% ---
class refTerm{@Atom} : refTerm{@Atom}
end class refTerm
% ---
implement refTerm{@Atom}
facts
value : refTermValue{@Atom} := nil.
clauses
tryToValueList(RtValTail) = tryToValueList_0(value, RtValTail).
class predicates
tryToValueList_0 : (
refTermValue{Atm} RtValue,
refTermValue{Atm} RtValueTail [out])
-> refTermValue{Atm}* RtValueFront
determ.
clauses
tryToValueList_0(refTerm::cmp(refTerm::fct_cons, [HeadRt, RestFrontRt]), RtValTail) =
[HeadRt:value | RestFrontRt:tryToValueList(RtValTail)].
tryToValueList_0(refTerm::nil, refTerm::nil) = [].
tryToValueList_0(refTerm::var(FreeRt), refTerm::var(FreeRt)) = [].
end implement refTerm
Posted: 18 Aug 2014 12:15
by Martin Meyer
To my supprise I found, that the below compiles. I.e. it does NOT cause something like
error c530 : The object member 'refTerm{@Atom}::@Atom/0' is used in the class predicate 'refTerm{@Atom}::tryToValueList_0/2->'.
Is it unintended? Or, does the compiler in class predicate
tryToValueList_0/2-> cleverly capture the value of
@Atom, which is used in domain
refTermValue, from context, and that
refTermValue does not need to be qualified by
refTerm{Atm}::, is syntactic sugar?
Code: Select all
interface refTerm{@Atom}
constants
fct_cons : symbol = "cons".
domains
refTermValue =
nil;
atm(@Atom Value);
cmp(symbol FunctorName, refTerm{@Atom}* ArgumentRtList);
var(refTerm{@Atom} Rt).
properties
value : refTermValue (o).
predicates
tryToValueList : (refTermValue RtValueTail [out])
-> refTermValue* RtValueFront
determ.
end interface refTerm
% ---
class refTerm{@Atom} : refTerm{@Atom}
end class refTerm
% ---
implement refTerm{@Atom}
facts
value : refTermValue := nil.
clauses
tryToValueList(RtValTail) = tryToValueList_0(value, RtValTail).
class predicates
tryToValueList_0 : (
refTermValue RtValue,
refTermValue RtValueTail [out])
-> refTermValue* RtValueFront
determ.
clauses
tryToValueList_0(cmp(fct_cons, [HeadRt, RestFrontRt]), RtValTail) =
[HeadRt:value | RestFrontRt:tryToValueList(RtValTail)].
tryToValueList_0(nil, nil) = [].
tryToValueList_0(var(FreeRt), var(FreeRt)) = [].
end implement refTerm
Regards
Martin
Posted: 19 Aug 2014 6:28
by Thomas Linder Puls
No, that is not intended. Your first code is correct, the second one accidentally works.