Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor SDK to fix multiple issues #101

Merged
merged 5 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/error-append-not-supported.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ++ operator assumes a type inferencer that can tell the difference between String and List. These are the only
two types that are part of the `appendable` type-class. Until the type inferencer is available we will error out to
remove ambiguity.
11 changes: 5 additions & 6 deletions src/Morphir/Elm/Frontend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ import Morphir.IR.Package as Package
import Morphir.IR.Path as Path exposing (Path)
import Morphir.IR.QName as QName
import Morphir.IR.SDK as SDK
import Morphir.IR.SDK.Appending as Appending
import Morphir.IR.SDK.Bool as Bool
import Morphir.IR.SDK.Comparison as Comparison
import Morphir.IR.SDK.Composition as Composition
import Morphir.IR.SDK.Comparable as Comparison
import Morphir.IR.SDK.Equality as Equality
import Morphir.IR.SDK.Float as Float
import Morphir.IR.SDK.Function as Function
import Morphir.IR.SDK.Int as Int
import Morphir.IR.SDK.List as List
import Morphir.IR.SDK.Number as Number
Expand Down Expand Up @@ -1029,7 +1028,7 @@ mapOperator sourceLocation op =
Ok <| Comparison.greaterThanOrEqual sourceLocation

"++" ->
Ok <| Appending.append sourceLocation
Err [ NotSupported sourceLocation "The ++ operator is currently not supported. Please use String.append or List.append. See docs/error-append-not-supported.md" ]

"+" ->
Ok <| Number.add sourceLocation
Expand All @@ -1050,10 +1049,10 @@ mapOperator sourceLocation op =
Ok <| Number.power sourceLocation

"<<" ->
Ok <| Composition.composeLeft sourceLocation
Ok <| Function.composeLeft sourceLocation

">>" ->
Ok <| Composition.composeRight sourceLocation
Ok <| Function.composeRight sourceLocation

