[mercury-users] Why not using constructors as HO functions ?

Holger Krug hkrug at rationalizer.com
Thu Jul 26 17:25:14 AEST 2001


I tried to use a constructor as a function in a place where a higher
order argument is expected, but this seems to be impossible. Wouldn't
it be nice syntactical sugar to allow constructors to be treated as
functions in this sense ? The following code shows an example:

% The code:

% Declarations:

:- type annotated_lexeme(Token)
    ==      lexeme(annotated_token(Token)).

:- type lexeme(Token)
    --->    lexeme(
                lxm_token         :: Token,
                lxm_regexp        :: regexp
            ).

:- type annotated_token(Token)
    --->    t(token_creator(Token))   % Return ok(apply(TokenCreator, Match))
                                      % on success.
    ;       noval(Token)              % Just return ok(Match) on success
    ;       ignore.                   % Just skip over these tokens.

:- type token_creator(Token) == (func(string)=Token).

:- func lexemes = list(annotated_lexeme(token)).

:- type token
    --->    comment(string)
    ;	    .....
    .

% This works:

lexemes = [
    lexeme( t(func(Match) = comment(Match)), (atom('%') >> junk))
    .....
          ].

% This does not work, but would be a nice syntactical shortcut:

lexemes = [
    lexeme( t(comment),	(atom('%') >> junk)),
    .....
          ].


-- 
Holger Krug
hkrug at rationalizer.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