finos/morphir-elm

Remove BoolLiteral and replace with reference to SDK constructors

Aberta

#51 aberto em 4 de abr. de 2020

 (0 comentário) (0 reação) (0 responsável)Elm (69 forks)auto 404
enhancementgood first issueir-simplification

Métricas do repositório

Stars
 (51 estrelas)
Métricas de merge de PR
 (Mesclagem média 3h 4m) (2 fundiu PRs em 30d)

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)

Guia do colaborador