Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request #3715

Closed
vicuna opened this issue Jul 5, 2005 · 2 comments
Closed

Feature request #3715

vicuna opened this issue Jul 5, 2005 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Jul 5, 2005

Original bug ID: 3715
Reporter: administrator
Status: closed
Resolution: won't fix
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

I looked all through the standard list library for a function like
this and couldn't find it, but it should definately be in there.

let rec apply n list =
match list with
[] -> []
| h::t -> (h n) :: (apply n t);;
val apply : 'a -> ('a -> 'b) list -> 'b list =

or tail recursively...

let rec apply n list res =
match list with
[] -> res
| h::t -> (apply n t) ((h n) :: res);;
val apply : 'a -> ('a -> 'b) list -> 'b list =

@vicuna
Copy link
Author

vicuna commented Jul 8, 2005

Comment author: administrator

I looked all through the standard list library for a function like
this and couldn't find it, but it should definately be in there.

let rec apply n list =
match list with
[] -> []
| h::t -> (h n) :: (apply n t);;
val apply : 'a -> ('a -> 'b) list -> 'b list =

It's not in the standard library because:

  1. It is not often needed.
  2. It's a one-liner:

let apply n list = List.map (fun f -> f n) list;;

BTW, your tail-recursive version is broken.

-- Damien

@vicuna
Copy link
Author

vicuna commented Jul 8, 2005

Comment author: administrator

wish denied DD 2005-07-08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant