[mercury-users] What mode is necessary?

Ralph Becket rafe at cs.mu.OZ.AU
Wed Nov 20 22:17:17 AEDT 2002


Mike Potanin, Wednesday, 20 November 2002:
> 
>  Hi!
> I want to make pred which receives on an input list_skel(free)
> and ground on an output. Like satisfy_request from manual.

The compiler does not yet handle partially instantiated
structures.  The reference manual defines the language; the compiler
is not yet a complete implementation of the language.

> I make code:
> :-inst listskel(Inst) == bound( [] ; [Inst | listskel(Inst)] ).

The list library defines an identical inst called list_skel.

> :-pred preffix(list(T), list(T)).
> :-mode preffix(listskel(free)>>listskel(ground), in) is semidet.
> %:-mode preffix(listskel(free)>>ground, in) is semidet.

[Are you sure you don't mean `prefix' for the name here?]

> and want use preffix([X,Y], [1,2,3,4]) where X, Y is free.
> But this code do not compile.
> What mode is necessary for first argument of preffix?
> mmc --infer-modes do not infered it.

We do have a branch of the compiler that can handle this sort of
thing, but it has not been integrated with the main branch.  There
are compile-time efficiency issues with it that have not been solved.

The simplest solution is to use take_upto/2 as defined in the list library:

	[X, Y] = take_upto(2, [1, 2, 3, 4])

> Similar code on Curry work:
> 
> preffix [] _ = success
> preffix (x:t) (y:t1) | x =:= y = preffix t t1
> 
> goal | preffix [x,y] [1,2,3,4] = (x,y)
>   where
>     x free
>     y free

There's some debate as to whether we really want to support partially
instantiated structures.  It's not clear that the few good examples of
their use justify the obfuscated coding style they also make possible!

- Ralph
--------------------------------------------------------------------------
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