Map a function or predicate in Mercury lang

Mapping a function in Mercury lang is pretty simple. First you need a function:

:- func myfunc(string) = string.

myfunc(In) = Out :- 
  append(In, In, Out).

Then you map it

:- import_module list.

NewList = map(myfunc, OldList)

We can do the same thing with a predicate.

:- pred mypred(string::in, string::out) is det.

mypred(A, B) :- append(A, A, B).

Then you map it

:- import_module list.
map(mypred, OldList, NewList).

A more complete description of higher-order predicates and functions in Mercury can be found here.

And the map predicates can be found in the list module here.

social