[mercury-users] define predicate with currying?

Michael Hendricks michael at ndrix.org
Thu Jan 5 22:12:09 AEDT 2012


I have the following simple program:

    main(!IO) :-
        hello([s("World")], !IO),
        hello([s("Mercury")], !IO).

    :- pred hello(list(string.poly_type)::in, io::di, io::uo).
    hello(Xs,!IO) :- format("Hello, %s!\n",Xs,!IO).

Is it possible to define 'hello' by currying 'format'?  In Haskell,
I'd do something like

    hello :: String -> IO ()
    hello = printf "Hello, %s!\n"

The best I could come up with in Mercury was

    main(!IO) :-
        Hello = format("Hello, %s!\n"),
        Hello([s("World")], !IO),
        Hello([s("Mercury")], !IO).

Of course, that only defines 'Hello' locally.  I was hoping for a
global definition.

Thanks.

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