284284
285285istree (t:: Term ) = true
286286
287- Term (f, args) = Term {rec_promote_symtype (f, map(symtype, args)... )} (f, args)
287+ Term (f, args) = Term {_promote_symtype (f, args)} (f, args)
288288
289289operation (x:: Term ) = getfield (x, :f )
290290
@@ -297,9 +297,22 @@ function Base.hash(t::Term{T}, salt::UInt) where {T}
297297 hashvec (arguments (t), hash (operation (t), hash (T, salt)))
298298end
299299
300+ _promote_symtype (f:: Sym , args) = promote_symtype (f, map (symtype, args)... )
301+ function _promote_symtype (f, args)
302+ if length (args) == 1
303+ promote_symtype (f, symtype (args[1 ]))
304+ elseif length (args) == 2
305+ promote_symtype (f, symtype (args[1 ]), symtype (args[2 ]))
306+ else
307+ # TODO : maybe restrict it only to functions that are Associative
308+ mapfoldl (symtype, (x,y) -> promote_symtype (f, x, y), args)
309+ end
310+ end
311+
312+
300313function term (f, args... ; type = nothing )
301314 if type === nothing
302- T = rec_promote_symtype (f, map (symtype, args) ... )
315+ T = _promote_symtype (f, args)
303316 else
304317 T = type
305318 end
@@ -689,10 +702,10 @@ end
689702
690703function similarterm (p:: Union{Mul, Add, Pow} , f, args)
691704 if f === (+ )
692- T = rec_promote_symtype (f, map (symtype, args) ... )
705+ T = _promote_symtype (f, args)
693706 Add (T, makeadd (1 , 0 , args... )... )
694707 elseif f == (* )
695- T = rec_promote_symtype (f, map (symtype, args) ... )
708+ T = _promote_symtype (f, args)
696709 Mul (T, makemul (1 , args... )... )
697710 elseif f == (^ ) && length (args) == 2
698711 Pow (args... )
0 commit comments