Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AND operator in IF statements in SML

Tags:

sml

ml

smlnj

I am new to SML. How do I use the AND operator inside IF statements? Here is my code:

val y = 1;
val x = 2;
if (x = 1 AND y = 2) then print ("YES ") else print("NO ");

My error is: stdIn:66.9-67.3 Error: unbound variable or constructor: AND stdIn:66.3-67.9 Error: operator is not a function [literal] operator: int in expression: 1 stdIn:66.3-67.9 Error: operator and operand don't agree [literal] operator domain: bool * bool operand: bool * int in expression: x = (1 ) y = 2

Thank you

like image 667
Shaolin Rabbi Avatar asked Nov 17 '12 12:11

Shaolin Rabbi


1 Answers

There is no AND operator in SML (unless you define one yourself). There is an and keyword, but you can't use it inside if statements (or generally as a part of any expression) because it's not an operator. It's used in combination with fun to define mutually recursive functions.

You're probably looking for the andalso operator, which takes two boolean operands and returns true if and only if both operands are true.

like image 186
sepp2k Avatar answered Sep 27 '22 16:09

sepp2k