This question is taken from an exam. I don’t know how to do that. 🙁
Question: Give an example of a haskell or ml function whose type is
( a -> b ) -> ( c -> a ) -> c -> b
How to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What meaningful function could have the type
mystery :: ( a -> b ) -> ( c -> a ) -> c -> b?Let’s see, what could
be?
It has three things to work with,
xof typec,gof typec -> aandfof typea -> b.It shall produce a value of type
b.The only argument that has anything to do with
bis the functionf, so the result must bef ???.What can be the argument of
fhere? It must have typea, and the only way to produce a value of that type from the given arguments (ignoring bottoms,undefined,error "foo") is applyinggto something, so it must beBut what could
gbe applied to? That must be a value of typec. Apart from bottoms, the only value of typecthat can be constructed from the arguments isx, somust be function composition (or undefined).