Skip to content

Commit

Permalink
Add Decimal type support in the SDK and Elm Frontend (#303)
Browse files Browse the repository at this point in the history
* #90 - Adding the Decimal type to Morphir SDK and Elm FronteEnd

* #90 Adding additional functions to Decimal SDK

* #90 - Bring SDK and IR.SDK inline with each ither

* #90 - Added helpers for common powers of 10

* #90 - Allow usage of the Decimal type in the Elm Frontend
  • Loading branch information
DamianReeves authored Jan 20, 2021
1 parent c95c17a commit 1f9d52d
Show file tree
Hide file tree
Showing 7 changed files with 682 additions and 1 deletion.
1 change: 1 addition & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"elm-explorations/test": "1.2.2 <= v < 2.0.0",
"justinmimbs/date": "3.2.1 <= v < 4.0.0",
"mdgriffith/elm-ui": "1.1.8 <= v < 2.0.0",
"prikhi/decimal": "2.0.0 <= v < 3.0.0",
"pzp1997/assoc-list": "1.0.0 <= v < 2.0.0",
"stil4m/elm-syntax": "7.1.3 <= v < 8.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/Morphir/Elm/Frontend/Resolve.elm
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ moduleMapping =
, ( [ [ "char" ] ], sdkModule [ "char" ] )
, ( [ [ "tuple" ] ], sdkModule [ "tuple" ] )
, ( [ [ "regex" ] ], sdkModule [ "regex" ] )
, ( [ [ "decimal" ] ], sdkModule [ "decimal" ] )
]


Expand Down
2 changes: 2 additions & 0 deletions src/Morphir/IR/SDK.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Morphir.IR.Package as Package exposing (PackageName)
import Morphir.IR.Path as Path exposing (Path)
import Morphir.IR.SDK.Basics as Basics
import Morphir.IR.SDK.Char as Char
import Morphir.IR.SDK.Decimal as Decimal
import Morphir.IR.SDK.Dict as Dict
import Morphir.IR.SDK.List as List
import Morphir.IR.SDK.LocalDate as LocalDate
Expand Down Expand Up @@ -61,6 +62,7 @@ packageSpec =
, ( [ [ "regex" ] ], Regex.moduleSpec )
, ( [ [ "stateful", "app" ] ], StatefulApp.moduleSpec )
, ( [ [ "rule" ] ], Rule.moduleSpec )
, ( [ [ "decimal" ] ], Decimal.moduleSpec )
]
}

Expand Down
62 changes: 62 additions & 0 deletions src/Morphir/IR/SDK/Decimal.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Morphir.IR.SDK.Decimal exposing (..)

import Dict
import Morphir.IR.Documented exposing (Documented)
import Morphir.IR.Module as Module exposing (ModuleName)
import Morphir.IR.Name as Name
import Morphir.IR.Path as Path exposing (Path)
import Morphir.IR.SDK.Basics exposing (boolType, floatType, intType, orderType)
import Morphir.IR.SDK.Common exposing (toFQName, vSpec)
import Morphir.IR.SDK.Maybe exposing (maybeType)
import Morphir.IR.SDK.String exposing (stringType)
import Morphir.IR.Type exposing (Specification(..), Type(..))


moduleName : ModuleName
moduleName =
Path.fromString "Decimal"


moduleSpec : Module.Specification ()
moduleSpec =
{ types =
Dict.fromList
[ ( Name.fromString "Decimal", OpaqueTypeSpecification [] |> Documented "Type that represents a Decimal." )
]
, values =
Dict.fromList
[ vSpec "fromInt" [ ( "n", intType () ) ] (decimalType ())
, vSpec "fromFloat" [ ( "f", floatType () ) ] (maybeType () (decimalType ()))
, vSpec "fromString" [ ( "str", stringType () ) ] (maybeType () (decimalType ()))
, vSpec "hundred" [ ( "n", intType () ) ] (decimalType ())
, vSpec "thousand" [ ( "n", intType () ) ] (decimalType ())
, vSpec "million" [ ( "n", intType () ) ] (decimalType ())
, vSpec "tenth" [ ( "n", intType () ) ] (decimalType ())
, vSpec "hundredth" [ ( "n", intType () ) ] (decimalType ())
, vSpec "millionth" [ ( "n", intType () ) ] (decimalType ())
, vSpec "bps" [ ( "n", intType () ) ] (decimalType ())
, vSpec "toString" [ ( "decimalValue", decimalType () ) ] (stringType ())
, vSpec "toFloat" [ ( "d", decimalType () ) ] (floatType ())
, vSpec "add" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (decimalType ())
, vSpec "sub" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (decimalType ())
, vSpec "negate" [ ( "value", decimalType () ) ] (decimalType ())
, vSpec "mul" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (decimalType ())
, vSpec "truncate" [ ( "n", intType () ), ( "d", decimalType () ) ] (decimalType ())
, vSpec "round" [ ( "n", intType () ), ( "d", decimalType () ) ] (decimalType ())
, vSpec "gt" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (boolType ())
, vSpec "eq" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (boolType ())
, vSpec "neq" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (boolType ())
, vSpec "lt" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (boolType ())
, vSpec "lte" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (boolType ())
, vSpec "compare" [ ( "a", decimalType () ), ( "b", decimalType () ) ] (orderType ())
, vSpec "abs" [ ( "value", decimalType () ) ] (decimalType ())
, vSpec "zero" [] (decimalType ())
, vSpec "one" [] (decimalType ())
, vSpec "minusOne" [] (decimalType ())
]
}


decimalType : a -> Type a
decimalType attributes =
Reference attributes (toFQName moduleName "Decimal") []
Loading

0 comments on commit 1f9d52d

Please sign in to comment.