finos/morphir-elm

Remove BoolLiteral and replace with reference to SDK constructors

Ouverte

#51 ouverte le 4 avr. 2020

 (0 commentaire) (0 réaction) (0 personne assignée)Elm (69 forks)auto 404
enhancementgood first issueir-simplification

Métriques du dépôt

Stars
 (51 étoiles)
Métriques de merge PR
 (Merge moyen 3h 4m) (2 PRs mergées en 30 j)

Description

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)

Guide contributeur