[mercury-users] List comprehensions?
Pavel Zolnikov
pavelzolnikov at yahoo.com
Sat Apr 28 23:28:58 AEST 2001
That was nice. How about partial application of a curried function ?
[Haskell]
add::Intetger->Integer->Integer
add x y = x + y
inc::Integer->Integer
inc = add 1
With best regards,
Pavel.
----- Original Message -----
From: "Robert Bossy" <bossy at ccr.jussieu.fr>
To: <mercury-users at cs.mu.OZ.AU>
Sent: Saturday, April 28, 2001 8:37 AM
Subject: Re: [mercury-users] List comprehensions?
> > The list comprehensions in the functional programming language Clean
> > are a very compact and powerful way to express list manipulation. For
> > example the square of all integers from 1 to 10 that are not dividable
> > by three are computed by the program:
> >
> > Start = [n*n \\ n <- [1..10] | n rem 3 <> 0]
>
> Of course it is possible, thanks to higher order predicates and functions:
>
> Start = filter_map((func(N) = N * N is semidet :- N mod 3 \= 0),1 `..`
10).
>
>
> The list module has a lot of useful HO predicates and funcs:
> map to translate a list to another, element per element
> filter to select some elements from a list
> foldl to compute a value from the successive elements of a list
> etc.
>
> filter_map combines the map and filter fonctionalities and could be
defined as:
>
> :- func list__filter_map(func(X) = Y, list(X)) = list(Y).
> :- mode list__filter_map(func(in) = out is semidet, in) = out is det.
> filter_map(_function,[]) = [].
> filter_map(Function,[Hd0|Tl]) = L :-
> (
> if Hd = Function(Hd0)
> then L = [Hd|filter_map(Function,Tl)]
> else L = filter_map(Function,Tl)
> ).
>
>
>
> Regards,
>
> --
> sig(Robert,Bossy) :-
> bossy at ccr.jussieu.fr
> .
> --------------------------------------------------------------------------
> 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
> --------------------------------------------------------------------------
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--------------------------------------------------------------------------
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