Skip to content

Commit

Permalink
Changes suggested in the PR. finos#46, finos#25, finos#5
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaMihaly committed Apr 2, 2020
1 parent 9ce6d29 commit 910d4fa
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Morphir/Elm/Frontend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ mapDeclarationsToType sourceFile expose decls =
ctorArgsResult
|> Result.map
(\ctorArgs ->
( ctorName, ctorArgs )
Type.Constructor ctorName ctorArgs
)
)
|> ResultList.toResult
Expand Down
5 changes: 4 additions & 1 deletion src/Morphir/Elm/Frontend/Resolve.elm
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ createPackageResolver dependencies currentPackagePath currentPackageModules =
case typeDecl of
Type.CustomTypeSpecification _ ctors ->
ctors
|> List.map (Tuple.first >> Name.toTitleCase)
|> List.map
(\(Type.Constructor ctorName _) ->
ctorName |> Name.toTitleCase
)

_ ->
[]
Expand Down
4 changes: 2 additions & 2 deletions src/Morphir/IR/SDK.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Morphir.IR.SDK exposing (..)

import Dict
import Morphir.IR.Package as Package
import Morphir.IR.Path exposing (Path)
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.Float as Float
Expand All @@ -15,7 +15,7 @@ import Morphir.IR.SDK.String as String

packageName : Path
packageName =
[ [ "morphir" ], [ "s", "d", "k" ] ]
Path.fromString "Morphir.SDK"


