From: Alan P. <ap...@re...> - 2003-05-22 22:33:06
|
In article <200...@ro...eak>, Michal Moskal wrote: > > 1) For extList: > > val partial_map : ('a -> 'b option) -> 'a list -> 'b list > > let rec partial_map f = function > | x :: xs -> > begin > match f x with > | Some y -> y :: list_partial_map f xs > | None -> list_partial_map f xs > end > | [] -> [] The perl map function allows the number of outgoing items to be other than 1, for instance: my @l2 = map { if ( filter( $_ ) { $_ } else {()}} @l1; or: my %h = map { $_, f( $_ )} @l; I imagine it would be a bit tricky to implement an Enum function like that ("merge_map"?), but it would generalize the partial map function above. A more general question: how many map/iterate functions will be a part of the data structures, as opposed to having users stick to the Enum versions? For instance, List.map f l vs List.of_enum (Enum.map f (List.enum l)) Will each datastructure have its own map function, to make things convenient for users? |