[m-dev.] Functional iteration schemata

Ralph Becket rbeck at microsoft.com
Wed Aug 22 23:02:05 AEST 2001


I've been toying around with some common functional sequence
iteration schemata to get something approximating sequence
quantification for nondet code or list comprehension in
languages like Haskell.

It allows for rather concise code, e.g.

:- func factors(int) = list({int, int}).

factors(N) =
    over_range(2, N,                    func(X) =
        over_list(2 `..` X,             func(Y) =
            provided(Y `factor_of` X,   func(A) =
                [{Y, X} | A]
            )
        )
    )([]).

and

:- func quotients(list({int, int})) = list(int).

quotients(Factors) =
    over_list(Factors, func({Y, X}) = cons(X // Y))([]).

I haven't thought much about other types of sequence, but I'd
like to hear any ideas/opinions.  Particularly, is there demand
for something like this as a library or extras module?  I've
attached some draft code to this e-mail.

- Ralph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seqs.m
Type: application/octet-stream
Size: 3641 bytes
Desc: seqs.m
URL: <http://lists.mercurylang.org/archives/developers/attachments/20010822/a4edff4a/attachment.obj>


More information about the developers mailing list