finos/morphir-elm

Remove BoolLiteral and replace with reference to SDK constructors

オープン

#51 opened on 2020/04/04

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)Elm (69 件のフォーク)auto 404
enhancementgood first issueir-simplification

Repository metrics

Stars
 (51 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Boolean values are currently represented in the IR as built-in literals. The Bool type though is in the SDK as an opaque type. An alternative representation for Booleans is a custom type:

type Bool = True | False

This representation does not require literal boolean values because you can use the type True, False constructors instead. The net result is that the IR becomes smaller and there are less specific cases to handle.

The specific change is to remove boolean literals here: https://github.com/finos/morphir-elm/blob/5e18e70bd4631aea1d1b677be04b62de3069a5eb/src/Morphir/IR/Literal.elm#L36

Then change Bool from opaque to a custom type in the SDK: https://github.com/finos/morphir-elm/blob/5e18e70bd4631aea1d1b677be04b62de3069a5eb/src/Morphir/IR/SDK/Basics.elm#L41

And add utility functions to refer to True and False constructors conveniently:

true : a -> Value ta a
true a =
    Value.Constructor a (toFQName moduleName "True")

false : a -> Value ta a
false a =
    Value.Constructor a (toFQName moduleName "False")

Finally, replace all BoolLiterals in the codebase using the following substitution rule:

Value.Literal a (BoolLiteral v) -> 
    if v then 
        (Morphir.IR.SDK.Basics.true a) 
    else 
        (Morphir.IR.SDK.Basics.false a)

コントリビューターガイド