[mercury-users] More on higher order functions

Ralph Becket rbeck at microsoft.com
Thu Feb 10 23:25:32 AEDT 2000


Hi Tyson,

sorry about the delay in getting back to you.  

> I think the general premise is OK, but I'm not entirely sure where
> this idea applies in the code above.  Do you mean that the compiler
> doesn't assume the default func mode when you pass a data term which
> contains a field which is a higher order func?
> 
> I think this is a bug, I suspect it can be fixed.

If the following should work, then there's a bug in 0.9.1:

:- module funcmodes.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- import_module int.

:- type foo ---> foo(func(int) = int).

:- func bar(foo, int) = int.

bar(foo(F), X) = F(X).

main -->
    io__write_int(bar(foo(func(X) = X * X), 7)),
    io__nl.

The compiler comes back with

funcmodes.m:018: In clause for `bar(in, in) = out':
funcmodes.m:018:   in argument 1 (i.e. the function term) of higher-order
functi
on call:
funcmodes.m:018:   mode error: variable `F' has instantiatedness `ground',
funcmodes.m:018:   expecting higher-order func inst (of arity 1).
For more information, try recompiling with `-E'.

I've attached the .m and .err files.

On a vulgar, but amusing, note, the following has been doing the
rounds of the office:  go to www.amazon.co.uk and do a search
for `pointers in C' in the search box at the top-left :)

By the way, are we going to see you at the Project 7 meeting?

Cheers,

Ralph


begin 600 funcmodes.m
M#0HZ+2!M;V1U;&4 at 9G5N8VUO9&5S+ at T*#0HZ+2!I;G1E<F9A8V4N#0H-"CHM
M(&EM<&]R=%]M;V1U;&4@:6\N#0H-"CHM('!R960@;6%I;BAI;U]?<W1A=&4Z
M.F1I+"!I;U]?<W1A=&4Z.G5O*2!I<R!D970N#0H-"CHM(&EM<&QE;65N=&%T
M:6]N+ at T*#0HZ+2!I;7!O<G1?;6]D=6QE(&EN="X-"@T*.BT@='EP92!F;V\@
M+2TM/B!F;V\H9G5N8RAI;G0I(#T@:6YT*2X-"@T*.BT at 9G5N8R!B87(H9F]O
M+"!I;G0I(#T@:6YT+ at T*#0IB87(H9F]O*$8I+"!8*2`]($8H6"DN#0H-"FUA
M:6X at +2T^#0H@("`@:6]?7W=R:71E7VEN="AB87(H9F]O*&9U;F,H6"D@/2!8
:("H at 6"DL(#<I*2P-"B`@("!I;U]?;FPN#0H=
`
end

begin 600 funcmodes.err
M9G5N8VUO9&5S+FTZ,#$X.B!);B!C;&%U<V4 at 9F]R(&!B87(H:6XL(&EN*2`]
M(&]U="<Z#0IF=6YC;6]D97,N;3HP,3 at Z("`@:6X at 87)G=6UE;G0@,2`H:2YE
M+B!T:&4 at 9G5N8W1I;VX@=&5R;2D@;V8@:&EG:&5R+6]R9&5R(&9U;F-T:6]N
M(&-A;&PZ#0IF=6YC;6]D97,N;3HP,3 at Z("`@;6]D92!E<G)O<CH@=F%R:6%B
M;&4 at 8$8G(&AA<R!I;G-T86YT:6%T961N97-S(&!G<F]U;F0G+`T*9G5N8VUO
M9&5S+FTZ,#$X.B`@(&5X<&5C=&EN9R!H:6=H97(M;W)D97(@9G5N8R!I;G-T
M("AO9B!A<FET>2`Q*2X-"D9O<B!M;W)E(&EN9F]R;6%T:6]N+"!T<GD@<F5C
5;VUP:6QI;F<@=VET:"!@+44G+ at T*
`
end
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list