Haskell confusion (81)

59 Name: #!/usr/bin/anonymous : 2006-04-04 11:52 ID:OPMPwlS+

>>57
It's pretty trivial to use named arguments in perl if you simply suck @_ (the arguments list) into a hash; from there it's likewise pretty trivial to conditionally do stuff or not based on the presence of a given key in said hash. I don't know if this is quite what you're talking about. A quick example might be a socket wrapper that takes an address and an optional port (a fairly common scenario):

sub contrived_socket_wrapper {

my (%args) = @_;
die "contrived_socket_wrapper needs an address" if not $args{'address'};
$args{'port'} = 23 if not $args{'port'};
#... connect to host $args{'address'} on port $args{'port'}...

}

This can then be called like:

contrived_socket_wrapper (address=>'localhost'); # uses default port
contrived_socket_wrapper (address=>'localhost', port=>45); # uses port 45

This thread has been closed. You cannot post in this thread any longer.