finos/morphir-elm

Remove BoolLiteral and replace with reference to SDK constructors

Aperta

#51 aperta il 4 apr 2020

 (0 commenti) (0 reazioni) (0 assegnatari)Elm (69 fork)auto 404
enhancementgood first issueir-simplification

Metriche repository

Star
 (51 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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)

Guida contributor