[m-users.] How to decompose a term with a variable data constructor
Volker Wysk
post at volker-wysk.de
Tue Nov 2 04:29:23 AEDT 2021
Hi.
I have a simple term type, like this:
:- type tterm
---> thema(string)
; und(tterm, tterm)
; oder(tterm, tterm).
Now I want to decompose such a term:
Konstr(T1, T2) = und(thema("aaa"), thema("bbb"))
Konstr is a ground variable, which has been passed as an input argument to
my predicate. T1 and T2 are free variables. My idea was that the above
statement should succeed if Konstr is "und", and fail otherwise. This would
mean to pass "und" to the predicate as a function of type (func(tterm,tterm)
= tterm). But this won't work.
I realize that the compiler can't unify a function call with a discriminated
union. This would mean to calculate the function backwards - the arguments
from the result.
Now, my question is: How can you decompose a discriminated union when the
data constructor isn't known at compile time? Something like
Constr(T1, T2) = und(thema("aaa"), thema("bbb"))
which would result in
Constr = und, % ???
T1 = thema("aaa"),
T2 = thema("bbb")
Cheers,
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20211101/6cd97e62/attachment.sig>
More information about the users
mailing list