[m-users.] Using type constructors in predicate heads
Sean Charles (emacstheviking)
objitsu at gmail.com
Mon Nov 8 01:56:02 AEDT 2021
I had actually done that earlier Zoltan by declaring a type
:- type callable —> callable(string, list(snode)).
but I felt that this was me giving in to the compiler. Thanks again for your feedback though, today I learned a new word,
superhomogeneous
which feels like it is to do with milk but as we know it isn't.
Great list,
Thanks all once again,
Sean.
> On 7 Nov 2021, at 13:45, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
>
> 2021-11-07 15:11 GMT+11:00 "Julien Fischer" <jfischer at opturion.com>:
>>>> :- type snode
>>> ---> sexp(location, list(snode))
>>> ; list(location, list(snode))
>>> ; map(location, list(snode))
>>> ; tk(location,string)
>>> ; kw(location, string)
>>> ; s1(location,string)
>>> ; s2(location,string)
>
> Julien answered your question as you asked it, but there is
> something else you could do to achieve your goal that falls outside
> the strict parameters of your question: changing the snode type
> to create single structure holding all the info about sexp's.
> Specifically, you could define a new type like this:
>
> :- type sexp_info
> ---> sexp_info(location, list(snode)).
>
> and then update the snode type like this:
>
> :- type snode
> ----> sexp(sexp_info)
> ; ....
>
> This way, after you have tested that a variable of type snode
> is bound to sexp, you could pass an sexp_info to other predicates;
> you wouldn't have to pass the whole snode.
>
> I find this solution to be better when there is a lot of code
> that needs to work with the info associated with one function symbol
> (sexp in this case) that does not care about the other function symbols
> in that type. Of course, I don't know whether that is the case in your application.
>
> Zoltan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20211107/ef0ea072/attachment.html>
More information about the users
mailing list