From an old exam I had this SML function and I should give an answer on what this function calculates.
fun guess(e,(a,b)) = if e then (a,b) else (b,a)
The signature is bool * ('a * 'a) -> 'a * 'a
but I have no clue what the purpose of this function is - despite the fact that it returns either (a,b) or (b,a).
Can anyone light me up?
If the condition is true it leaves (a,b) alone, otherwise it reverses it. There really isn't anything more to say about what it computes. As to borderline plausible motivation, sometimes ordered pairs need to be sorted in various ways. For example, guess(a<=b,(a,b))
will reverse (a,b) if a > b.