packageSpec : Package.Specification ()
Expand Down
4 changes: 2 additions & 2 deletions src/Morphir/IR/SDK/Maybe.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ moduleSpec =
Dict.fromList
[ ( [ "maybe" ]
, CustomTypeSpecification [ [ "a" ] ]
[ ( [ "just" ], [ ( [ "value" ], Type.Variable () [ "a" ] ) ] )
, ( [ "nothing" ], [] )
[ Type.Constructor [ "just" ] [ ( [ "value" ], Type.Variable () [ "a" ] ) ]
, Type.Constructor [ "nothing" ] []
]
)
]
Expand Down
6 changes: 3 additions & 3 deletions src/Morphir/IR/SDK/Number.elm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Morphir.IR.SDK.Number exposing (..)
module Morphir.IR.SDK.Number exposing (negate)

import Dict
import Morphir.IR.FQName as FQName exposing (FQName)
import Morphir.IR.Module as Module
import Morphir.IR.Name as Name
import Morphir.IR.Path exposing (Path)
import Morphir.IR.Path as Path exposing (Path)
import Morphir.IR.QName as QName
import Morphir.IR.SDK.Common exposing (packageName)
import Morphir.IR.Type exposing (Specification(..), Type(..))
Expand All @@ -13,7 +13,7 @@ import Morphir.IR.Value as Value exposing (Value)

moduleName : Path
moduleName =
[ [ "number" ] ]
Path.fromString "Number"


moduleSpec : Module.Specification ()
Expand Down
4 changes: 2 additions & 2 deletions src/Morphir/IR/SDK/Result.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ moduleSpec =
Dict.fromList
[ ( [ "result" ]
, CustomTypeSpecification [ [ "e" ], [ "a" ] ]
[ ( [ "ok" ], [ ( [ "value" ], Type.Variable () [ "a" ] ) ] )
, ( [ "err" ], [ ( [ "error" ], Type.Variable () [ "e" ] ) ] )
[ Type.Constructor [ "ok" ] [ ( [ "value" ], Type.Variable () [ "a" ] ) ]
, Type.Constructor [ "err" ] [ ( [ "error" ], Type.Variable () [ "e" ] ) ]
]
)
]
Expand Down
47 changes: 23 additions & 24 deletions src/Morphir/IR/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Morphir.IR.Type exposing
, Field, matchField, mapFieldName, mapFieldType
, Specification(..), typeAliasSpecification, opaqueTypeSpecification, customTypeSpecification
, Definition(..), typeAliasDefinition, customTypeDefinition
, Constructors
, Constructors, Constructor(..)
, fuzzType
, encodeType, decodeType, encodeSpecification, encodeDefinition
, Constructor, definitionToSpecification, eraseAttributes, mapDefinition, mapSpecification, mapTypeAttributes, rewriteType
, definitionToSpecification, eraseAttributes, mapDefinition, mapSpecification, mapTypeAttributes, rewriteType
)

{-| This module contains the building blocks of types in the Morphir IR.
Expand Down Expand Up @@ -45,7 +45,7 @@ module Morphir.IR.Type exposing
# Constructors
@docs Constructors
@docs Constructors, Constructor
# Property Testing
Expand Down Expand Up @@ -127,8 +127,8 @@ type alias Constructors a =


{-| -}
type alias Constructor a =
( Name, List ( Name, Type a ) )
type Constructor a
= Constructor Name (List ( Name, Type a ))


definitionToSpecification : Definition a -> Specification a
Expand Down Expand Up @@ -164,15 +164,15 @@ mapSpecification f spec =
ctorsResult =
constructors
|> List.map
(\( ctorName, ctorArgs ) ->
(\(Constructor ctorName ctorArgs) ->
ctorArgs
|> List.map
(\( argName, argType ) ->
f argType
|> Result.map (Tuple.pair argName)
)
|> ResultList.toResult
|> Result.map (Tuple.pair ctorName)
|> Result.map (Constructor ctorName)
)
|> ResultList.toResult
|> Result.mapError List.concat
Expand All @@ -195,15 +195,15 @@ mapDefinition f def =
ctorsResult =
constructors.value
|> List.map
(\( ctorName, ctorArgs ) ->
(\(Constructor ctorName ctorArgs) ->
ctorArgs
|> List.map
(\( argName, argType ) ->
f argType
|> Result.map (Tuple.pair argName)
)
|> ResultList.toResult
|> Result.map (Tuple.pair ctorName)
|> Result.map (Constructor ctorName)
)
|> ResultList.toResult
|> Result.map (AccessControlled constructors.access)
Expand Down Expand Up @@ -272,14 +272,14 @@ eraseAttributes typeDef =
CustomTypeDefinition typeVars acsCtrlConstructors ->
let
eraseCtor : Constructor a -> Constructor ()
eraseCtor ( name, types ) =
eraseCtor (Constructor name types) =
let
extraErasedTypes : List ( Name, Type () )
extraErasedTypes =
types
|> List.map (\( n, t ) -> ( n, mapTypeAttributes (\_ -> ()) t ))
in
( name, extraErasedTypes )
Constructor name extraErasedTypes

eraseAccessControlledCtors : AccessControlled (Constructors a) -> AccessControlled (Constructors ())
eraseAccessControlledCtors acsCtrlCtors =
Expand Down Expand Up @@ -779,18 +779,17 @@ encodeConstructors : (a -> Encode.Value) -> Constructors a -> Encode.Value
encodeConstructors encodeAttributes ctors =
ctors
|> Encode.list
(\( ctorName, ctorArgs ) ->
Encode.object
[ ( "name", encodeName ctorName )
, ( "args"
, ctorArgs
|> Encode.list
(\( argName, argType ) ->
Encode.list identity
[ encodeName argName
, encodeType encodeAttributes argType
]
)
)
(\(Constructor ctorName ctorArgs) ->
Encode.list identity
[ Encode.string "Constructor"
, encodeName ctorName
, ctorArgs
|> Encode.list
(\( argName, argType ) ->
Encode.list identity
[ encodeName argName
, encodeType encodeAttributes argType
]
)
]
)
7 changes: 3 additions & 4 deletions tests/Morphir/Elm/FrontendTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ frontendTest =
, public
(Type.CustomTypeDefinition []
(public
[ ( [ "foo" ]
, [ ( [ "arg", "1" ], Type.Reference () (fQName packageName [ [ "b" ] ] [ "bee" ]) [] )
[ Type.Constructor [ "foo" ]
[ ( [ "arg", "1" ], Type.Reference () (fQName packageName [ [ "b" ] ] [ "bee" ]) [] )
]
)
]
)
)
Expand Down Expand Up @@ -149,7 +148,7 @@ frontendTest =
[ ( [ "bee" ]
, public
(Type.CustomTypeDefinition []
(public [ ( [ "bee" ], [] ) ])
(public [ Type.Constructor [ "bee" ] [] ])
)
)
]
Expand Down

0 comments on commit 910d4fa

Please sign in to comment.