Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

If-then-else

💡 お知らせ: このドキュメントはAIによって翻訳されています。表現に違和感がある場合は、原文(英語)を参照するか、翻訳にご協力ください。

Flix は、おなじみの if-then-else 式をサポートしています。

if (1 == 1) "Hello" else "World"

これは Hello に評価されます。

加えて、if ガードは言語の他の部分でもサポートされています。

ガード付きパターンマッチ

パターンマッチの中で if ガードを使えます。

def isSquare(s: Shape): Bool = match s {
    case Rectangle(h, w) if h == w => true
    case _                         => false
}

ガード付き Datalog ルール

Datalog ルールの中で if ガードを使えます。

Path(x, z) :- Path(x, y), Edge(y, z), if (x != z).

ガードを囲む括弧は必須である点に注意してください。