Question

I need help solving this problem using the ML programming language Write a function min3 of...

I need help solving this problem using the ML programming language

Write a function min3 of type int * int * int -> int that returns the smallest of three integers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The idea of finding min3 is by dividing it into min2.

for example.

Consider, if first number be smaller than second , then apply min2 of (first and third).

If first number is not smaller than second, then apply min2 of (second and third)

We have argument type as a 3-tuple.

It can be done in 2 ways.

Here, finding min3 of 3 Using a projection:

fun min3(t:int*int*int) = if (#1t < #2t) then if (#1t < #3t) then #1t else #3t else if (#2t < #3t ) then #2t else #3t;

Here, finding min3 Using a local declaration:

fun min3(t:int*int*int) = let val (a,b,c)=t in if (a<b) then if (a<c) then a else c else if (b<c) then b else c end;

OUTPUT:

**Thank You.**

Add a comment
Know the answer?
Add Answer to:
I need help solving this problem using the ML programming language Write a function min3 of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT