[mercury-users] Can this be done better?
Richard O'Keefe
ok at cs.otago.ac.nz
Tue Jan 31 12:47:50 AEDT 2012
On 31/01/2012, at 4:09 AM, Michael Richter wrote:
> main(!IO) :-
> Forward = [math.sin, math.cos, (func(X) = math.ln(X))],
> Reverse = [math.asin, math.acos, (func(X) = math.exp(X))],
> Results = list.map_corresponding(
> (func(F, R) = compose(R, F, 0.5)), Forward, Reverse),
>
> io.write_list(Results, ", ", io.write_float, !IO),
> io.write_string("\n", !IO).
>
> THIS is awesome, however! There's a lot of stuff in the standard library, but the documentation is … a wee bit terse. I completely overlooked that one.
When I had a similar problem some time back, map_corresponding is what I went
looking for. I was *expecting* it to be called zipWith (as in Haskell's List
module) or map (as in SML's ListPair module, or Quintus Prolog's 'lists' one).
map2 looked pretty close, but had the wrong modes.
Haskell has a nice feature: you can look up a function in the core libraries
by giving its type signature. Visit http://www.haskell.org/hoogle/
and type
(a -> b -> c) -> [a] -> [b] -> [c]
into the search box. It should be possible to adapt this to Mercury.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list