I would like to implement a function which gets as input f g a when f g are lambda functions and a is a parameter. The function should do as following:
fun foo f g a = if (g a) then (f a) else a;
> val foo = fn : ('a -> 'a) -> ('a -> bool) -> 'a -> 'a
Is it possible to somehow replace if-else with andalso,orelse, or some other method? I would like to implement a function without using if-else statements.
Edit: Looking for a way to combine two functions, one of them is 'a -> 'a while the other one is 'a -> bool.
(fn x => if (g x) then (f x) else x)and I would like somehow to remove theif-elsestatements.aandf ahave type 'a, I'm not sure if there is a more elegant way to do it. (You can only replace if-then-else with andalso/orelse when the type of the branches are bool.) But maybe changing the names and order of the identifiers will make it more readable. I'd still like to see the context.