"::" ->
Ok <| List.construct sourceLocation
Expand Down
4 changes: 4 additions & 0 deletions src/Morphir/IR/SDK.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import Morphir.IR.Package as Package exposing (PackagePath)
import Morphir.IR.Path as Path exposing (Path)
import Morphir.IR.SDK.Bool as Bool
import Morphir.IR.SDK.Char as Char
import Morphir.IR.SDK.Comparable as Comparable
import Morphir.IR.SDK.Float as Float
import Morphir.IR.SDK.Function as Function
import Morphir.IR.SDK.Int as Int
import Morphir.IR.SDK.List as List
import Morphir.IR.SDK.Maybe as Maybe
Expand All @@ -24,8 +26,10 @@ packageSpec =
Dict.fromList
[ ( [ [ "bool" ] ], Bool.moduleSpec )
, ( [ [ "char" ] ], Char.moduleSpec )
, ( [ [ "comparable" ] ], Comparable.moduleSpec )
, ( [ [ "int" ] ], Int.moduleSpec )
, ( [ [ "float" ] ], Float.moduleSpec )
, ( [ [ "function" ] ], Function.moduleSpec )
, ( [ [ "string" ] ], String.moduleSpec )
, ( [ [ "maybe" ] ], Maybe.moduleSpec )
, ( [ [ "result" ] ], Result.moduleSpec )
Expand Down
26 changes: 0 additions & 26 deletions src/Morphir/IR/SDK/Appending.elm

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Morphir.IR.SDK.Comparison exposing (..)
module Morphir.IR.SDK.Comparable exposing (..)

import Dict
import Morphir.IR.Module as Module exposing (ModulePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Morphir.IR.SDK.Composition exposing (..)
module Morphir.IR.SDK.Function exposing (..)

import Dict
import Morphir.IR.Module as Module exposing (ModulePath)
Expand All @@ -9,7 +9,7 @@ import Morphir.IR.Value as Value exposing (Value)

moduleName : ModulePath
moduleName =
Path.fromString "Composition"
Path.fromString "Function"


moduleSpec : Module.Specification ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Morphir.SDK.Comparison exposing (lessThan, greaterThan, lessThanOrEqual, greaterThanOrEqual, max, min, compare, Order)
module Morphir.SDK.Comparable exposing (lessThan, greaterThan, lessThanOrEqual, greaterThanOrEqual, max, min, compare, Order)

{-| Comparing ordered values.

Expand Down
6 changes: 3 additions & 3 deletions src/Morphir/SDK/Float.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ values like this:

halfOf : Int -> Float
halfOf number =
toFloat number / 2
fromInt number / 2

-}
toFloat : Int -> Float
toFloat =
fromInt : Int -> Float
fromInt =
Basics.toFloat


Expand Down
43 changes: 3 additions & 40 deletions src/Morphir/SDK/Basics.elm → src/Morphir/SDK/Function.elm
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
module Morphir.SDK.Basics exposing
( append
, identity, always
, composeLeft, composeRight
)
module Morphir.SDK.Function exposing (identity, always, composeLeft, composeRight)

{-| Mirror of the `Basics` module in `elm/core` with some modifications for Morphir:
{-| Function helpers for Morphir:

- Operators are replaced with named functions.
- The Morphir Elm frontend maps operators to these named functions.
- `Never` type and `never` value are excluded since business logic should never use these.
- `<|` and `|>` operators are excluded since they are purely syntactic.
- The Morphir Elm frontend replaces `<|` with simple function application and `|>` with function application wit
reversed argument order.
- Some functions excluded do to being too graphics specific:
- degrees, radians, turns, toPolar, fromPolar


# Append Strings and Lists

@docs append


# Function Helpers

@docs identity, always, apL, apR, composeL, composeR
@docs identity, always, composeLeft, composeRight

-}

-- APPEND


{-| Put two appendable things together. This includes strings and lists.

"hello" ++ "world" == "helloworld"

[ 1, 1, 2 ] ++ [ 3, 5, 8 ] == [ 1, 1, 2, 3, 5, 8 ]

-}
append : appendable -> appendable -> appendable
append =
(++)



-- FUNCTION HELPERS


Expand Down
10 changes: 4 additions & 6 deletions tests/Morphir/Elm/FrontendTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import Morphir.IR.Literal exposing (Literal(..))
import Morphir.IR.Name as Name
import Morphir.IR.Package as Package
import Morphir.IR.Path as Path
import Morphir.IR.SDK.Appending as Appending
import Morphir.IR.SDK.Bool as Bool
import Morphir.IR.SDK.Comparison as Comparison
import Morphir.IR.SDK.Composition as Composition
import Morphir.IR.SDK.Comparable as Comparison
import Morphir.IR.SDK.Equality as Equality
import Morphir.IR.SDK.Float as Float
import Morphir.IR.SDK.Function as Function
import Morphir.IR.SDK.Int as Int
import Morphir.IR.SDK.List as List
import Morphir.IR.SDK.Maybe as Maybe
Expand Down Expand Up @@ -312,15 +311,14 @@ valueTests =
, checkIR "a > b" <| binary Comparison.greaterThan (ref "a") (ref "b")
, checkIR "a <= b" <| binary Comparison.lessThanOrEqual (ref "a") (ref "b")
, checkIR "a >= b" <| binary Comparison.greaterThanOrEqual (ref "a") (ref "b")
, checkIR "a ++ b" <| binary Appending.append (ref "a") (ref "b")
, checkIR "a + b" <| binary Number.add (ref "a") (ref "b")
, checkIR "a - b" <| binary Number.subtract (ref "a") (ref "b")
, checkIR "a * b" <| binary Number.multiply (ref "a") (ref "b")
, checkIR "a / b" <| binary Float.divide (ref "a") (ref "b")
, checkIR "a // b" <| binary Int.divide (ref "a") (ref "b")
, checkIR "a ^ b" <| binary Number.power (ref "a") (ref "b")
, checkIR "a << b" <| binary Composition.composeLeft (ref "a") (ref "b")
, checkIR "a >> b" <| binary Composition.composeRight (ref "a") (ref "b")
, checkIR "a << b" <| binary Function.composeLeft (ref "a") (ref "b")
, checkIR "a >> b" <| binary Function.composeRight (ref "a") (ref "b")
, checkIR "a :: b" <| binary List.construct (ref "a") (ref "b")
, checkIR "::" <| List.construct ()
, checkIR "foo (::)" <| Apply () (ref "foo") (List.construct ())
Expand Down