compare - SML - Finding Reals In A Range -
i have task of taking list of reals , returning list containing elements >= 1.0 , <= 2.0, using list.filter anonymous function , list of reals.
i'm unsure of how check elements against conditions, i've tried far
filter(fn x => 1.0 <= x <= 2.0) r where r list of reals. what's way if else in anonymous function?
you're on right track, cannot 1.0 <= x <= 2.0.
1.0 <= x <= 2.0 means (1.0 <= x) <= 2.0, let's x = 1.5, gives (1.0 <= 1.5) <= 2.0, same true <= 2.0, makes no sense.
instead, need check both 1.0 <= x , x <= 2.0, using andalso combine 2 boolean expressions:
1.0 <= x andalso x <= 2.0 compare sml
No comments:
Post a Comment