i have a task to define two functions, one with type:
('a-> 'b) -> ('c -> 'a) -> 'c -> 'b
and second one with just
'a -> 'b
while the first function is composition and i've done that this way:
let compose f g arg = f(g(arg))
i'm stuck on the second one. could anyone lead me to correct answer? i made this one:
let a x = List.hd []
but im pretty sure there is much simplier example.
The first function is not currying, it's function composition. Currying has the type ('a * 'b -> 'c) -> 'a -> 'b -> 'c.
Your solution for 'a -> 'b is pretty good. Note that List.hd [] raises an exception. So another implementation is:
let f x = raise Not_found
The thing to realize is that no "nice" function can possibly have the given type. Where would it get an actual value of type 'b to return? It would have to be a value that can have any type at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With