[m-users.] Higher-order predicate issue
Sean Charles (emacstheviking)
objitsu at gmail.com
Sun Oct 3 21:03:13 AEDT 2021
Thank you Zoltan and Peter then!
After a little more head scratching and using my go-to help tool, the mmc-doc sources, I have managed to work it out and I now have the following:
64 :- type renderer == (pred(render_inst, rop_error, tcon, tcon)).
65 :- mode renderer == (pred(in, out, in, out) is det).
:
106 Renderer = get_target_renderer(Target),
:
155 :- func get_target_renderer(string::in) = (renderer::out(renderer)).
156 :- inst renderer == (pred(in, out, in, out) is det).
157
158 get_target_renderer(T) = R :-
159 LCTarget = string.to_lower(T),
160 ( if LCTarget = "php" then
161 R = target_c.render
162 else
163 R = target_c.render
164 ).
And it all works beautifully, thank you both for your guidance and assitance. I am not 100% sure I totally understand what’s going on but using mmc-doc’s definition of:
:- type maybeio == (pred(maybe(string), io, io)).
:- inst maybeio == (pred(out, di, uo) is det).
:- func (maybeio::in(maybeio)) // (maybeio::in(maybeio))
= (maybeio::out(maybeio)).
I managed to work it out and then referred back to section 4.1 on Modes and section 8 Higher-order programming for some closure on the matter, at leat for now. I will spend some more time on it later but The Boss she now insists I have to mow the lawn front and back. Meh.
Thanks as always,
Sean.
> On 2 Oct 2021, at 22:25, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
>
> 2021-10-03 07:11 GMT+11:00 "Sean Charles (emacstheviking)" <objitsu at gmail.com>:
>> :- func get_target_renderer(string::in) = (renderer::out).
>
> This is mirror image of the bug Peter pointed out yesterday:
> the result of this function should have mode "out(renderer)"
> instead of just "out". Declaring the result to have mode "out"
> also throws away the mode information about the higher order
> result, so it is not surprising that you get mode errors when
> that higher order mode information is needed but not present,
> i.e. what you call Renderer.
>
> Zoltan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20211003/b3537438/attachment.html>
More information about the users
mailing list