Elm-operators

提供:Dev Guides
移動先:案内検索

エルム-演算子

演算子は、データに対して実行される機能を定義します。 演算子が機能する値は、オペランドと呼ばれます。 次の式を考えてください

7 + 5 = 12

ここで、値7、5、および12はオペランドであり、+および=は演算子です。

エルムの主要な演算子は次のように分類できます-

  • 算術
  • リレーショナル
  • 論理的

算術演算子

変数aおよびbの値がそれぞれ7および2であると仮定します。

link:/elm/elm_arithmatic_operators [例を表示]

Sr. No. Operator Description Example
1 +(Addition) returns the sum of the operands a+b is 9
2 -(Subtraction) returns the difference of the values a-b is 5
3 * (Multiplication) returns the product of the values a*b is 14
4 /(Float Division) performs division operation and returns a float quotient a/b is 3.5
5 //(Integer Division) performs division operation and returns a integer quotient a//b is 3
6 % (Modulus) performs division operation and returns the remainder a % b is 1

関係演算子

関係演算子は、2つのエンティティ間の関係の種類をテストまたは定義します。 これらの演算子は、2つ以上の値を比較するために使用されます。 関係演算子はブール値を返します。 正しいか間違っているか。

_a_の値が10で、_b_が20であると仮定します。

link:/elm/elm_relational_operators [例を表示]

Sr. No. Operator Description Example
1 > Greater than (a > b) is False
2 < Lesser than (a < b) is True
3 >= Greater than or equal to (a >= b) is False
4 Lesser than or equal to (a ⇐ b) is True
5 == Equality (a == b) is false
6 != Not equal (a != b) is True

比較可能なタイプ

=や<などの比較演算子は、比較可能な型で機能します。 これらは、数字、文字、文字列、リスト、タプルとして定義されます。 演算子の両側の比較可能な型は同じでなければなりません。

Sr. No. Comparable Type Example
1 number 7>2 gives True
2 character 'a' =='b' gives False
3 string "hello" =="hello" gives True
4 tuple (1,"One")==(1,"One") gives True
5 list [1,2]==[1,2] gives True

elm REPLを開き、以下に示す例を試してください-

C:\Users\admin>elm repl
---- elm-repl 0.18.0 -----------------------------------------------------------
:help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> 7>2
True : Bool
> 7.0>2
True : Bool
> 7.0<2.0
False : Bool
> 'a' > 'b'
False : Bool
> 'a' < 'b'
True : Bool
> "a" < "b"
True : Bool
> (1,2) > (2,3)
False : Bool
> ['1','3'] < ['2','1']
True : Bool
>

論理演算子

論理演算子は、2つ以上の条件を結合するために使用されます。 論理演算子もブール値を返します。

link:/elm/elm_logical_operators [例を表示]

Sr. No. Operator Description Example
1 && The operator returns true only if all the expressions specified return true (10>5) && (20>5) returns True
2
The operator returns true if at least one of the expressions specified return true (10 < 5) (20 >5) returns True
3 not The operator returns the inverse of the expression’s result. For E.g.: !(>5) returns false. not (10 < 5) returns True
4 xor The operator returns true only if exactly one input returns true. The operator returns false if both the expressions return true. xor (10 > 5 ) (20 > 5) returns false