-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Decimal type support in the SDK and Elm Frontend (#303)
* #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
1 parent
c95c17a
commit 1f9d52d
Showing
7 changed files
with
682 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") [] |
Oops, something went wrong.