diff --git a/review/src/ReviewConfig.elm b/review/src/ReviewConfig.elm index ac3570e8..dcd8b4a0 100644 --- a/review/src/ReviewConfig.elm +++ b/review/src/ReviewConfig.elm @@ -39,30 +39,29 @@ config : List Rule config = [ NoMissingTypeExpose.rule , NoUnused.Dependencies.rule - - -- , Docs.NoMissing.rule - -- { document = onlyExposed - -- , from = exposedModules - -- } - --, Docs.ReviewLinksAndSections.rule - --, Docs.ReviewAtDocs.rule - --, Docs.UpToDateReadmeLinks.rule - --, NoDebug.Log.rule - --, NoDebug.TodoOrToString.rule - -- |> Rule.ignoreErrorsForDirectories [ "tests/" ] - --, NoExposingEverything.rule - --, NoImportingEverything.rule [] - --, NoMissingTypeAnnotation.rule - --, NoMissingTypeAnnotationInLetIn.rule - --, NoSimpleLetBody.rule - --, NoPrematureLetComputation.rule - --, NoUnused.CustomTypeConstructors.rule [] - --, NoUnused.CustomTypeConstructorArgs.rule - --, NoUnused.Exports.rule - --, NoUnused.Parameters.rule - --, NoUnused.Patterns.rule - --, NoUnused.Variables.rule - --, Simplify.rule Simplify.defaults + , Docs.NoMissing.rule + { document = onlyExposed + , from = exposedModules + } + , Docs.ReviewLinksAndSections.rule + , Docs.ReviewAtDocs.rule + , Docs.UpToDateReadmeLinks.rule + , NoDebug.Log.rule + , NoDebug.TodoOrToString.rule + |> Rule.ignoreErrorsForDirectories [ "tests/" ] + , NoExposingEverything.rule + , NoImportingEverything.rule [] + , NoMissingTypeAnnotation.rule + , NoMissingTypeAnnotationInLetIn.rule + , NoSimpleLetBody.rule + , NoPrematureLetComputation.rule + , NoUnused.CustomTypeConstructors.rule [] + , NoUnused.CustomTypeConstructorArgs.rule + , NoUnused.Exports.rule + , NoUnused.Parameters.rule + , NoUnused.Patterns.rule + , NoUnused.Variables.rule + , Simplify.rule Simplify.defaults ] |> List.map (Rule.ignoreErrorsForDirectories diff --git a/review/suppressed/Docs.NoMissing.json b/review/suppressed/Docs.NoMissing.json new file mode 100644 index 00000000..4fe7a449 --- /dev/null +++ b/review/suppressed/Docs.NoMissing.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 32, "filePath": "src/Elm/Case/Branch.elm" }, + { "count": 29, "filePath": "src/Elm.elm" }, + { "count": 22, "filePath": "src/Elm/Annotation.elm" }, + { "count": 13, "filePath": "src/Elm/Case.elm" }, + { "count": 9, "filePath": "src/Elm/Let.elm" }, + { "count": 8, "filePath": "src/Elm/Declare.elm" }, + { "count": 6, "filePath": "src/Elm/ToString.elm" } + ] +} diff --git a/review/suppressed/Docs.ReviewAtDocs.json b/review/suppressed/Docs.ReviewAtDocs.json new file mode 100644 index 00000000..caa4ab64 --- /dev/null +++ b/review/suppressed/Docs.ReviewAtDocs.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 2, "filePath": "src/Elm.elm" } + ] +} diff --git a/review/suppressed/Docs.ReviewLinksAndSections.json b/review/suppressed/Docs.ReviewLinksAndSections.json new file mode 100644 index 00000000..ffeedf42 --- /dev/null +++ b/review/suppressed/Docs.ReviewLinksAndSections.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Elm.elm" } + ] +} diff --git a/review/suppressed/Docs.UpToDateReadmeLinks.json b/review/suppressed/Docs.UpToDateReadmeLinks.json new file mode 100644 index 00000000..f77b0272 --- /dev/null +++ b/review/suppressed/Docs.UpToDateReadmeLinks.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 2, "filePath": "README.md" } + ] +} diff --git a/review/suppressed/NoUnused.CustomTypeConstructorArgs.json b/review/suppressed/NoUnused.CustomTypeConstructorArgs.json new file mode 100644 index 00000000..c9391d9c --- /dev/null +++ b/review/suppressed/NoUnused.CustomTypeConstructorArgs.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Elm/Op.elm" }, + { "count": 1, "filePath": "src/Internal/Compiler.elm" } + ] +} diff --git a/review/suppressed/NoUnused.CustomTypeConstructors.json b/review/suppressed/NoUnused.CustomTypeConstructors.json new file mode 100644 index 00000000..c2a8979a --- /dev/null +++ b/review/suppressed/NoUnused.CustomTypeConstructors.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 4, "filePath": "src/Internal/Compiler.elm" }, + { "count": 1, "filePath": "src/Internal/Comments.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Exports.json b/review/suppressed/NoUnused.Exports.json new file mode 100644 index 00000000..3f2338e0 --- /dev/null +++ b/review/suppressed/NoUnused.Exports.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Error/Format.elm" }, + { "count": 1, "filePath": "src/Internal/Debug.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Parameters.json b/review/suppressed/NoUnused.Parameters.json new file mode 100644 index 00000000..4b9639bc --- /dev/null +++ b/review/suppressed/NoUnused.Parameters.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Internal/Compiler.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Variables.json b/review/suppressed/NoUnused.Variables.json new file mode 100644 index 00000000..2afae835 --- /dev/null +++ b/review/suppressed/NoUnused.Variables.json @@ -0,0 +1,17 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 9, "filePath": "src/Internal/Compiler.elm" }, + { "count": 5, "filePath": "src/Elm.elm" }, + { "count": 5, "filePath": "src/Internal/Write.elm" }, + { "count": 4, "filePath": "src/Internal/Debug.elm" }, + { "count": 2, "filePath": "src/Elm/Op.elm" }, + { "count": 2, "filePath": "src/Internal/Comments.elm" }, + { "count": 2, "filePath": "tests/Pattern.elm" }, + { "count": 1, "filePath": "src/Internal/Index.elm" }, + { "count": 1, "filePath": "tests/Elm/Expect.elm" }, + { "count": 1, "filePath": "tests/PackageHelpers.elm" } + ] +} diff --git a/review/suppressed/Simplify.json b/review/suppressed/Simplify.json new file mode 100644 index 00000000..5b0bfc56 --- /dev/null +++ b/review/suppressed/Simplify.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 2, "filePath": "src/Internal/Compiler.elm" } + ] +} diff --git a/src/Elm.elm b/src/Elm.elm index 270b47e5..a68fd4a9 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -100,19 +100,16 @@ import Dict import Elm.Annotation import Elm.Parser import Elm.Processing -import Elm.Syntax.Declaration as Declaration exposing (Declaration(..)) +import Elm.Syntax.Declaration as Declaration import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp -import Elm.Syntax.Infix as Infix +import Elm.Syntax.File import Elm.Syntax.Module -import Elm.Syntax.Node as Node +import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Pattern as Pattern -import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation import Internal.Clean as Clean -import Internal.Comments import Internal.Compiler as Compiler -import Internal.Debug import Internal.Dependencies import Internal.Format as Format import Internal.Index as Index @@ -135,6 +132,7 @@ type alias Expression = toString : Expression -> String toString (Compiler.Expression toExp) = let + expresh : Compiler.ExpressionDetails expresh = toExp Index.startIndex in @@ -301,13 +299,12 @@ value details = case details.annotation of Nothing -> let + typename : String typename = Index.protectTypeName details.name index in Ok - { type_ = - Annotation.GenericType - typename + { type_ = Annotation.GenericType typename , inferences = Dict.empty , aliases = Compiler.emptyAliases } @@ -349,6 +346,7 @@ withType ((Compiler.Annotation annDetails) as ann) (Compiler.Expression toExp) = Compiler.Expression <| \index -> let + exp : Compiler.ExpressionDetails exp = toExp index in @@ -367,7 +365,7 @@ withType ((Compiler.Annotation annDetails) as ann) (Compiler.Expression toExp) = , aliases = expressionAnnotation.aliases } - Err err -> + Err _ -> Ok { type_ = annDetails.annotation , inferences = Dict.empty @@ -391,9 +389,11 @@ unwrapper modName typename = Compiler.Expression <| \index -> let + arg : { name : String, typename : String, val : Compiler.Expression, index : Index.Index } arg = Compiler.toVar index "val" + return : { name : String, typename : String, val : Compiler.Expression, index : Index.Index } return = Compiler.toVar arg.index "unwrapped" in @@ -585,7 +585,7 @@ tuple oneExp twoExp = ( oneIndex, one ) = Compiler.toExpressionDetails index oneExp - ( twoIndex, two ) = + ( _, two ) = Compiler.toExpressionDetails oneIndex twoExp in { expression = @@ -627,7 +627,7 @@ triple oneExp twoExp threeExp = ( twoIndex, two ) = Compiler.toExpressionDetails oneIndex twoExp - ( threeIndex, three ) = + ( _, three ) = Compiler.toExpressionDetails twoIndex threeExp in { expression = @@ -731,6 +731,7 @@ list exprs = Compiler.expression <| \index -> let + exprDetails : List Compiler.ExpressionDetails exprDetails = Compiler.thread index exprs in @@ -777,12 +778,14 @@ updateRecord fields recordExpression = |> List.foldl (\( fieldNameUnformatted, fieldExp ) ( currentIndex, fieldAnnotationResult, items ) -> let + fieldName : String fieldName = Format.formatValue fieldNameUnformatted ( newIndex, exp ) = Compiler.toExpressionDetails currentIndex fieldExp + currentFieldAnnotations : Result (List Compiler.InferenceError) (List ( String, Compiler.Inference )) currentFieldAnnotations = case fieldAnnotationResult of Ok fieldAnns -> @@ -824,6 +827,7 @@ updateRecord fields recordExpression = _ -> let + name : String name = "record" ++ Index.indexToString fieldIndex in @@ -893,7 +897,7 @@ updateRecord fields recordExpression = ) } - otherwise -> + _ -> recordExp.annotation otherwise -> @@ -924,6 +928,7 @@ record fields = Compiler.expression <| \index -> let + unified : { index : Index.Index, fields : List ( Node String, Node Exp.Expression ), passed : Set.Set String, errors : List Compiler.InferenceError, fieldAnnotations : List ( String, Compiler.Inference ), imports : List Compiler.Module } unified = fields |> List.foldl @@ -932,6 +937,7 @@ record fields = ( newIndex, exp ) = Compiler.toExpressionDetails found.index fieldExpression + fieldName : String fieldName = Format.formatValue unformattedFieldName in @@ -953,11 +959,11 @@ record fields = Err errs -> errs ++ found.errors - Ok ann -> + Ok _ -> found.errors , fieldAnnotations = case exp.annotation of - Err err -> + Err _ -> found.fieldAnnotations Ok ann -> @@ -998,14 +1004,14 @@ record fields = |> Annotation.Record , inferences = List.foldl - (\( name, ann ) gathered -> + (\( _, ann ) gathered -> Compiler.mergeInferences ann.inferences gathered ) Dict.empty unified.fieldAnnotations , aliases = List.foldl - (\( name, ann ) gathered -> + (\( _, ann ) gathered -> Compiler.mergeAliases ann.aliases gathered ) Compiler.emptyAliases @@ -1065,7 +1071,7 @@ ifThen condition thenBranch elseBranch = ( thenIndex, thenB ) = Compiler.toExpressionDetails condIndex thenBranch - ( finalIndex, elseB ) = + ( _, elseB ) = Compiler.toExpressionDetails thenIndex elseBranch in { expression = @@ -1094,6 +1100,7 @@ get unformattedFieldName recordExpression = Compiler.Expression <| \index -> let + fieldName : String fieldName = Format.formatValue unformattedFieldName @@ -1152,26 +1159,16 @@ verifyFieldsHelper existingFields updatedFields = True ( fieldName, fieldInference ) :: remain -> - if presentAndMatching fieldName fieldInference existingFields then - verifyFieldsHelper existingFields remain - - else - False + presentAndMatching fieldName fieldInference existingFields + && verifyFieldsHelper existingFields remain -presentAndMatching fieldName fieldInference existingFields = - List.foldl - (\(Node.Node _ ( Node.Node _ existingFieldName, Node.Node _ existingFieldType )) gathered -> - if gathered then - gathered - - else if fieldName == existingFieldName then - True - - else - False +presentAndMatching : String -> Compiler.Inference -> List (Node Annotation.RecordField) -> Bool +presentAndMatching fieldName _ existingFields = + List.any + (\(Node.Node _ ( Node.Node _ existingFieldName, _ )) -> + fieldName == existingFieldName ) - False existingFields @@ -1203,7 +1200,7 @@ customType name variants = variants , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -1306,7 +1303,7 @@ alias name innerAnnotation = Compiler.getAnnotationImports innerAnnotation , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -1331,6 +1328,7 @@ apply fnExp argExpressions = ( annotationIndex, fnDetails ) = Compiler.toExpressionDetails index fnExp + args : List Compiler.ExpressionDetails args = Compiler.thread annotationIndex argExpressions in @@ -1397,12 +1395,14 @@ fn ( oneBaseName, maybeAnnotation ) toExpression = Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeAnnotation (Compiler.Expression toExpr) = toExpression one.val + return : Compiler.ExpressionDetails return = toExpr one.index in @@ -1413,7 +1413,7 @@ fn ( oneBaseName, maybeAnnotation ) toExpression = } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1452,9 +1452,11 @@ functionReduced argBaseName toExpression = ( arg1Name, newIndex ) = Index.getName argBaseName index + argType : Elm.Annotation.Annotation argType = Elm.Annotation.var arg1Name + arg1 : Expression arg1 = value { importFrom = [] @@ -1465,6 +1467,7 @@ functionReduced argBaseName toExpression = (Compiler.Expression toExpr) = toExpression arg1 + return : Compiler.ExpressionDetails return = toExpr newIndex in @@ -1476,7 +1479,7 @@ functionReduced argBaseName toExpression = } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1504,20 +1507,21 @@ popLastAndDenodeLast lst = [] -> Nothing - last :: initReverse -> - Just ( List.reverse initReverse, Compiler.denode last ) + (Node _ last) :: initReverse -> + Just ( List.reverse initReverse, last ) betaReduce : Exp.Expression -> Exp.Expression betaReduce e = let + extractLastArg : Exp.Expression -> Maybe String extractLastArg arg = case arg of Exp.FunctionOrValue [] n -> Just n - Exp.ParenthesizedExpression p -> - extractLastArg <| Compiler.denode p + Exp.ParenthesizedExpression (Node _ p) -> + extractLastArg p _ -> Nothing @@ -1527,14 +1531,7 @@ betaReduce e = case popLastAndDenodeLast args of Just ( initLambdaArgs, Pattern.VarPattern lastLambdaArg ) -> case Compiler.denode expression of - Exp.RecordAccess argNode fieldNode -> - let - fieldName = - Compiler.denode fieldNode - - arg = - Compiler.denode argNode - in + Exp.RecordAccess (Node _ arg) (Node.Node _ fieldName) -> case arg of Exp.FunctionOrValue [] argName -> if argName == lastLambdaArg then @@ -1559,8 +1556,8 @@ betaReduce e = if extractLastArg lastApplicationArg == Just lastLambdaArg then if List.isEmpty initLambdaArgs then case initApplicationArgs of - [ s ] -> - betaReduce <| Compiler.denode s + [ Node _ s ] -> + betaReduce s _ -> Exp.Application initApplicationArgs @@ -1600,26 +1597,29 @@ fn2 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) toExpression = Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType - ( newIndex_, return ) = + ( _, return ) = Compiler.toExpressionDetails two.index (toExpression one.val two.val) in { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - ] + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + ] , expression = Compiler.nodify return.expression } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1653,30 +1653,34 @@ fn3 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails three.index (toExpression one.val two.val three.val) in { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - ] + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + ] , expression = Compiler.nodify return.expression } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1716,34 +1720,39 @@ fn4 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType + four : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails four.index (toExpression one.val two.val three.val four.val) in { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - ] + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + ] , expression = Compiler.nodify return.expression } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1789,38 +1798,44 @@ fn5 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType + four : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType + five : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } five = Compiler.toVarMaybeType four.index fiveBaseName maybeFiveType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails five.index (toExpression one.val two.val three.val four.val five.val) in { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - ] + Compiler.nodifyAll <| + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + ] , expression = Compiler.nodify return.expression } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1872,42 +1887,49 @@ fn6 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType + four : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType + five : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } five = Compiler.toVarMaybeType four.index fiveBaseName maybeFiveType + six : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } six = Compiler.toVarMaybeType five.index sixBaseName maybeSixType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails five.index (toExpression one.val two.val three.val four.val five.val six.val) in { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - , Compiler.nodify (Pattern.VarPattern six.name) - ] + Compiler.nodifyAll <| + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + , Pattern.VarPattern six.name + ] , expression = Compiler.nodify return.expression } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1977,9 +1999,9 @@ renderDocumentation : -> Maybe String renderDocumentation resolvedType bodyAnnotation = case resolvedType of - Ok sig -> + Ok _ -> case bodyAnnotation of - Ok inference -> + Ok _ -> Nothing Err err -> @@ -1996,9 +2018,10 @@ sep = "\n----\n" +renderDebugDocumentation : Result String value -> Result (List Compiler.InferenceError) Compiler.Inference -> Maybe String renderDebugDocumentation resolvedType bodyAnnotation = case resolvedType of - Ok sig -> + Ok _ -> case bodyAnnotation of Ok inference -> Just (Internal.Write.writeInference inference) @@ -2036,6 +2059,7 @@ renderError err = declaration : String -> Expression -> Declaration declaration nameStr (Compiler.Expression toBody) = let + name : String name = Format.formatDeclarationName nameStr in @@ -2048,20 +2072,23 @@ declaration nameStr (Compiler.Expression toBody) = , toBody = \index -> let + body : Compiler.ExpressionDetails body = toBody index + resolvedType : Result String Annotation.TypeAnnotation resolvedType = body.annotation |> Result.mapError renderError |> Result.andThen (\sig -> Compiler.resolve index sig.inferences sig.type_) + maybeWarning : Maybe { declaration : String, warning : String } maybeWarning = case resolvedType of - Ok sig -> + Ok _ -> case body.annotation of - Ok inference -> + Ok _ -> Nothing Err [] -> @@ -2091,26 +2118,21 @@ declaration nameStr (Compiler.Expression toBody) = -- (renderDebugDocumentation resolvedType body.annotation) , signature = - case body.annotation of - Ok sig -> - case resolvedType of - Ok (Annotation.GenericType generic) -> - -- Top level values can't be lonely generic types. - Nothing - - Ok finalType -> - Just - (Compiler.nodify - { name = Compiler.nodify name - , typeAnnotation = - Compiler.nodify (Clean.clean finalType) - } - ) + case ( body.annotation, resolvedType ) of + ( Ok _, Ok (Annotation.GenericType _) ) -> + -- Top level values can't be lonely generic types. + Nothing - Err errMsg -> - Nothing + ( Ok _, Ok finalType ) -> + Just + (Compiler.nodify + { name = Compiler.nodify name + , typeAnnotation = + Compiler.nodify (Clean.clean finalType) + } + ) - Err _ -> + _ -> Nothing , declaration = case body.expression of @@ -2151,6 +2173,7 @@ functionAdvanced args fullExpression = Compiler.expression <| \index -> let + expr : Compiler.ExpressionDetails expr = case fullExpression of Compiler.Expression toExpr -> @@ -2160,7 +2183,7 @@ functionAdvanced args fullExpression = Exp.LambdaExpression { args = List.map - (\( name, ann ) -> Compiler.nodify (Pattern.VarPattern name)) + (\( name, _ ) -> Compiler.nodify (Pattern.VarPattern name)) args , expression = Compiler.nodify expr.expression } @@ -2173,7 +2196,7 @@ functionAdvanced args fullExpression = Ok { type_ = List.foldr - (\( name, Compiler.Annotation ann ) fnbody -> + (\( _, Compiler.Annotation ann ) fnbody -> Annotation.FunctionTypeAnnotation (Compiler.nodify ann.annotation) (Compiler.nodify fnbody) @@ -2213,6 +2236,7 @@ function initialArgList toFullExpression = Compiler.expression <| \index -> let + args : { index : Index.Index, args : List Expression, names : List String, types : List Annotation.TypeAnnotation } args = List.foldl (\( nameBase, maybeType ) found -> @@ -2220,6 +2244,7 @@ function initialArgList toFullExpression = ( name, newIndex ) = Index.getName nameBase found.index + argType : Compiler.Annotation argType = Maybe.withDefault (Compiler.Annotation @@ -2235,6 +2260,7 @@ function initialArgList toFullExpression = ) maybeType + arg : Expression arg = value { importFrom = [] @@ -2255,9 +2281,11 @@ function initialArgList toFullExpression = } initialArgList + fullExpression : Expression fullExpression = toFullExpression (List.reverse args.args) + expr : Compiler.ExpressionDetails expr = case fullExpression of Compiler.Expression toExpr -> @@ -2364,6 +2392,7 @@ This will give you more flexibility in the future and save you having to wire up portIncoming : String -> List Elm.Annotation.Annotation -> Declaration portIncoming nameStr args = let + name : String name = Format.formatDeclarationName nameStr in @@ -2374,7 +2403,7 @@ portIncoming nameStr args = List.concatMap Compiler.getAnnotationImports args , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2388,7 +2417,7 @@ portIncoming nameStr args = (Compiler.nodify (Annotation.GenericType "msg")) (Compiler.nodify sub) - start :: remain -> + _ :: _ -> Annotation.FunctionTypeAnnotation (groupAnn (Compiler.nodify @@ -2407,6 +2436,7 @@ portIncoming nameStr args = } +groupAnn : Node Annotation.TypeAnnotation -> Node Annotation.TypeAnnotation groupAnn ann = Annotation.Tupled [ ann ] @@ -2434,6 +2464,7 @@ will generate portOutgoing : String -> Elm.Annotation.Annotation -> Declaration portOutgoing nameStr arg = let + name : String name = Format.formatDeclarationName nameStr in @@ -2444,7 +2475,7 @@ portOutgoing nameStr arg = Compiler.getAnnotationImports arg , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2482,28 +2513,26 @@ unsafe source = parse : String -> Result String { declarations : List Declaration } parse source = case Elm.Parser.parse source of - Err deadends -> + Err _ -> Err "Uh oh" Ok raw -> let + parsedFile : Elm.Syntax.File.File parsedFile = Elm.Processing.process elmProcessContext raw + exposedList : Expose.Exposing exposedList = Compiler.denode parsedFile.moduleDefinition |> Elm.Syntax.Module.exposingList + declarations : List ( Int, Compiler.Declaration ) declarations = List.map - (\dec -> - let - declar = - Compiler.denode dec - in - ( Node.range dec - |> (.start >> .row) + (\(Node range declar) -> + ( range.start.row , Compiler.Declaration { name = Maybe.withDefault "parsed" (decName declar) , exposed = determineExposure declar exposedList @@ -2511,7 +2540,7 @@ parse source = [] , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2522,13 +2551,12 @@ parse source = ) parsedFile.declarations + comments : List ( Int, Compiler.Declaration ) comments = List.map - (\nodedComment -> - ( Node.range nodedComment - |> (.start >> .row) - , Compiler.Comment - (Compiler.denode nodedComment) + (\(Node range nodedComment) -> + ( range.start.row + , Compiler.Comment nodedComment ) ) parsedFile.comments @@ -2542,6 +2570,7 @@ parse source = } +decName : Declaration.Declaration -> Maybe String decName decBody = case decBody of Declaration.FunctionDeclaration func -> @@ -2560,7 +2589,7 @@ decName decBody = Compiler.denode myPort.name |> Just - Declaration.InfixDeclaration inf -> + Declaration.InfixDeclaration _ -> Nothing Declaration.Destructuring _ _ -> @@ -2584,50 +2613,61 @@ determineExposure dec exposedDec = Expose.Explicit nodes -> case dec of Declaration.FunctionDeclaration myFn -> - case Compiler.denode myFn.declaration of - implementation -> - case Compiler.denode implementation.name of - name -> - if List.any (valueIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = False } + let + implementation : Exp.FunctionImplementation + implementation = + Compiler.denode myFn.declaration - else - Compiler.NotExposed + name : String + name = + Compiler.denode implementation.name + in + if List.any (valueIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = False } + + else + Compiler.NotExposed Declaration.AliasDeclaration typeAlias -> - case Compiler.denode typeAlias.name of - name -> - if List.any (typeIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = False } + let + name : String + name = + Compiler.denode typeAlias.name + in + if List.any (typeIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = False } - else - Compiler.NotExposed + else + Compiler.NotExposed Declaration.CustomTypeDeclaration type_ -> - case Compiler.denode type_.name of - name -> - if List.any (typeIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = False } + let + name : String + name = + Compiler.denode type_.name + in + if List.any (typeIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = False } - else if List.any (typeConstructorIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = True } + else if List.any (typeConstructorIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = True } - else - Compiler.NotExposed + else + Compiler.NotExposed - Declaration.PortDeclaration sig -> + Declaration.PortDeclaration _ -> Compiler.NotExposed - Declaration.InfixDeclaration infixDec -> + Declaration.InfixDeclaration _ -> Compiler.NotExposed - Declaration.Destructuring pattern exp -> + Declaration.Destructuring _ _ -> Compiler.NotExposed valueIsExposed : String -> Node.Node Expose.TopLevelExpose -> Bool -valueIsExposed name node = - case Compiler.denode node of +valueIsExposed name (Node _ node) = + case node of Expose.InfixExpose _ -> False @@ -2642,12 +2682,12 @@ valueIsExposed name node = typeIsExposed : String -> Node.Node Expose.TopLevelExpose -> Bool -typeIsExposed name node = - case Compiler.denode node of +typeIsExposed name (Node _ node) = + case node of Expose.InfixExpose _ -> False - Expose.FunctionExpose fnName -> + Expose.FunctionExpose _ -> False Expose.TypeOrAliasExpose typeName -> @@ -2658,12 +2698,12 @@ typeIsExposed name node = typeConstructorIsExposed : String -> Node.Node Expose.TopLevelExpose -> Bool -typeConstructorIsExposed name node = - case Compiler.denode node of +typeConstructorIsExposed name (Node _ node) = + case node of Expose.InfixExpose _ -> False - Expose.FunctionExpose fnName -> + Expose.FunctionExpose _ -> False Expose.TypeOrAliasExpose typeName -> diff --git a/src/Elm/Annotation.elm b/src/Elm/Annotation.elm index 121f9c5c..0d300ff6 100644 --- a/src/Elm/Annotation.elm +++ b/src/Elm/Annotation.elm @@ -223,8 +223,7 @@ alias mod name vars target = List.concatMap Compiler.getAnnotationImports vars _ -> - [ mod ] - ++ List.concatMap Compiler.getAnnotationImports vars + mod :: List.concatMap Compiler.getAnnotationImports vars , aliases = List.foldl (\ann aliases -> diff --git a/src/Elm/Case.elm b/src/Elm/Case.elm index fa8ca42c..43ef2ca4 100644 --- a/src/Elm/Case.elm +++ b/src/Elm/Case.elm @@ -64,7 +64,7 @@ Generates -} -import Dict exposing (Dict) +import Dict import Elm exposing (Expression) import Elm.Annotation as Type import Elm.Syntax.Expression as Exp @@ -73,7 +73,6 @@ import Elm.Syntax.Pattern as Pattern import Elm.Syntax.TypeAnnotation as Annotation import Internal.Branch as Branch exposing (Branch, Pattern(..)) import Internal.Compiler as Compiler -import Internal.Debug as Debug import Internal.Format as Format import Internal.Index as Index @@ -98,6 +97,12 @@ captureCase mainExpression mainExpressionTypeModule index branches = ( branchIndex, mainExpressionDetails ) = Compiler.toExpressionDetails index mainExpression + caseExp : + { index : Index.Index + , cases : List ( Node.Node Pattern.Pattern, Node.Node Exp.Expression ) + , imports : List Compiler.Module + , annotation : Maybe (Result (List Compiler.InferenceError) Compiler.Inference) + } caseExp = List.foldl (captureCaseHelper mainExpressionTypeModule) @@ -146,6 +151,7 @@ captureCaseHelper mainCaseExpressionModule (Branch toBranch) accum = ( branchIndex, originalPattern, caseExpression ) = toBranch (Index.dive accum.index) + pattern : Pattern.Pattern pattern = case mainCaseExpressionModule of [] -> @@ -163,7 +169,7 @@ captureCaseHelper mainCaseExpressionModule (Branch toBranch) accum = _ -> originalPattern - ( newIndex, exp ) = + ( _, exp ) = Compiler.toExpressionDetails branchIndex caseExpression in { index = accum.index @@ -234,20 +240,22 @@ maybe mainExpression branches = ) , Branch (\branchIndex -> - case branches.just of - ( justVarName, toReturn ) -> - let - just = - Compiler.toVarMaybeType branchIndex justVarName Nothing - in - ( just.index - , Pattern.NamedPattern - { moduleName = [] - , name = "Just" - } - [ Compiler.nodify (Pattern.VarPattern just.name) ] - , toReturn just.val - ) + let + ( justVarName, toReturn ) = + branches.just + + just : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } + just = + Compiler.toVarMaybeType branchIndex justVarName Nothing + in + ( just.index + , Pattern.NamedPattern + { moduleName = [] + , name = "Just" + } + [ Compiler.nodify (Pattern.VarPattern just.name) ] + , toReturn just.val + ) ) ] in @@ -301,17 +309,20 @@ tuple mainExpression oneName twoName branches = [ Branch (\branchIndex -> let + first : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } first = Compiler.toVarMaybeType branchIndex oneName Nothing + second : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } second = Compiler.toVarMaybeType first.index twoName Nothing in ( second.index - , Pattern.TuplePattern - [ Compiler.nodify (Pattern.VarPattern first.name) - , Compiler.nodify (Pattern.VarPattern second.name) - ] + , Pattern.TuplePattern <| + Compiler.nodifyAll + [ Pattern.VarPattern first.name + , Pattern.VarPattern second.name + ] , branches first.val second.val ) ) @@ -368,21 +379,25 @@ triple mainExpression one two three branches = [ Branch (\branchIndex -> let + first : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } first = Compiler.toVarMaybeType branchIndex one Nothing + second : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } second = Compiler.toVarMaybeType first.index two Nothing + third : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } third = Compiler.toVarMaybeType second.index three Nothing in ( third.index - , Pattern.TuplePattern - [ Compiler.nodify (Pattern.VarPattern first.name) - , Compiler.nodify (Pattern.VarPattern second.name) - , Compiler.nodify (Pattern.VarPattern third.name) - ] + , Pattern.TuplePattern <| + Compiler.nodifyAll + [ Pattern.VarPattern first.name + , Pattern.VarPattern second.name + , Pattern.VarPattern third.name + ] , branches first.val second.val third.val ) ) @@ -444,31 +459,35 @@ result mainExpression branches = (Index.dive index) [ Branch (\branchIndex -> - case branches.ok of - ( okNameStr, toOk ) -> - let - ok = - Compiler.toVarMaybeType branchIndex okNameStr Nothing - in - ( ok.index - , Pattern.NamedPattern { moduleName = [], name = "Ok" } - [ Compiler.nodify (Pattern.VarPattern ok.name) ] - , toOk ok.val - ) + let + ( okNameStr, toOk ) = + branches.ok + + ok : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } + ok = + Compiler.toVarMaybeType branchIndex okNameStr Nothing + in + ( ok.index + , Pattern.NamedPattern { moduleName = [], name = "Ok" } + [ Compiler.nodify (Pattern.VarPattern ok.name) ] + , toOk ok.val + ) ) , Branch (\branchIndex -> - case branches.err of - ( errNameStr, toErr ) -> - let - err = - Compiler.toVarMaybeType branchIndex errNameStr Nothing - in - ( err.index - , Pattern.NamedPattern { moduleName = [], name = "Err" } - [ Compiler.nodify (Pattern.VarPattern err.name) ] - , toErr err.val - ) + let + ( errNameStr, toErr ) = + branches.err + + err : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } + err = + Compiler.toVarMaybeType branchIndex errNameStr Nothing + in + ( err.index + , Pattern.NamedPattern { moduleName = [], name = "Err" } + [ Compiler.nodify (Pattern.VarPattern err.name) ] + , toErr err.val + ) ) ] in @@ -500,6 +519,7 @@ string mainExpression branches = Compiler.Expression <| \index -> let + allBranches : List (Pattern Expression) allBranches = List.map (\( caseString, caseExpression ) -> @@ -586,9 +606,11 @@ list mainExpression branches = , Branch (\branchIndex -> let + top : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } top = Compiler.toVarMaybeType branchIndex "top" Nothing + remaining : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } remaining = Compiler.toVarMaybeType branchIndex "remaining" Nothing in @@ -629,6 +651,7 @@ custom mainExpression annotation branches = Compiler.Expression <| \index -> let + myMain : Expression myMain = mainExpression |> Elm.withType annotation @@ -678,6 +701,7 @@ otherwise toExp = Branch (\index -> let + other : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } other = Compiler.toVarMaybeType index "otherwise" Nothing in @@ -694,16 +718,15 @@ branch1 name ( argName, argType ) toExp = Branch (\index -> let - var = + one : { name : String, exp : Expression, index : Index.Index } + one = Compiler.toVarWithType index argName argType in - ( var.index - , Pattern.NamedPattern - { moduleName = [] - , name = Format.formatType name - } - [ Compiler.nodify (Pattern.VarPattern var.name) ] - , toExp var.exp + ( one.index + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name ] + , toExp one.exp ) ) @@ -714,17 +737,20 @@ branch2 name ( oneName, oneType ) ( twoName, twoType ) toExp = Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType in ( two.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + ] , toExp one.exp two.exp ) ) @@ -742,21 +768,25 @@ branch3 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType in ( three.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + ] , toExp one.exp two.exp three.exp ) ) @@ -775,25 +805,30 @@ branch4 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType + four : { name : String, exp : Expression, index : Index.Index } four = Compiler.toVarWithType three.index fourName fourType in ( four.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + ] , toExp one.exp two.exp three.exp four.exp ) ) @@ -820,29 +855,35 @@ branch5 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType + four : { name : String, exp : Expression, index : Index.Index } four = Compiler.toVarWithType three.index fourName fourType + five : { name : String, exp : Expression, index : Index.Index } five = Compiler.toVarWithType four.index fiveName fiveType in ( five.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + ] , toExp one.exp two.exp three.exp four.exp five.exp ) ) @@ -871,33 +912,40 @@ branch6 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType + four : { name : String, exp : Expression, index : Index.Index } four = Compiler.toVarWithType three.index fourName fourType + five : { name : String, exp : Expression, index : Index.Index } five = Compiler.toVarWithType four.index fiveName fiveType + six : { name : String, exp : Expression, index : Index.Index } six = Compiler.toVarWithType four.index sixName sixType in ( six.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - , Compiler.nodify (Pattern.VarPattern six.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + , Pattern.VarPattern six.name + ] , toExp one.exp two.exp three.exp four.exp five.exp six.exp ) ) @@ -914,6 +962,7 @@ branchWith name arity toExp = |> List.map (\i -> let + var : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } var = Compiler.toVarMaybeType index ("arg" ++ String.fromInt i) Nothing in @@ -940,6 +989,7 @@ branchList arity toExp = List.foldl (\i ( listPattern, currentArgs ) -> let + var : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } var = Compiler.toVarMaybeType index ("arg" ++ String.fromInt i) Nothing in diff --git a/src/Elm/Case/Branch.elm b/src/Elm/Case/Branch.elm index bbe2178c..9e4c3d08 100644 --- a/src/Elm/Case/Branch.elm +++ b/src/Elm/Case/Branch.elm @@ -133,9 +133,9 @@ These helpers let you define a Custom Type pattern with a builder. -} import Elm exposing (Expression) -import Elm.Annotation as Type -import Elm.Syntax.Node as Node exposing (Node(..)) +import Elm.Syntax.Node exposing (Node) import Elm.Syntax.Pattern as Pattern +import Elm.Syntax.TypeAnnotation as Annotation import Internal.Branch as Branch exposing (Pattern(..)) import Internal.Compiler as Compiler import Internal.Format as Format @@ -398,6 +398,7 @@ withField newField (Record toRecord) = ( newIndex, existingFields, recordBuilder ) = toRecord index + new : { name : String, typename : String, val : Expression, index : Index.Index } new = Compiler.toVarExactName newIndex newField in @@ -463,6 +464,7 @@ withParam (Branch toBranch) (CustomType toCustomType) = ( newIndex, pattern, val ) = toBranch index + custom : { index : Index.Index, base : String, patterns : List Pattern.Pattern, value : a -> b } custom = toCustomType newIndex in @@ -480,6 +482,7 @@ toPattern (CustomType toCustomType) = Branch.Branch (\index -> let + custom : { index : Index.Index, base : String, patterns : List Pattern.Pattern, value : a } custom = toCustomType index in @@ -688,6 +691,7 @@ aliasAs name combine (Branch.Branch branch) = ( newIndex, pattern, destructured ) = branch index + aliased : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } aliased = Compiler.toVarMaybeType newIndex name Nothing in @@ -739,6 +743,7 @@ var name = Branch.Branch (\index -> let + variable : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } variable = Compiler.toVarMaybeType index name Nothing in @@ -786,7 +791,7 @@ list { patterns, gather, startWith, finally } = let ( finalIndex, itemPatterns, finalGathered ) = List.foldl - (\((Branch toBranch) as branch) ( index, patternList, gathered ) -> + (\(Branch toBranch) ( index, patternList, gathered ) -> let ( newIndex, pattern, value ) = toBranch index @@ -858,12 +863,12 @@ listWithRemaining { patterns, gather, startWith, remaining, finally } = (Branch toRemaining) = remaining - ( restIndex, restPattern, remainingValue ) = + ( _, restPattern, remainingValue ) = toRemaining startIndex ( finalIndex, itemPatterns, finalGathered ) = List.foldl - (\((Branch toBranch) as branch) ( index, patternList, gathered ) -> + (\(Branch toBranch) ( index, patternList, gathered ) -> let ( newIndex, pattern, value ) = toBranch index diff --git a/src/Elm/Declare.elm b/src/Elm/Declare.elm index 22355a92..5d523ac5 100644 --- a/src/Elm/Declare.elm +++ b/src/Elm/Declare.elm @@ -67,6 +67,7 @@ In that case you can do something like this using `callFrom`: import Elm exposing (Declaration, Expression) import Elm.Annotation import Elm.Syntax.Expression as Exp +import Elm.Syntax.ModuleName as ModuleName import Internal.Compiler as Compiler import Internal.Format as Format @@ -84,45 +85,13 @@ fn : } fn name one toExp = let + funcExp : Expression funcExp = Elm.fn one toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne = - Elm.apply - (valueFrom importFrom) - [ argOne ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne -> + call [ argOne ] {-| -} @@ -139,45 +108,13 @@ fn2 : } fn2 name one two toExp = let + funcExp : Expression funcExp = Elm.fn2 one two toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo -> + call [ argOne, argTwo ] {-| -} @@ -195,45 +132,13 @@ fn3 : } fn3 name one two three toExp = let + funcExp : Expression funcExp = Elm.fn3 one two three toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo argThree = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo argThree -> + call [ argOne, argTwo, argThree ] {-| -} @@ -252,45 +157,13 @@ fn4 : } fn4 name one two three four toExp = let + funcExp : Expression funcExp = Elm.fn4 one two three four toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo argThree argFour = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree, argFour ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo argThree argFour -> + call [ argOne, argTwo, argThree, argFour ] {-| -} @@ -310,45 +183,13 @@ fn5 : } fn5 name one two three four five toExp = let + funcExp : Expression funcExp = Elm.fn5 one two three four five toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo argThree argFour argFive = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree, argFour, argFive ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo argThree argFour argFive -> + call [ argOne, argTwo, argThree, argFour, argFive ] {-| -} @@ -369,15 +210,55 @@ fn6 : } fn6 name one two three four five six toExp = let + funcExp : Expression funcExp = Elm.fn6 one two three four five six toExp + in + innerFunction name funcExp <| + \call argOne argTwo argThree argFour argFive argSix -> + call [ argOne, argTwo, argThree, argFour, argFive, argSix ] + +{-| -} +function : + String + -> List ( String, Maybe Elm.Annotation.Annotation ) + -> (List Expression -> Expression) + -> + { declaration : Declaration + , call : List Expression -> Expression + , callFrom : List String -> List Expression -> Expression + , value : List String -> Expression + } +function name params toExp = + let + funcExp : Expression + funcExp = + Elm.function params toExp + in + innerFunction name funcExp identity + + +innerFunction : + String + -> Expression + -> ((List Expression -> Expression) -> a) + -> + { declaration : Declaration + , call : a + , callFrom : ModuleName.ModuleName -> a + , value : ModuleName.ModuleName -> Expression + } +innerFunction name funcExp collectArgs = + let + valueFrom : ModuleName.ModuleName -> Expression valueFrom importFrom = Compiler.Expression <| \index -> case funcExp of Compiler.Expression toFnExp -> let + fnExp : Compiler.ExpressionDetails fnExp = toFnExp index in @@ -387,26 +268,21 @@ fn6 name one two three four five six toExp = -- to refer to something that already exists. Exp.FunctionOrValue importFrom (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports + , annotation = fnExp.annotation + , imports = fnExp.imports } - call importFrom argOne argTwo argThree argFour argFive argSix = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree, argFour, argFive, argSix ] + call : ModuleName.ModuleName -> a + call importFrom = + collectArgs + (Elm.apply + (valueFrom importFrom) + ) in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom + { declaration = Elm.declaration name funcExp + , call = call [] + , callFrom = call + , value = valueFrom } @@ -434,55 +310,3 @@ value name expression = , value = declaration_.call [] , valueFrom = \from -> declaration_.callFrom from [] } - - -{-| -} -function : - String - -> List ( String, Maybe Elm.Annotation.Annotation ) - -> (List Expression -> Expression) - -> - { declaration : Declaration - , call : List Expression -> Expression - , callFrom : List String -> List Expression -> Expression - , value : List String -> Expression - } -function name params toExp = - let - funcExp = - Elm.function params toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom args = - Elm.apply (valueFrom importFrom) args - in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } diff --git a/src/Elm/Let.elm b/src/Elm/Let.elm index 5f736fe4..817d8b26 100644 --- a/src/Elm/Let.elm +++ b/src/Elm/Let.elm @@ -164,9 +164,11 @@ with (Let toScopeA) (Let toScopeAB) = Let (\index -> let + resultA : { letDecls : List (Node.Node Exp.LetDeclaration), index : Index.Index, return : a, imports : List Module } resultA = toScopeA index + resultB : { letDecls : List (Node.Node Exp.LetDeclaration), index : Index.Index, return : a -> b, imports : List Module } resultB = toScopeAB resultA.index in @@ -219,7 +221,7 @@ value desiredName valueExpr sourceLet = , index = finalIndex , return = Compiler.Expression - (\i -> + (\_ -> { details | expression = Exp.FunctionOrValue [] @@ -251,6 +253,7 @@ fn desiredName ( desiredArg, argAnnotation ) toInnerFn sourceLet = ( argName, thirdIndex ) = Index.getName desiredArg secondIndex + arg : Expression arg = Elm.value { importFrom = [] @@ -285,7 +288,7 @@ fn desiredName ( desiredArg, argAnnotation ) toInnerFn sourceLet = \callerArg -> Elm.apply (Compiler.Expression - (\i -> + (\_ -> { innerFnDetails | expression = Exp.FunctionOrValue [] @@ -323,6 +326,7 @@ fn2 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) toInnerFn ( twoName, fourIndex ) = Index.getName twoDesiredArg thirdIndex + one : Expression one = Elm.value { importFrom = [] @@ -330,6 +334,7 @@ fn2 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) toInnerFn , name = oneName } + two : Expression two = Elm.value { importFrom = [] @@ -366,7 +371,7 @@ fn2 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) toInnerFn \oneIncoming twoIncoming -> Elm.apply (Compiler.Expression - (\i -> + (\_ -> { innerFnDetails | expression = Exp.FunctionOrValue [] @@ -409,6 +414,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes ( threeName, fifthIndex ) = Index.getName threeDesiredArg fourIndex + one : Expression one = Elm.value { importFrom = [] @@ -416,6 +422,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes , name = oneName } + two : Expression two = Elm.value { importFrom = [] @@ -423,6 +430,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes , name = twoName } + three : Expression three = Elm.value { importFrom = [] @@ -461,7 +469,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes \oneIncoming twoIncoming threeIncoming -> Elm.apply (Compiler.Expression - (\i -> + (\_ -> { innerFnDetails | expression = Exp.FunctionOrValue [] @@ -523,7 +531,7 @@ tuple desiredNameOne desiredNameTwo valueExpr sourceLet = Ok inference -> case inference.type_ of - Annotation.Tupled [ Node.Node _ oneType, Node.Node _ twoType ] -> + Annotation.Tupled [ Node.Node _ oneType, _ ] -> Ok { type_ = oneType , inferences = Dict.empty @@ -547,7 +555,7 @@ tuple desiredNameOne desiredNameTwo valueExpr sourceLet = Ok inference -> case inference.type_ of - Annotation.Tupled [ Node.Node _ oneType, Node.Node _ twoType ] -> + Annotation.Tupled [ _, Node.Node _ twoType ] -> Ok { type_ = twoType , inferences = Dict.empty @@ -584,7 +592,7 @@ record fields recordExp sourceLet = ( finalIndex, unpackedfields ) = List.foldl - (\fieldName ( i, gathered ) -> + (\fieldName ( _, gathered ) -> let ( gotIndex, got ) = Elm.get fieldName recordExp @@ -633,10 +641,11 @@ toExpression (Let toScope) = Compiler.Expression <| \index -> let + scope : { letDecls : List (Node.Node Exp.LetDeclaration), index : Index.Index, return : Expression, imports : List Module } scope = toScope index - ( returnIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails scope.index scope.return in { expression = diff --git a/src/Elm/Op.elm b/src/Elm/Op.elm index 72f61e81..f16347b4 100644 --- a/src/Elm/Op.elm +++ b/src/Elm/Op.elm @@ -57,25 +57,13 @@ Would generate import Dict import Elm exposing (Expression) -import Elm.Annotation -import Elm.Parser -import Elm.Processing -import Elm.Syntax.Declaration as Declaration exposing (Declaration(..)) -import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp import Elm.Syntax.Infix as Infix -import Elm.Syntax.Module -import Elm.Syntax.Node as Node -import Elm.Syntax.Pattern as Pattern -import Elm.Syntax.Range as Range +import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.TypeAnnotation as Annotation -import Internal.Comments import Internal.Compiler as Compiler -import Internal.Debug import Internal.Index as Index import Internal.Types -import Internal.Write -import Set @@ -492,11 +480,8 @@ applyPipe (BinOp symbol dir _) infixAnnotation l r = ( leftIndex, left ) = Compiler.toExpressionDetails index l - ( rightIndex, right ) = + ( _, right ) = Compiler.toExpressionDetails leftIndex r - - annotationIndex = - Index.next rightIndex in { expression = Exp.OperatorApplication symbol @@ -528,6 +513,7 @@ parens (Compiler.Expression toExp) = Compiler.Expression (\index -> let + exp : Compiler.ExpressionDetails exp = toExp index in @@ -546,11 +532,8 @@ applyInfix extraImports (BinOp symbol dir _) infixAnnotation l r = ( leftIndex, left ) = Compiler.toExpressionDetails index l - ( rightIndex, right ) = + ( _, right ) = Compiler.toExpressionDetails leftIndex r - - annotationIndex = - Index.next rightIndex in { expression = Exp.OperatorApplication symbol @@ -583,9 +566,11 @@ applyNumber symbol dir l r = ( rightIndex, right ) = Compiler.toExpressionDetails leftIndex r + annotationIndex : Index.Index annotationIndex = Index.next rightIndex + numberTypeName : String numberTypeName = Index.protectTypeName "number" @@ -685,8 +670,8 @@ autopipe committed topFn expressions = [] -> Exp.Application [] - innerFn :: remain -> - autopipe True (Compiler.denode innerFn) (List.map Compiler.denode remain) + (Node _ innerFn) :: remain -> + autopipe True innerFn (Compiler.denodeAll remain) ) ) (Compiler.nodify diff --git a/src/Elm/ToString.elm b/src/Elm/ToString.elm index 011a7be9..565de3bf 100644 --- a/src/Elm/ToString.elm +++ b/src/Elm/ToString.elm @@ -22,7 +22,6 @@ import Elm exposing (Declaration, Expression) import Elm.Annotation exposing (Annotation) import Elm.Syntax.Declaration as Declaration import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Writer import Internal.Clean as Clean import Internal.Compiler as Compiler import Internal.Index as Index @@ -57,6 +56,7 @@ expressionWith : } expressionWith options (Compiler.Expression toExp) = let + expresh : Compiler.ExpressionDetails expresh = toExp Index.startIndex in @@ -77,17 +77,10 @@ expressionWith options (Compiler.Expression toExp) = errMsg Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - Compiler.inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ Compiler.inferenceErrorToString err - ) - "Err: " - inferenceError + "Err: " + ++ String.join + "\n\n" + (List.map Compiler.inferenceErrorToString inferenceError) } @@ -118,6 +111,11 @@ declarationWith options decl = case decl of Compiler.Declaration { imports, docs, toBody } -> let + rendered : + { declaration : Declaration.Declaration + , additionalImports : List Compiler.Module + , warning : Maybe Compiler.Warning + } rendered = toBody Index.startIndex in diff --git a/src/Error/Format.elm b/src/Error/Format.elm index 7bd80ce9..50019f8d 100644 --- a/src/Error/Format.elm +++ b/src/Error/Format.elm @@ -60,6 +60,7 @@ grey str = color : Int -> Int -> String -> String color openCode closeCode content = let + delim : Int -> String delim code = --"\\u001B[" ++ String.fromInt code ++ "m" "\u{001B}[" ++ String.fromInt code ++ "m" diff --git a/src/Internal/Clean.elm b/src/Internal/Clean.elm index 0d678654..6077cdc2 100644 --- a/src/Internal/Clean.elm +++ b/src/Internal/Clean.elm @@ -20,6 +20,7 @@ import Set exposing (Set) clean : Type.TypeAnnotation -> Type.TypeAnnotation clean ann = let + renames : Dict String String renames = prepareRename ann Set.empty |> verify @@ -33,6 +34,7 @@ verify set = Set.foldl (\name gathered -> let + newName : String newName = findClean 0 (sanitized name) set in @@ -45,6 +47,7 @@ verify set = findClean : Int -> String -> Set String -> String findClean i name set = let + newName : String newName = if i == 0 then name @@ -65,7 +68,7 @@ sanitized str = [] -> str - top :: remain -> + top :: _ -> top @@ -75,7 +78,7 @@ prepareRename ann dict = Type.GenericType generic -> dict |> Set.insert generic - Type.Typed name nodedVars -> + Type.Typed _ nodedVars -> List.foldl (\(Node.Node _ tipe) d -> prepareRename tipe d) dict nodedVars Type.Unit -> @@ -87,7 +90,7 @@ prepareRename ann dict = Type.Record record -> List.foldl (\(Node.Node _ ( _, Node.Node _ field )) d -> prepareRename field d) dict record - Type.GenericRecord name (Node.Node range record) -> + Type.GenericRecord _ (Node.Node _ record) -> List.foldl (\(Node.Node _ ( _, Node.Node _ field )) d -> prepareRename field d) dict record Type.FunctionTypeAnnotation (Node.Node _ one) (Node.Node _ two) -> diff --git a/src/Internal/Comments.elm b/src/Internal/Comments.elm index bc232cce..d62b793d 100644 --- a/src/Internal/Comments.elm +++ b/src/Internal/Comments.elm @@ -1,7 +1,7 @@ module Internal.Comments exposing ( Comment, CommentPart(..), DocComment, FileComment , emptyComment, addPart - , prettyDocComment, prettyFileComment + , prettyFileComment ) {-| A component DSL that helps with building comments. @@ -22,7 +22,7 @@ can be extracted to order the exposing clause by. # Pretty printing of comments -@docs prettyDocComment, prettyFileComment +@docs prettyFileComment -} @@ -106,6 +106,7 @@ layoutTags width parts = case part of DocTags tags -> let + splits : List (List String) splits = fitAndSplit width tags in @@ -198,15 +199,18 @@ prettyCommentPart part = prettyTags tags +prettyMarkdown : String -> Doc t prettyMarkdown val = Pretty.string val +prettyCode : String -> Doc t prettyCode val = Pretty.string val |> Pretty.indent 4 +prettyTags : List String -> Doc t prettyTags tags = [ Pretty.string "@docs" , List.map Pretty.string tags @@ -216,7 +220,7 @@ prettyTags tags = partToStringAndTags : Int -> CommentPart -> ( String, List String ) -partToStringAndTags width part = +partToStringAndTags _ part = case part of Markdown val -> ( val, [] ) diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index fccb4aa0..c3449645 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -1,4 +1,4 @@ -module Internal.Compiler exposing (..) +module Internal.Compiler exposing (AliasCache, Annotation(..), AnnotationDetails, Declaration(..), DeclarationDetails, Expose(..), Expression(..), ExpressionDetails, Inference, InferenceError(..), Module, RenderedDeclaration(..), Restrictions(..), VariableCache, Visited, Warning, addAlias, addInference, applyType, denode, denodeAll, denodeMaybe, documentation, emptyAliases, expose, exposeWith, expression, facts, findAlias, fullModName, getAliases, getAnnotation, getAnnotationImports, getGenerics, getImports, getInnerAnnotation, getInnerInference, getTypeModule, importInferences, inference, inferenceErrorToString, makeImport, mergeAliases, mergeInferences, noImports, nodify, nodifyAll, parens, resolve, resolveField, thread, toExpressionDetails, toVar, toVarExactName, toVarMaybeType, toVarWithType, unify, unifyOn) import Dict exposing (Dict) import Elm.Syntax.Declaration as Declaration @@ -6,12 +6,12 @@ import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp import Elm.Syntax.ModuleName as ModuleName import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Range as Range exposing (emptyRange) +import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation import Elm.Writer -import Error.Format import Internal.Format as Format import Internal.Index as Index exposing (Index) +import Result.Extra import Set exposing (Set) @@ -30,7 +30,7 @@ type alias AnnotationDetails = getTypeModule : Annotation -> List String getTypeModule (Annotation annotation) = case annotation.annotation of - Annotation.Typed (Node _ ( mod, typeName )) _ -> + Annotation.Typed (Node _ ( mod, _ )) _ -> mod _ -> @@ -183,7 +183,7 @@ parens expr = Exp.UnitExpr -> expr - Exp.Integer i -> + Exp.Integer _ -> expr Exp.Literal _ -> @@ -230,6 +230,7 @@ parens expr = facts : Expression -> Result String (List ( String, Annotation.TypeAnnotation )) facts (Expression exp) = let + expresh : ExpressionDetails expresh = exp Index.startIndex in @@ -240,17 +241,9 @@ facts (Expression exp) = |> Ok Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ inferenceErrorToString err - ) - "" - inferenceError + inferenceError + |> List.map inferenceErrorToString + |> String.join "\n\n" |> Err @@ -260,25 +253,21 @@ unique [ 0, 1, 1, 0, 1 ] -} unique : List a -> List a unique list = - uniqueHelp identity [] list [] + uniqueHelp list [] -uniqueHelp : (a -> b) -> List b -> List a -> List a -> List a -uniqueHelp f existing remaining accumulator = +uniqueHelp : List a -> List a -> List a +uniqueHelp remaining accumulator = case remaining of [] -> List.reverse accumulator first :: rest -> - let - computedFirst = - f first - in - if List.member computedFirst existing then - uniqueHelp f existing rest accumulator + if List.member first accumulator then + uniqueHelp rest accumulator else - uniqueHelp f (computedFirst :: existing) rest (first :: accumulator) + uniqueHelp rest (first :: accumulator) toVar : @@ -295,6 +284,7 @@ toVar index desiredName = ( name, newIndex ) = Index.getName desiredName index + typename : String typename = Index.protectTypeName desiredName index in @@ -303,7 +293,7 @@ toVar index desiredName = , index = newIndex , val = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -331,6 +321,7 @@ toVarExactName : } toVarExactName index name = let + typename : String typename = Index.protectTypeName name index in @@ -339,7 +330,7 @@ toVarExactName index name = , index = Index.next index , val = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -387,7 +378,7 @@ toVarMaybeType index desiredName maybeAnnotation = , index = newIndex , val = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -422,7 +413,7 @@ toVarWithType index desiredName (Annotation ann) = , index = newIndex , exp = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -449,7 +440,7 @@ mergeInferences one two = case oneVal of Annotation.GenericRecord recordName (Node.Node oneRange recordDefinition) -> case twoVal of - Annotation.GenericRecord twoRecordName (Node.Node twoRange twoRecordDefinition) -> + Annotation.GenericRecord _ (Node.Node _ twoRecordDefinition) -> Dict.insert key (Annotation.GenericRecord recordName (Node.Node oneRange (recordDefinition ++ twoRecordDefinition)) @@ -531,7 +522,7 @@ inferenceErrorToString inf = |> Elm.Writer.write ) - RecordUpdateIncorrectFields details -> + RecordUpdateIncorrectFields _ -> "Mismatched record update" EmptyCaseStatement -> @@ -623,7 +614,7 @@ getGenericsHelper ann = Annotation.GenericType str -> [ str ] - Annotation.Typed modName anns -> + Annotation.Typed _ anns -> List.concatMap (getGenericsHelper << denode) anns Annotation.Unit -> @@ -634,27 +625,23 @@ getGenericsHelper ann = Annotation.Record recordDefinition -> List.concatMap - (\nodedField -> - case denode nodedField of - ( name, field ) -> - getGenericsHelper (denode field) + (\(Node _ ( _, Node _ field )) -> + getGenericsHelper field ) recordDefinition - Annotation.GenericRecord recordName recordDefinition -> - denode recordName + Annotation.GenericRecord (Node _ recordName) (Node _ recordDefinition) -> + recordName :: List.concatMap - (\nodedField -> - case denode nodedField of - ( name, field ) -> - getGenericsHelper (denode field) + (\(Node _ ( _, Node _ field )) -> + getGenericsHelper field ) - (denode recordDefinition) + recordDefinition - Annotation.FunctionTypeAnnotation one two -> + Annotation.FunctionTypeAnnotation (Node _ one) (Node _ two) -> List.concatMap getGenericsHelper - [ denode one - , denode two + [ one + , two ] @@ -709,6 +696,7 @@ getAnnotation exp = documentation : String -> Declaration -> Declaration documentation rawDoc decl = let + doc : String doc = String.trim rawDoc in @@ -720,7 +708,7 @@ documentation rawDoc decl = Comment _ -> decl - Block source -> + Block _ -> decl Declaration details -> @@ -993,22 +981,7 @@ getExposedGroups decls = matchName : Maybe a -> Maybe a -> Bool matchName one two = - case one of - Nothing -> - case two of - Nothing -> - True - - _ -> - False - - Just oneName -> - case two of - Nothing -> - False - - Just twoName -> - oneName == twoName + one == two groupExposing : List ( Maybe String, String ) -> List { group : Maybe String, members : List String } @@ -1128,12 +1101,13 @@ threadHelper index exps rendered = resolve : Index -> VariableCache -> Annotation.TypeAnnotation -> Result String Annotation.TypeAnnotation resolve index cache annotation = if Index.typecheck index then - let - restrictions = - getRestrictions annotation cache - in case resolveVariables Set.empty cache annotation of Ok newAnnotation -> + let + restrictions : Restrictions + restrictions = + getRestrictions annotation cache + in newAnnotation |> rewriteTypeVariables |> checkRestrictions restrictions @@ -1185,75 +1159,45 @@ resolveVariables visited cache annotation = Result.map Annotation.Tupled (resolveVariableList visited cache nodes []) Annotation.Record fields -> - Result.map (Annotation.Record << List.reverse) - (List.foldl - (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) found -> - case found of - Err err -> - Err err - - Ok processedFields -> - case resolveVariables visited cache fieldType of - Err err -> - Err err - - Ok resolvedField -> - let - restrictions = - getRestrictions annotation cache - in - case checkRestrictions restrictions resolvedField of - Ok _ -> - Ok - (Node fieldRange - ( name, Node fieldTypeRange resolvedField ) - :: processedFields - ) - - Err err -> - -- Note, this error probably need - Err err - ) - (Ok []) - fields + Result.Extra.combineMap + (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) -> + resolveVariables visited cache fieldType + |> Result.andThen + (\resolvedField -> + let + restrictions : Restrictions + restrictions = + getRestrictions annotation cache + in + Result.map + (\_ -> + Node fieldRange + ( name, Node fieldTypeRange resolvedField ) + ) + (checkRestrictions restrictions resolvedField) + ) ) + fields + |> Result.map Annotation.Record Annotation.GenericRecord baseName (Node recordNode fields) -> - let - newFieldResult = - List.foldl - (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) found -> - case found of - Err err -> - Err err - - Ok processedFields -> - case resolveVariables visited cache fieldType of - Err err -> - Err err - - Ok resolvedField -> - let - restrictions = - getRestrictions annotation cache - in - Ok - (Node fieldRange - ( name, Node fieldTypeRange resolvedField ) - :: processedFields - ) - ) - (Ok []) - fields - in - Result.map - (\newFields -> - Annotation.GenericRecord baseName - (Node recordNode - (List.reverse newFields) + Result.Extra.combineMap + (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) -> + Result.map + (\resolvedField -> + Node fieldRange + ( name, Node fieldTypeRange resolvedField ) ) + (resolveVariables visited cache fieldType) ) - newFieldResult + fields + |> Result.map + (\newFields -> + Annotation.GenericRecord baseName + (Node recordNode + newFields + ) + ) resolveVariableList : @@ -1404,7 +1348,7 @@ getRestrictionsHelper : -> Restrictions getRestrictionsHelper existingRestrictions notation cache = case notation of - Annotation.FunctionTypeAnnotation (Node.Node oneCoords one) (Node.Node twoCoords two) -> + Annotation.FunctionTypeAnnotation _ _ -> existingRestrictions Annotation.GenericType name -> @@ -1415,25 +1359,26 @@ getRestrictionsHelper existingRestrictions notation cache = ) cache - Annotation.Typed nodedModuleName vars -> + Annotation.Typed _ _ -> existingRestrictions Annotation.Unit -> existingRestrictions - Annotation.Tupled nodes -> + Annotation.Tupled _ -> existingRestrictions - Annotation.Record fields -> + Annotation.Record _ -> existingRestrictions - Annotation.GenericRecord baseName (Node recordNode fields) -> + Annotation.GenericRecord _ _ -> existingRestrictions rewriteTypeVariables : Annotation.TypeAnnotation -> Annotation.TypeAnnotation rewriteTypeVariables type_ = let + existing : Set String existing = getGenericsHelper type_ |> Set.fromList @@ -1448,6 +1393,7 @@ rewriteTypeVariablesHelper existing renames type_ = case Dict.get varName renames of Nothing -> let + simplified : String simplified = simplify varName in @@ -1466,10 +1412,10 @@ rewriteTypeVariablesHelper existing renames type_ = ( newUsed, newVars ) = vars |> List.foldl - (\typevar ( varUsed, varList ) -> + (\(Node _ typevar) ( varUsed, varList ) -> let ( oneUsed, oneType ) = - rewriteTypeVariablesHelper existing varUsed (denode typevar) + rewriteTypeVariablesHelper existing varUsed typevar in ( oneUsed, nodify oneType :: varList ) ) @@ -1482,22 +1428,22 @@ rewriteTypeVariablesHelper existing renames type_ = Annotation.Unit -> ( renames, type_ ) - Annotation.Tupled valsA -> + Annotation.Tupled _ -> ( renames, type_ ) - Annotation.Record fieldsA -> + Annotation.Record _ -> ( renames, type_ ) - Annotation.GenericRecord (Node.Node _ reVarName) (Node.Node fieldsARange fieldsA) -> + Annotation.GenericRecord _ _ -> ( renames, type_ ) - Annotation.FunctionTypeAnnotation one two -> + Annotation.FunctionTypeAnnotation (Node _ one) (Node _ two) -> let ( oneUsed, oneType ) = - rewriteTypeVariablesHelper existing renames (denode one) + rewriteTypeVariablesHelper existing renames one ( twoUsed, twoType ) = - rewriteTypeVariablesHelper existing oneUsed (denode two) + rewriteTypeVariablesHelper existing oneUsed two in ( twoUsed , Annotation.FunctionTypeAnnotation @@ -1509,25 +1455,10 @@ rewriteTypeVariablesHelper existing renames type_ = {-| -} simplify : String -> String simplify fullStr = - String.split "_" fullStr - |> List.foldl - (\piece str -> - let - isDigit = - String.all Char.isDigit piece - in - if isDigit then - str - - else - case str of - "" -> - piece - - _ -> - str ++ "_" ++ piece - ) - "" + fullStr + |> String.split "_" + |> List.filter (\piece -> not <| String.all Char.isDigit piece) + |> String.join "_" checkRestrictions : Restrictions -> Annotation.TypeAnnotation -> Result String Annotation.TypeAnnotation @@ -1689,7 +1620,7 @@ applyTypeHelper : -> Result (List InferenceError) Inference applyTypeHelper aliases cache fn args = case fn of - Annotation.FunctionTypeAnnotation one two -> + Annotation.FunctionTypeAnnotation (Node _ one) (Node _ two) -> case args of [] -> Ok @@ -1699,18 +1630,16 @@ applyTypeHelper aliases cache fn args = } top :: rest -> - case unifiable aliases cache (denode one) top of + case unifiable aliases cache one top of ( variableCache, Ok _ ) -> applyTypeHelper aliases variableCache - (denode two) + two rest - ( varCache, Err err ) -> - Err - [ err - ] + ( _, Err err ) -> + Err [ err ] Annotation.GenericType varName -> case args of @@ -1723,6 +1652,7 @@ applyTypeHelper aliases cache fn args = _ -> let + resultType : Annotation.TypeAnnotation resultType = Annotation.GenericType (varName ++ "_result") in @@ -1833,7 +1763,7 @@ unifyHelper exps existing = case top.annotation of Ok ann -> case unifiable ann.aliases ann.inferences ann.type_ existing.type_ of - ( _, Err err ) -> + ( _, Err _ ) -> Err [ MismatchedList ann.type_ existing.type_ ] @@ -1883,6 +1813,13 @@ unifyOn (Annotation annDetails) res = [ err ] +unifyWithAlias : + AliasCache + -> VariableCache + -> Node ( ModuleName.ModuleName, String ) + -> List (Node Annotation.TypeAnnotation) + -> Annotation.TypeAnnotation + -> Maybe ( VariableCache, Result error Annotation.TypeAnnotation ) unifyWithAlias aliases vars typename typeVars typeToUnifyWith = case getAlias typename aliases of Nothing -> @@ -1890,6 +1827,7 @@ unifyWithAlias aliases vars typename typeVars typeToUnifyWith = Just foundAlias -> let + fullAliasedType : Annotation.TypeAnnotation fullAliasedType = case foundAlias.variables of [] -> @@ -1897,6 +1835,7 @@ unifyWithAlias aliases vars typename typeVars typeToUnifyWith = _ -> let + makeAliasVarCache : a -> Node b -> ( a, b ) makeAliasVarCache varName (Node.Node _ varType) = ( varName, varType ) in @@ -1921,12 +1860,12 @@ unifyWithAlias aliases vars typename typeVars typeToUnifyWith = typeToUnifyWith in case unifiedResult of - Ok finalInference -> + Ok _ -> -- We want to maintain the declared alias in the type signature -- So, we are using `unifiable` to check that Just ( returnedVars, Ok fullAliasedType ) - Err err -> + Err _ -> Nothing @@ -2071,7 +2010,7 @@ unifiable aliases vars one two = ( newVars, Err err ) -> ( newVars, Err err ) - Just knownType -> + Just _ -> -- NOTE: we should probably check knownType in some way? case unifiableFields aliases vars fieldsA fieldsB [] of ( newVars, Ok unifiedFields ) -> @@ -2103,7 +2042,7 @@ unifiable aliases vars one two = _ -> ( vars, Err (UnableToUnify one two) ) - Annotation.GenericRecord (Node.Node _ reVarName) (Node.Node fieldsARange fieldsA) -> + Annotation.GenericRecord _ (Node.Node _ fieldsA) -> case two of Annotation.GenericType b -> case Dict.get b vars of @@ -2130,7 +2069,7 @@ unifiable aliases vars one two = ( newVars, Err err ) -> ( newVars, Err err ) - Just knownType -> + Just _ -> -- NOTE: we should probably check knownType in some way? case unifiableFields aliases vars fieldsA fieldsB [] of ( newVars, Ok unifiedFields ) -> @@ -2162,7 +2101,7 @@ unifiable aliases vars one two = _ -> ( vars, Err (UnableToUnify one two) ) - Annotation.FunctionTypeAnnotation oneA oneB -> + Annotation.FunctionTypeAnnotation (Node _ oneA) (Node _ oneB) -> case two of Annotation.GenericType b -> case Dict.get b vars of @@ -2174,10 +2113,10 @@ unifiable aliases vars one two = Just foundTwo -> unifiable aliases vars one foundTwo - Annotation.FunctionTypeAnnotation twoA twoB -> - case unifiable aliases vars (denode oneA) (denode twoA) of + Annotation.FunctionTypeAnnotation (Node _ twoA) (Node _ twoB) -> + case unifiable aliases vars oneA twoA of ( aVars, Ok unifiedA ) -> - case unifiable aliases aVars (denode oneB) (denode twoB) of + case unifiable aliases aVars oneB twoB of ( bVars, Ok unifiedB ) -> ( bVars , Ok @@ -2214,22 +2153,12 @@ unifiableFields aliases vars one two unified = ( [], [] ) -> ( vars, Ok (nodifyAll (List.reverse unified)) ) - ( oneX :: oneRemain, twoFields ) -> - let - ( oneFieldName, oneFieldVal ) = - denode oneX - - oneName = - denode oneFieldName - - oneVal = - denode oneFieldVal - in - case getField oneName oneVal twoFields [] of + ( (Node _ ( Node _ oneFieldName, Node _ oneFieldVal )) :: oneRemain, twoFields ) -> + case getField oneFieldName oneFieldVal twoFields [] of Ok ( matchingFieldVal, remainingTwo ) -> let ( newVars, unifiedFieldResult ) = - unifiable aliases vars oneVal matchingFieldVal + unifiable aliases vars oneFieldVal matchingFieldVal in case unifiedFieldResult of Ok unifiedField -> @@ -2237,7 +2166,7 @@ unifiableFields aliases vars one two unified = newVars oneRemain remainingTwo - (( nodify oneName, nodify unifiedField ) :: unified) + (( nodify oneFieldName, nodify unifiedField ) :: unified) Err err -> ( newVars, Err err ) @@ -2249,6 +2178,17 @@ unifiableFields aliases vars one two unified = ( vars, Err MismatchedTypeVariables ) +getField : + String + -> Annotation.TypeAnnotation + -> List (Node ( Node String, Node Annotation.TypeAnnotation )) + -> List (Node ( Node String, Node Annotation.TypeAnnotation )) + -> + Result + InferenceError + ( Annotation.TypeAnnotation + , List (Node ( Node String, Node Annotation.TypeAnnotation )) + ) getField name val fields captured = case fields of [] -> @@ -2264,14 +2204,8 @@ getField name val fields captured = top :: remain -> let - ( topFieldName, topFieldVal ) = + ( Node _ topName, Node _ topVal ) = denode top - - topName = - denode topFieldName - - topVal = - denode topFieldVal in if topName == name then Ok @@ -2283,25 +2217,32 @@ getField name val fields captured = getField name val remain (top :: captured) +unifiableLists : + AliasCache + -> VariableCache + -> List (Node Annotation.TypeAnnotation) + -> List (Node Annotation.TypeAnnotation) + -> List Annotation.TypeAnnotation + -> ( VariableCache, Result InferenceError (List (Node Annotation.TypeAnnotation)) ) unifiableLists aliases vars one two unified = case ( one, two ) of ( [], [] ) -> ( vars, Ok (nodifyAll (List.reverse unified)) ) - ( [ oneX ], [ twoX ] ) -> - case unifiable aliases vars (denode oneX) (denode twoX) of + ( [ Node _ oneX ], [ Node _ twoX ] ) -> + case unifiable aliases vars oneX twoX of ( newVars, Ok un ) -> ( newVars, Ok (nodifyAll (List.reverse (un :: unified))) ) ( newVars, Err err ) -> ( newVars, Err err ) - ( oneX :: oneRemain, twoX :: twoRemain ) -> - case unifiable aliases vars (denode oneX) (denode twoX) of + ( (Node _ oneX) :: oneRemain, (Node _ twoX) :: twoRemain ) -> + case unifiable aliases vars oneX twoX of ( newVars, Ok un ) -> unifiableLists aliases newVars oneRemain twoRemain (un :: unified) - ( newVars, Err err ) -> + ( _, Err err ) -> ( vars, Err err ) _ -> @@ -2325,7 +2266,7 @@ unifyNumber vars numberName two = , Ok two ) - Annotation.GenericType twoVarName -> + Annotation.GenericType _ -> -- We don't know how this will resolve -- So, for now we say this is fine -- and in the resolveVariables step, we need to check that everything works @@ -2361,7 +2302,7 @@ unifyAppendable vars numberName two = , Ok two ) - Annotation.GenericType twoVarName -> + Annotation.GenericType _ -> -- We don't know how this will resolve -- So, for now we say this is fine -- and in the resolveVariables step, we need to check that everything works @@ -2399,7 +2340,7 @@ isAppendable annotation = Annotation.Typed (Node.Node _ ( [], "String" )) _ -> True - Annotation.Typed (Node.Node _ ( [], "List" )) [ Node.Node _ inner ] -> + Annotation.Typed (Node.Node _ ( [], "List" )) [ _ ] -> True _ -> @@ -2445,7 +2386,7 @@ unifyComparable vars comparableName two = else case two of - Annotation.GenericType twoVarName -> + Annotation.GenericType _ -> -- We don't know how this will resolve -- So, for now we say this is fine -- and in the resolveVariables step, we need to check that everything works @@ -2460,6 +2401,19 @@ unifyComparable vars comparableName two = ) +resolveField : + Index + -> Annotation.TypeAnnotation + -> AliasCache + -> VariableCache + -> String + -> + Result + (List InferenceError) + { type_ : Annotation.TypeAnnotation + , inferences : VariableCache + , aliases : AliasCache + } resolveField index type_ aliases inferences fieldName = if Index.typecheck index then case type_ of @@ -2481,8 +2435,8 @@ resolveField index type_ aliases inferences fieldName = } ] - Annotation.GenericRecord name fields -> - case getFieldFromList fieldName (denode fields) of + Annotation.GenericRecord _ (Node _ fields) -> + case getFieldFromList fieldName fields of Just ann -> Ok { type_ = ann @@ -2497,7 +2451,7 @@ resolveField index type_ aliases inferences fieldName = , existingFields = List.map (denode >> Tuple.first >> denode) - (denode fields) + fields } ] @@ -2507,7 +2461,7 @@ resolveField index type_ aliases inferences fieldName = , fieldName = fieldName } - Annotation.Typed nodedModAndName vars -> + Annotation.Typed nodedModAndName _ -> case getAlias nodedModAndName aliases of Nothing -> Err @@ -2557,14 +2511,12 @@ getFieldFromList selector fields = [] -> Nothing - nodifiedTop :: remain -> - case denode nodifiedTop of - ( fieldname, contents ) -> - if denode fieldname == selector then - Just (denode contents) + (Node _ ( Node _ fieldname, Node _ contents )) :: remain -> + if fieldname == selector then + Just contents - else - getFieldFromList selector remain + else + getFieldFromList selector remain addInference : @@ -2581,7 +2533,7 @@ addInference key value infs = Just (Annotation.GenericRecord (Node.Node range recordName) (Node.Node fieldRange fields)) -> case value of - Annotation.GenericRecord (Node.Node existingRange existingRecordName) (Node.Node existingFieldRange existingFields) -> + Annotation.GenericRecord _ (Node.Node _ existingFields) -> Just (Annotation.GenericRecord (Node.Node range recordName) @@ -2627,6 +2579,7 @@ containsFieldByName ( Node.Node _ oneName, _ ) ( Node.Node _ twoName, _ ) = inferRecordField : Index -> { nameOfRecord : String, fieldName : String } -> Result (List InferenceError) Inference inferRecordField index { nameOfRecord, fieldName } = let + fieldType : Annotation.TypeAnnotation fieldType = Annotation.GenericType (Format.formatValue @@ -2668,6 +2621,7 @@ protectInference index infResult = Err err +protectAnnotation : Index -> Annotation.TypeAnnotation -> Annotation.TypeAnnotation protectAnnotation index ann = case ann of Annotation.GenericType str -> @@ -2703,6 +2657,7 @@ protectAnnotation index ann = (mapNode (protectAnnotation index) two) +protectField : Index -> Node ( a, Node Annotation.TypeAnnotation ) -> Node ( a, Node Annotation.TypeAnnotation ) protectField index (Node.Node nodeRange ( nodedName, nodedType )) = Node.Node nodeRange ( nodedName diff --git a/src/Internal/Debug.elm b/src/Internal/Debug.elm index c88e7de5..fb340957 100644 --- a/src/Internal/Debug.elm +++ b/src/Internal/Debug.elm @@ -1,4 +1,4 @@ -module Internal.Debug exposing (annotationFormatted, everything, everythingFormatted, facts) +module Internal.Debug exposing (facts) import Dict import Internal.Compiler as Compiler @@ -14,6 +14,7 @@ import Internal.Write facts : Compiler.Expression -> Result String (List ( String, String )) facts (Compiler.Expression exp) = let + expresh : Compiler.ExpressionDetails expresh = exp Index.startIndex in @@ -28,17 +29,9 @@ facts (Compiler.Expression exp) = |> Ok Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - Compiler.inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ Compiler.inferenceErrorToString err - ) - "" - inferenceError + inferenceError + |> List.map Compiler.inferenceErrorToString + |> String.join "\n\n" |> Err @@ -48,6 +41,7 @@ everythingFormatted : -> List String everythingFormatted log exp = let + every : Result String { facts : List ( String, String ), signature : String, aliases : List ( String, String ) } every = everything exp @@ -59,8 +53,7 @@ everythingFormatted log exp = [ err ] Ok e -> - List.concatMap - identity + List.concat [ [ "Signature" , " " ++ e.signature ] @@ -83,6 +76,7 @@ annotationFormatted : -> List String annotationFormatted log ann = let + every : Result String { facts : List ( String, String ), signature : String, aliases : List ( String, String ) } every = annotation ann @@ -94,8 +88,7 @@ annotationFormatted log ann = [ err ] Ok e -> - List.concatMap - identity + List.concat [ [ "Signature" , " " ++ e.signature ] @@ -121,6 +114,7 @@ everything : } everything (Compiler.Expression exp) = let + expresh : Compiler.ExpressionDetails expresh = exp Index.startIndex in @@ -143,6 +137,7 @@ annotation ann = case ann of Ok sig -> let + allFacts : List ( String, String ) allFacts = sig.inferences |> Dict.toList @@ -164,15 +159,7 @@ annotation ann = } Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - Compiler.inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ Compiler.inferenceErrorToString err - ) - "" - inferenceError + inferenceError + |> List.map Compiler.inferenceErrorToString + |> String.join "\n\n" |> Err diff --git a/src/Internal/Format.elm b/src/Internal/Format.elm index 751428e0..ce1b2917 100644 --- a/src/Internal/Format.elm +++ b/src/Internal/Format.elm @@ -10,6 +10,7 @@ module Internal.Format exposing (formatDeclarationName, formatType, formatValue, formatValue : String -> String formatValue str = let + formatted : String formatted = String.toLower (String.left 1 str) ++ String.dropLeft 1 str in diff --git a/src/Internal/ImportsAndExposing.elm b/src/Internal/ImportsAndExposing.elm index 8910b17e..9135eb41 100644 --- a/src/Internal/ImportsAndExposing.elm +++ b/src/Internal/ImportsAndExposing.elm @@ -1,7 +1,8 @@ module Internal.ImportsAndExposing exposing (sortAndDedupExposings, sortAndDedupImports) -import Elm.Syntax.Exposing exposing (ExposedType, Exposing(..), TopLevelExpose(..)) +import Elm.Syntax.Exposing exposing (Exposing(..), TopLevelExpose(..)) import Elm.Syntax.Import exposing (Import) +import Elm.Syntax.ModuleName import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Range exposing (emptyRange) @@ -29,7 +30,7 @@ topLevelExposeOrder tlel tler = ( _, InfixExpose _ ) -> GT - ( _, _ ) -> + _ -> compare (topLevelExposeName tlel) (topLevelExposeName tler) @@ -61,6 +62,7 @@ groupByExposingName innerImports = List.foldl (\exp ( currName, currAccum, accum ) -> let + nextName : String nextName = topLevelExposeName exp in @@ -102,7 +104,7 @@ combineTopLevelExposes exposes = _ -> exp - ( _, _ ) -> + _ -> result ) hd @@ -161,6 +163,7 @@ sortAndDedupExposing exp = sortAndDedupImports : List Import -> List Import sortAndDedupImports imports = let + impName : Import -> Elm.Syntax.ModuleName.ModuleName impName imp = denode imp.moduleName in @@ -181,6 +184,7 @@ groupByModuleName innerImports = List.foldl (\imp ( currName, currAccum, accum ) -> let + nextName : Elm.Syntax.ModuleName.ModuleName nextName = denode imp.moduleName in @@ -207,6 +211,7 @@ combineImports innerImports = hd :: tl -> let + combinedImports : Import combinedImports = List.foldl (\imp result -> diff --git a/src/Internal/Index.elm b/src/Internal/Index.elm index 93703e62..6fd62c6a 100644 --- a/src/Internal/Index.elm +++ b/src/Internal/Index.elm @@ -1,6 +1,6 @@ module Internal.Index exposing ( Index, startIndex, startChecked - , next, nextN, dive + , next, dive , getName, indexToString, protectTypeName , typecheck ) @@ -9,7 +9,7 @@ module Internal.Index exposing @docs Index, startIndex, startChecked -@docs next, nextN, dive +@docs next, dive @docs getName, indexToString, protectTypeName @@ -43,7 +43,7 @@ type Index typecheck : Index -> Bool -typecheck (Index top tail scope check) = +typecheck (Index _ _ _ check) = check @@ -81,6 +81,7 @@ dive (Index top tail scope check) = getName : String -> Index -> ( String, Index ) getName desiredName ((Index top tail scope check) as index) = let + formattedName : String formattedName = Format.formatValue desiredName in @@ -89,6 +90,7 @@ getName desiredName ((Index top tail scope check) as index) = else let + protectedName : String protectedName = formattedName ++ String.fromInt top in @@ -99,6 +101,7 @@ getName desiredName ((Index top tail scope check) as index) = else let + protectedNameLevel2 : String protectedNameLevel2 = formattedName ++ indexToString index in @@ -108,7 +111,7 @@ getName desiredName ((Index top tail scope check) as index) = protectTypeName : String -> Index -> String -protectTypeName base ((Index top tail scope check) as index) = +protectTypeName base ((Index _ tail _ _) as index) = case tail of [] -> Format.formatValue base @@ -119,7 +122,7 @@ protectTypeName base ((Index top tail scope check) as index) = indexToString : Index -> String -indexToString (Index top tail scope check) = +indexToString (Index top tail _ _) = (if top == 0 then "" diff --git a/src/Internal/Render.elm b/src/Internal/Render.elm index e085a23b..a58f792f 100644 --- a/src/Internal/Render.elm +++ b/src/Internal/Render.elm @@ -3,6 +3,7 @@ module Internal.Render exposing (render) {-| -} import Elm.Syntax.Declaration +import Elm.Syntax.Documentation import Elm.Syntax.Exposing as Expose import Elm.Syntax.Module import Elm.Syntax.Range as Range @@ -10,7 +11,7 @@ import Internal.Comments import Internal.Compiler as Compiler import Internal.Index as Index import Internal.Write -import Set exposing (Set) +import Set {-| -} @@ -49,6 +50,7 @@ render : -> File render toDocComment fileDetails = let + rendered : { declarations : List Compiler.RenderedDeclaration, imports : List Compiler.Module, exposed : List Expose.TopLevelExpose, exposedGroups : List ( Maybe String, String ), hasPorts : Bool, warnings : List Compiler.Warning } rendered = List.foldl (\decl gathered -> @@ -61,6 +63,7 @@ render toDocComment fileDetails = Compiler.Declaration decDetails -> let + result : { declaration : Elm.Syntax.Declaration.Declaration, additionalImports : List Compiler.Module, warning : Maybe Compiler.Warning } result = decDetails.toBody fileDetails.index in @@ -106,6 +109,7 @@ render toDocComment fileDetails = } fileDetails.declarations + body : String body = Internal.Write.write { moduleDefinition = @@ -177,6 +181,7 @@ dedupImports mods = List.foldl (\mod ( set, gathered ) -> let + stringName : String stringName = Compiler.fullModName mod in @@ -194,6 +199,7 @@ dedupImports mods = |> List.sortBy Compiler.fullModName +addDocs : Maybe Elm.Syntax.Documentation.Documentation -> Elm.Syntax.Declaration.Declaration -> Elm.Syntax.Declaration.Declaration addDocs maybeDoc decl = case maybeDoc of Nothing -> @@ -223,7 +229,7 @@ addDocs maybeDoc decl = (Compiler.nodify doc) } - Elm.Syntax.Declaration.PortDeclaration sig -> + Elm.Syntax.Declaration.PortDeclaration _ -> decl Elm.Syntax.Declaration.InfixDeclaration _ -> @@ -233,6 +239,7 @@ addDocs maybeDoc decl = decl +addExposed : Compiler.Expose -> Elm.Syntax.Declaration.Declaration -> List Expose.TopLevelExpose -> List Expose.TopLevelExpose addExposed exposed declaration otherExposes = case exposed of Compiler.NotExposed -> @@ -242,6 +249,7 @@ addExposed exposed declaration otherExposes = case declaration of Elm.Syntax.Declaration.FunctionDeclaration fn -> let + fnName : String fnName = Compiler.denode (.name (Compiler.denode fn.declaration)) in @@ -250,6 +258,7 @@ addExposed exposed declaration otherExposes = Elm.Syntax.Declaration.AliasDeclaration synonym -> let + aliasName : String aliasName = Compiler.denode synonym.name in @@ -258,6 +267,7 @@ addExposed exposed declaration otherExposes = Elm.Syntax.Declaration.CustomTypeDeclaration myType -> let + typeName : String typeName = Compiler.denode myType.name in @@ -274,13 +284,14 @@ addExposed exposed declaration otherExposes = Elm.Syntax.Declaration.PortDeclaration myPort -> let + typeName : String typeName = Compiler.denode myPort.name in Expose.FunctionExpose typeName :: otherExposes - Elm.Syntax.Declaration.InfixDeclaration inf -> + Elm.Syntax.Declaration.InfixDeclaration _ -> otherExposes Elm.Syntax.Declaration.Destructuring _ _ -> @@ -312,19 +323,4 @@ groupExposing items = matchName : Maybe a -> Maybe a -> Bool matchName one two = - case one of - Nothing -> - case two of - Nothing -> - True - - _ -> - False - - Just oneName -> - case two of - Nothing -> - False - - Just twoName -> - oneName == twoName + one == two diff --git a/src/Internal/Types.elm b/src/Internal/Types.elm index 22d7d860..13ebd45a 100644 --- a/src/Internal/Types.elm +++ b/src/Internal/Types.elm @@ -1,9 +1,8 @@ module Internal.Types exposing (appendable, bool, char, comparable, custom, float, function, int, list, string, var) -import Elm.Syntax.Node as Node exposing (Node(..)) +import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation -import Internal.Compiler exposing (Annotation) import Internal.Format as Format @@ -20,6 +19,7 @@ nodify exp = formatValue : String -> String formatValue str = let + formatted : String formatted = if String.toUpper str == str then String.toLower str diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index 4fe83377..e972f800 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -2,13 +2,11 @@ module Internal.Write exposing ( write , writeAnnotation , writeAnnotationWith - , writeDeclaration , writeDeclarationWith , writeExpression , writeExpressionWith , writeImports , writeInference - , writeSignature , writeSignatureWith ) @@ -21,23 +19,21 @@ Thank you Rupert! import Dict import Elm.Syntax.Declaration import Elm.Syntax.Documentation exposing (Documentation) -import Elm.Syntax.Exposing exposing (ExposedType, Exposing(..), TopLevelExpose(..)) -import Elm.Syntax.Expression exposing (Case, CaseBlock, Expression(..), Function, FunctionImplementation, Lambda, LetBlock, LetDeclaration(..), RecordSetter) -import Elm.Syntax.File +import Elm.Syntax.Exposing exposing (Exposing(..), TopLevelExpose(..)) +import Elm.Syntax.Expression exposing (CaseBlock, Expression(..), Function, FunctionImplementation, Lambda, LetBlock, LetDeclaration(..), RecordSetter) import Elm.Syntax.Import exposing (Import) import Elm.Syntax.Infix exposing (Infix, InfixDirection(..)) import Elm.Syntax.Module exposing (DefaultModuleData, EffectModuleData, Module(..)) import Elm.Syntax.ModuleName exposing (ModuleName) -import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (Pattern(..), QualifiedNameRef) -import Elm.Syntax.Range exposing (Location, Range, emptyRange) +import Elm.Syntax.Node exposing (Node(..)) +import Elm.Syntax.Pattern exposing (Pattern(..)) import Elm.Syntax.Signature exposing (Signature) import Elm.Syntax.Type exposing (Type, ValueConstructor) import Elm.Syntax.TypeAlias exposing (TypeAlias) -import Elm.Syntax.TypeAnnotation exposing (RecordDefinition, RecordField, TypeAnnotation(..)) +import Elm.Syntax.TypeAnnotation exposing (RecordField, TypeAnnotation(..)) import Hex import Internal.Comments as Comments -import Internal.Compiler as Util exposing (denode, denodeAll, denodeMaybe, nodify, nodifyAll, nodifyMaybe) +import Internal.Compiler as Util exposing (denode, denodeAll, denodeMaybe, nodify) import Internal.ImportsAndExposing as ImportsAndExposing import Pretty exposing (Doc) @@ -74,7 +70,7 @@ prepareLayout width file = Just fileComment -> let - ( fileCommentStr, innerTags ) = + ( fileCommentStr, _ ) = Comments.prettyFileComment width fileComment in doc @@ -258,6 +254,7 @@ prettyPortModuleData moduleData = prettyEffectModuleData : EffectModuleData -> Doc t prettyEffectModuleData moduleData = let + prettyCmdAndSub : Maybe String -> Maybe String -> Maybe (Doc t) prettyCmdAndSub maybeCmd maybeSub = case ( maybeCmd, maybeSub ) of ( Nothing, Nothing ) -> @@ -339,6 +336,7 @@ The exposed values will be de-duplicated and sorted. prettyExposing : Exposing -> Doc t prettyExposing exposing_ = let + exposings : Doc t exposings = case exposing_ of All _ -> @@ -386,7 +384,7 @@ prettyTopLevelExpose tlExpose = {-| Pretty prints a single top-level declaration. -} prettyDeclaration : Int -> Util.RenderedDeclaration -> Doc t -prettyDeclaration width decl = +prettyDeclaration _ decl = case decl of Util.RenderedDecl innerDecl -> prettyElmSyntaxDeclaration noAliases innerDecl @@ -423,8 +421,8 @@ prettyElmSyntaxDeclaration aliases decl = Elm.Syntax.Declaration.InfixDeclaration infix_ -> prettyInfix infix_ - Elm.Syntax.Declaration.Destructuring pattern expr -> - prettyDestructuring aliases (denode pattern) (denode expr) + Elm.Syntax.Declaration.Destructuring (Node _ pattern) (Node _ expr) -> + prettyDestructuring aliases pattern expr prettyDeclarations : Aliases -> List Util.RenderedDeclaration -> Doc t @@ -468,6 +466,7 @@ prettyFun aliases fn = prettyTypeAlias : Aliases -> TypeAlias -> Doc t prettyTypeAlias aliases tAlias = let + typeAliasPretty : Doc t typeAliasPretty = [ Pretty.string "type alias" , Pretty.string (denode tAlias.name) @@ -490,6 +489,7 @@ prettyTypeAlias aliases tAlias = prettyCustomType : Aliases -> Type -> Doc t prettyCustomType aliases type_ = let + customTypePretty : Doc t customTypePretty = [ Pretty.string "type" , Pretty.string (denode type_.name) @@ -536,6 +536,7 @@ prettyPortDeclaration aliases sig = prettyInfix : Infix -> Doc t prettyInfix infix_ = let + dirToString : InfixDirection -> String dirToString direction = case direction of Left -> @@ -627,6 +628,7 @@ prettyPattern aliases pattern = adjustPatternParentheses : Bool -> Pattern -> Pattern adjustPatternParentheses isTop pattern = let + addParens : Pattern -> Pattern addParens pat = case ( isTop, pat ) of ( False, NamedPattern _ (_ :: _) ) -> @@ -635,15 +637,15 @@ adjustPatternParentheses isTop pattern = ( False, AsPattern _ _ ) -> nodify pat |> ParenthesizedPattern - ( _, _ ) -> + _ -> pat + removeParens : Pattern -> Pattern removeParens pat = case pat of - ParenthesizedPattern innerPat -> - if shouldRemove (denode innerPat) then - denode innerPat - |> removeParens + ParenthesizedPattern (Node _ innerPat) -> + if shouldRemove innerPat then + removeParens innerPat else pat @@ -651,6 +653,7 @@ adjustPatternParentheses isTop pattern = _ -> pat + shouldRemove : Pattern -> Bool shouldRemove pat = case ( isTop, pat ) of ( False, NamedPattern _ _ ) -> @@ -659,7 +662,7 @@ adjustPatternParentheses isTop pattern = ( _, AsPattern _ _ ) -> False - ( _, _ ) -> + _ -> isTop in removeParens pattern @@ -707,10 +710,10 @@ prettyPatternInner aliases isTop pattern = |> Pretty.surround Pretty.space Pretty.space |> Pretty.braces - UnConsPattern hdPat tlPat -> - [ prettyPatternInner aliases False (denode hdPat) + UnConsPattern (Node _ hdPat) (Node _ tlPat) -> + [ prettyPatternInner aliases False hdPat , Pretty.string "::" - , prettyPatternInner aliases False (denode tlPat) + , prettyPatternInner aliases False tlPat ] |> Pretty.words @@ -721,9 +724,11 @@ prettyPatternInner aliases isTop pattern = _ -> let + open : Doc t open = Pretty.a Pretty.space (Pretty.string "[") + close : Doc t close = Pretty.a (Pretty.string "]") Pretty.space in @@ -741,15 +746,15 @@ prettyPatternInner aliases isTop pattern = :: List.map (prettyPatternInner aliases False) (denodeAll listPats) |> Pretty.words - AsPattern pat name -> - [ prettyPatternInner aliases False (denode pat) + AsPattern (Node _ pat) (Node _ name) -> + [ prettyPatternInner aliases False pat , Pretty.string "as" - , Pretty.string (denode name) + , Pretty.string name ] |> Pretty.words - ParenthesizedPattern pat -> - prettyPatternInner aliases True (denode pat) + ParenthesizedPattern (Node _ pat) -> + prettyPatternInner aliases True pat |> Pretty.parens @@ -764,6 +769,7 @@ type alias Context = } +topContext : { precedence : number, isTop : Bool, isLeftPipe : Bool } topContext = { precedence = 11 , isTop = True @@ -774,6 +780,7 @@ topContext = adjustExpressionParentheses : Context -> Expression -> Expression adjustExpressionParentheses context expression = let + addParens : Expression -> Expression addParens expr = case ( context.isTop, context.isLeftPipe, expr ) of ( False, False, LetExpression _ ) -> @@ -788,15 +795,15 @@ adjustExpressionParentheses context expression = ( False, False, IfBlock _ _ _ ) -> nodify expr |> ParenthesizedExpression - ( _, _, _ ) -> + _ -> expr + removeParens : Expression -> Expression removeParens expr = case expr of - ParenthesizedExpression innerExpr -> - if shouldRemove (denode innerExpr) then - denode innerExpr - |> removeParens + ParenthesizedExpression (Node _ innerExpr) -> + if shouldRemove innerExpr then + removeParens innerExpr else expr @@ -804,6 +811,7 @@ adjustExpressionParentheses context expression = _ -> expr + shouldRemove : Expression -> Bool shouldRemove expr = case ( context.isTop, context.isLeftPipe, expr ) of ( True, _, _ ) -> @@ -813,11 +821,7 @@ adjustExpressionParentheses context expression = True ( False, _, Application _ ) -> - if context.precedence < 11 then - True - - else - False + context.precedence < 11 ( False, _, FunctionOrValue _ _ ) -> True @@ -858,7 +862,7 @@ adjustExpressionParentheses context expression = ( False, _, RecordUpdateExpression _ _ ) -> True - ( _, _, _ ) -> + _ -> False in removeParens expression @@ -921,10 +925,10 @@ prettyExpressionInner aliases context indent expression = , False ) - Negation expr -> + Negation (Node _ expr) -> let ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode expr) + prettyExpressionInner aliases topContext 4 expr in ( Pretty.string "-" |> Pretty.a prettyExpr @@ -974,7 +978,7 @@ prettyExpressionInner aliases context indent expression = RecordUpdateExpression var setters -> prettyRecordUpdateExpression aliases indent var setters - GLSLExpression val -> + GLSLExpression _ -> ( Pretty.string "glsl" , True ) @@ -1007,12 +1011,7 @@ prettyApplication aliases indent exprs = isEndLineOperator : String -> Bool isEndLineOperator op = - case op of - "<|" -> - True - - _ -> - False + op == "<|" prettyOperatorApplication : Aliases -> Int -> String -> InfixDirection -> Node Expression -> Node Expression -> ( Doc t, Bool ) @@ -1025,8 +1024,9 @@ prettyOperatorApplication aliases indent symbol dir exprl exprr = prettyOperatorApplicationLeft : Aliases -> Int -> String -> InfixDirection -> Node Expression -> Node Expression -> ( Doc t, Bool ) -prettyOperatorApplicationLeft aliases indent symbol _ exprl exprr = +prettyOperatorApplicationLeft aliases _ symbol _ (Node _ exprl) (Node _ exprr) = let + context : Context context = { precedence = precedence symbol , isTop = False @@ -1034,11 +1034,12 @@ prettyOperatorApplicationLeft aliases indent symbol _ exprl exprr = } ( prettyExpressionLeft, alwaysBreakLeft ) = - prettyExpressionInner aliases context 4 (denode exprl) + prettyExpressionInner aliases context 4 exprl ( prettyExpressionRight, alwaysBreakRight ) = - prettyExpressionInner aliases context 4 (denode exprr) + prettyExpressionInner aliases context 4 exprr + alwaysBreak : Bool alwaysBreak = alwaysBreakLeft || alwaysBreakRight in @@ -1065,30 +1066,35 @@ prettyOperatorApplicationRight aliases indent symbol _ exprl exprr = [ prettyExpressionInner aliases context innerIndent expr ] innerOpApply : Bool -> String -> Node Expression -> Node Expression -> List ( Doc t, Bool ) - innerOpApply isTop sym left right = + innerOpApply isTop sym (Node _ left) (Node _ right) = let + context : Context context = { precedence = precedence sym , isTop = False , isLeftPipe = "<|" == sym } + innerIndent : Int innerIndent = decrementIndent 4 (String.length symbol + 1) - leftIndent = - if isTop then - indent - - else - innerIndent - + rightSide : List ( Doc t, Bool ) rightSide = - denode right |> expandExpr innerIndent context + right |> expandExpr innerIndent context in case rightSide of ( hdExpr, hdBreak ) :: tl -> - List.append (denode left |> expandExpr leftIndent context) + let + leftIndent : Int + leftIndent = + if isTop then + indent + + else + innerIndent + in + List.append (left |> expandExpr leftIndent context) (( Pretty.string sym |> Pretty.a Pretty.space |> Pretty.a hdExpr, hdBreak ) :: tl) [] -> @@ -1111,18 +1117,16 @@ prettyIfBlock : Aliases -> Int -> Node Expression -> Node Expression -> Node Exp prettyIfBlock aliases indent exprBool exprTrue exprFalse = let innerIfBlock : Node Expression -> Node Expression -> Node Expression -> List (Doc t) - innerIfBlock innerExprBool innerExprTrue innerExprFalse = + innerIfBlock (Node _ innerExprBool) (Node _ innerExprTrue) (Node _ innerExprFalse) = let - context = - topContext - + ifPart : Doc t ifPart = let - ( prettyBoolExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode innerExprBool) + ( _, alwaysBreak ) = + prettyExpressionInner aliases topContext 4 innerExprBool in [ [ Pretty.string "if" - , prettyExpressionInner aliases topContext 4 (denode innerExprBool) |> Tuple.first + , prettyExpressionInner aliases topContext 4 innerExprBool |> Tuple.first ] |> Pretty.lines |> optionalGroup alwaysBreak @@ -1132,22 +1136,25 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = |> Pretty.lines |> optionalGroup alwaysBreak + truePart : Doc t truePart = - prettyExpressionInner aliases topContext 4 (denode innerExprTrue) + prettyExpressionInner aliases topContext 4 innerExprTrue |> Tuple.first |> Pretty.indent indent + elsePart : Doc t elsePart = Pretty.line |> Pretty.a (Pretty.string "else") + falsePart : List (Doc t) falsePart = - case denode innerExprFalse of + case innerExprFalse of IfBlock nestedExprBool nestedExprTrue nestedExprFalse -> innerIfBlock nestedExprBool nestedExprTrue nestedExprFalse _ -> - [ prettyExpressionInner aliases topContext 4 (denode innerExprFalse) + [ prettyExpressionInner aliases topContext 4 innerExprFalse |> Tuple.first |> Pretty.indent indent ] @@ -1171,6 +1178,7 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = ] tl + prettyExpressions : List (Doc t) prettyExpressions = innerIfBlock exprBool exprTrue exprFalse in @@ -1194,19 +1202,20 @@ prettyLiteral val = prettyTupledExpression : Aliases -> Int -> List (Node Expression) -> ( Doc t, Bool ) prettyTupledExpression aliases indent exprs = - let - open = - Pretty.a Pretty.space (Pretty.string "(") - - close = - Pretty.a (Pretty.string ")") Pretty.line - in case exprs of [] -> ( Pretty.string "()", False ) _ -> let + open : Doc t + open = + Pretty.a Pretty.space (Pretty.string "(") + + close : Doc t + close = + Pretty.a (Pretty.string ")") Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettyExpressionInner aliases topContext (decrementIndent indent 2)) (denodeAll exprs) |> List.unzip @@ -1222,16 +1231,18 @@ prettyTupledExpression aliases indent exprs = prettyParenthesizedExpression : Aliases -> Int -> Node Expression -> ( Doc t, Bool ) -prettyParenthesizedExpression aliases indent expr = +prettyParenthesizedExpression aliases indent (Node _ expr) = let + open : Doc t open = Pretty.string "(" + close : Doc t close = Pretty.a (Pretty.string ")") Pretty.tightline ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext (decrementIndent indent 1) (denode expr) + prettyExpressionInner aliases topContext (decrementIndent indent 1) expr in ( prettyExpr |> Pretty.nest 1 @@ -1263,14 +1274,14 @@ prettyLetDeclaration aliases indent letDecl = LetFunction fn -> prettyFun aliases fn - LetDestructuring pattern expr -> - [ prettyPatternInner aliases False (denode pattern) + LetDestructuring (Node _ pattern) (Node _ expr) -> + [ prettyPatternInner aliases False pattern , Pretty.string "=" ] |> Pretty.words |> Pretty.a Pretty.line |> Pretty.a - (prettyExpressionInner aliases topContext 4 (denode expr) + (prettyExpressionInner aliases topContext 4 expr |> Tuple.first |> Pretty.indent indent ) @@ -1279,6 +1290,7 @@ prettyLetDeclaration aliases indent letDecl = prettyCaseBlock : Aliases -> Int -> CaseBlock -> ( Doc t, Bool ) prettyCaseBlock aliases indent caseBlock = let + casePart : Doc t casePart = let ( caseExpression, alwaysBreak ) = @@ -1295,13 +1307,15 @@ prettyCaseBlock aliases indent caseBlock = |> Pretty.lines |> optionalGroup alwaysBreak - prettyCase ( pattern, expr ) = - prettyPattern aliases (denode pattern) + prettyCase : Elm.Syntax.Expression.Case -> Doc t + prettyCase ( Node _ pattern, Node _ expr ) = + prettyPattern aliases pattern |> Pretty.a (Pretty.string " ->") |> Pretty.a Pretty.line - |> Pretty.a (prettyExpressionInner aliases topContext 4 (denode expr) |> Tuple.first |> Pretty.indent 4) + |> Pretty.a (prettyExpressionInner aliases topContext 4 expr |> Tuple.first |> Pretty.indent 4) |> Pretty.indent indent + patternsPart : Doc t patternsPart = List.map prettyCase caseBlock.cases |> doubleLines @@ -1334,20 +1348,21 @@ prettyLambdaExpression aliases indent lambda = prettyRecordExpr : Aliases -> List (Node RecordSetter) -> ( Doc t, Bool ) prettyRecordExpr aliases setters = - let - open = - Pretty.a Pretty.space (Pretty.string "{") - - close = - Pretty.a (Pretty.string "}") - Pretty.line - in case setters of [] -> ( Pretty.string "{}", False ) _ -> let + open : Doc t + open = + Pretty.a Pretty.space (Pretty.string "{") + + close : Doc t + close = + Pretty.a (Pretty.string "}") + Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettySetter aliases) (denodeAll setters) |> List.unzip @@ -1363,12 +1378,12 @@ prettyRecordExpr aliases setters = prettySetter : Aliases -> ( Node String, Node Expression ) -> ( Doc t, Bool ) -prettySetter aliases ( fld, val ) = +prettySetter aliases ( Node _ fld, Node _ val ) = let ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode val) + prettyExpressionInner aliases topContext 4 val in - ( [ [ Pretty.string (denode fld) + ( [ [ Pretty.string fld , Pretty.string "=" ] |> Pretty.words @@ -1383,19 +1398,20 @@ prettySetter aliases ( fld, val ) = prettyList : Aliases -> Int -> List (Node Expression) -> ( Doc t, Bool ) prettyList aliases indent exprs = - let - open = - Pretty.a Pretty.space (Pretty.string "[") - - close = - Pretty.a (Pretty.string "]") Pretty.line - in case exprs of [] -> ( Pretty.string "[]", False ) _ -> let + open : Doc t + open = + Pretty.a Pretty.space (Pretty.string "[") + + close : Doc t + close = + Pretty.a (Pretty.string "]") Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettyExpressionInner aliases topContext (decrementIndent indent 2)) (denodeAll exprs) |> List.unzip @@ -1411,32 +1427,22 @@ prettyList aliases indent exprs = prettyRecordAccess : Aliases -> Node Expression -> Node String -> ( Doc t, Bool ) -prettyRecordAccess aliases expr field = +prettyRecordAccess aliases (Node _ expr) (Node _ field) = let ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode expr) + prettyExpressionInner aliases topContext 4 expr in ( prettyExpr |> Pretty.a dot - |> Pretty.a (Pretty.string (denode field)) + |> Pretty.a (Pretty.string field) , alwaysBreak ) prettyRecordUpdateExpression : Aliases -> Int -> Node String -> List (Node RecordSetter) -> ( Doc t, Bool ) -prettyRecordUpdateExpression aliases indent var setters = +prettyRecordUpdateExpression aliases indent (Node _ var) setters = let - open = - [ Pretty.string "{" - , Pretty.string (denode var) - ] - |> Pretty.words - |> Pretty.a Pretty.line - - close = - Pretty.a (Pretty.string "}") - Pretty.line - + addBarToFirst : List (Doc t) -> List (Doc t) addBarToFirst exprs = case exprs of [] -> @@ -1451,6 +1457,19 @@ prettyRecordUpdateExpression aliases indent var setters = _ -> let + open : Doc t + open = + [ Pretty.string "{" + , Pretty.string var + ] + |> Pretty.words + |> Pretty.a Pretty.line + + close : Doc t + close = + Pretty.a (Pretty.string "}") + Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettySetter aliases) (denodeAll setters) |> List.unzip @@ -1494,23 +1513,22 @@ prettyTypeAnnotation aliases typeAnn = Record recordDef -> prettyRecord aliases (denodeAll recordDef) - GenericRecord paramName recordDef -> - prettyGenericRecord aliases (denode paramName) (denodeAll (denode recordDef)) + GenericRecord (Node _ paramName) (Node _ recordDef) -> + prettyGenericRecord aliases paramName (denodeAll recordDef) FunctionTypeAnnotation fromAnn toAnn -> prettyFunctionTypeAnnotation aliases fromAnn toAnn prettyTyped : Aliases -> Node ( ModuleName, String ) -> List (Node TypeAnnotation) -> Doc t -prettyTyped aliases fqName anns = +prettyTyped aliases (Node _ ( moduleName, typeName )) anns = let - ( moduleName, typeName ) = - denode fqName - + typeDoc : Doc t typeDoc = prettyModuleNameDot aliases moduleName |> Pretty.a (Pretty.string typeName) + argsDoc : Doc t argsDoc = List.map (prettyTypeAnnotationParens aliases) (denodeAll anns) |> Pretty.words @@ -1543,18 +1561,20 @@ prettyTypeAnnotationParens aliases typeAnn = prettyRecord : Aliases -> List RecordField -> Doc t prettyRecord aliases fields = - let - open = - Pretty.a Pretty.space (Pretty.string "{") - - close = - Pretty.a (Pretty.string "}") Pretty.line - in case fields of [] -> Pretty.string "{}" _ -> + let + open : Doc t + open = + Pretty.a Pretty.space (Pretty.string "{") + + close : Doc t + close = + Pretty.a (Pretty.string "}") Pretty.line + in fields |> List.map (Tuple.mapBoth denode denode) |> List.map (prettyFieldTypeAnn aliases) @@ -1566,17 +1586,7 @@ prettyRecord aliases fields = prettyGenericRecord : Aliases -> String -> List RecordField -> Doc t prettyGenericRecord aliases paramName fields = let - open = - [ Pretty.string "{" - , Pretty.string paramName - ] - |> Pretty.words - |> Pretty.a Pretty.line - - close = - Pretty.a (Pretty.string "}") - Pretty.line - + addBarToFirst : List (Doc t) -> List (Doc t) addBarToFirst exprs = case exprs of [] -> @@ -1590,6 +1600,20 @@ prettyGenericRecord aliases paramName fields = Pretty.string "{}" _ -> + let + open : Doc t + open = + [ Pretty.string "{" + , Pretty.string paramName + ] + |> Pretty.words + |> Pretty.a Pretty.line + + close : Doc t + close = + Pretty.a (Pretty.string "}") + Pretty.line + in open |> Pretty.a (fields @@ -1638,14 +1662,15 @@ prettyFunctionTypeAnnotation aliases left right = [ prettyTypeAnnotation aliases ann ] innerFnTypeAnn : Node TypeAnnotation -> Node TypeAnnotation -> List (Doc t) - innerFnTypeAnn innerLeft innerRight = + innerFnTypeAnn (Node _ innerLeft) (Node _ innerRight) = let + rightSide : List (Doc t) rightSide = - denode innerRight |> expandRight + innerRight |> expandRight in case rightSide of hd :: tl -> - (denode innerLeft |> expandLeft) + (innerLeft |> expandLeft) :: ([ Pretty.string "->", hd ] |> Pretty.words) :: tl @@ -1670,7 +1695,7 @@ isNakedCompound typeAnn = Typed _ [] -> False - Typed _ args -> + Typed _ _ -> True FunctionTypeAnnotation _ _ -> @@ -1693,6 +1718,7 @@ prettyMaybe prettyFn maybeVal = decrementIndent : Int -> Int -> Int decrementIndent currentIndent spaces = let + modded : Int modded = modBy 4 (currentIndent - spaces) in @@ -1782,8 +1808,10 @@ optionalParens flag doc = toHexString : Int -> String toHexString val = let + padWithZeros : String -> String padWithZeros str = let + length : Int length = String.length str in diff --git a/src/Result/Extra.elm b/src/Result/Extra.elm new file mode 100644 index 00000000..11638aaf --- /dev/null +++ b/src/Result/Extra.elm @@ -0,0 +1,21 @@ +module Result.Extra exposing (combineMap) + + +combineMap : (a -> Result e b) -> List a -> Result e (List b) +combineMap f list = + combineMapHelper f [] list + + +combineMapHelper : (a -> Result e b) -> List b -> List a -> Result e (List b) +combineMapHelper f acc list = + case list of + [] -> + Ok (List.reverse acc) + + h :: t -> + case f h of + Err e -> + Err e + + Ok fh -> + combineMapHelper f (fh :: acc) t diff --git a/tests/Declare.elm b/tests/Declare.elm index 70e1ceb8..38d960c6 100644 --- a/tests/Declare.elm +++ b/tests/Declare.elm @@ -2,22 +2,11 @@ module Declare exposing (suite) {-| -} -import Dict import Elm -import Elm.Annotation as Type import Elm.Declare import Elm.Expect -import Elm.Let import Elm.Op -import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) -import Gen.Element -import Gen.Maybe -import Internal.Compiler as Compiler -import Internal.Debug -import Internal.Write -import Test exposing (..) +import Test exposing (Test, describe, test) suite : Test @@ -27,12 +16,14 @@ suite = ] +myFn : { declaration : Elm.Declaration, call : Elm.Expression -> Elm.Expression, callFrom : List String -> Elm.Expression -> Elm.Expression, value : List String -> Elm.Expression } myFn = Elm.Declare.fn "myFn" ( "myInt", Nothing ) (Elm.Op.plus (Elm.int 5)) +declarations : Test declarations = describe "declarations" [ test "Basic function dec" <| @@ -55,4 +46,4 @@ mySweetNumber = myFn 82 """ - ] + ] diff --git a/tests/Elm/Expect.elm b/tests/Elm/Expect.elm index 89bb8709..4e155cb0 100644 --- a/tests/Elm/Expect.elm +++ b/tests/Elm/Expect.elm @@ -1,4 +1,4 @@ -module Elm.Expect exposing (declarationAs, equal, fileContentAs, importAs, infersType, renderedAs) +module Elm.Expect exposing (declarationAs, equal, fileContentAs, importAs, renderedAs) import Elm import Elm.ToString diff --git a/tests/File.elm b/tests/File.elm index 0b1d584f..fc9dae9e 100644 --- a/tests/File.elm +++ b/tests/File.elm @@ -2,24 +2,12 @@ module File exposing (suite) {-| -} -import Dict import Elm -import Elm.Annotation as Type -import Elm.Declare import Elm.Expect -import Elm.Let -import Elm.Op -import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) -import Gen.Element -import Gen.Maybe -import Internal.Compiler as Compiler -import Internal.Debug -import Internal.Write -import Test exposing (..) +import Test exposing (Test, describe, test) +testFn1 : Elm.Declaration testFn1 = Elm.declaration "testFn1" <| Elm.fn ( "arg", Nothing ) <| @@ -27,6 +15,7 @@ testFn1 = arg +testFn2 : Elm.Declaration testFn2 = Elm.declaration "testFn2" <| Elm.fn ( "arg", Nothing ) <| diff --git a/tests/Let.elm b/tests/Let.elm index 0558e7f0..20f904a5 100644 --- a/tests/Let.elm +++ b/tests/Let.elm @@ -1,20 +1,11 @@ module Let exposing (suite) -import Dict import Elm import Elm.Annotation as Type import Elm.Expect import Elm.Let import Elm.Op -import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) -import Gen.Element -import Gen.Maybe -import Internal.Compiler as Compiler -import Internal.Debug -import Internal.Write -import Test exposing (..) +import Test exposing (Test, describe, test) suite : Test diff --git a/tests/PackageHelpers.elm b/tests/PackageHelpers.elm index 6777c0a4..88ace4fe 100644 --- a/tests/PackageHelpers.elm +++ b/tests/PackageHelpers.elm @@ -1,26 +1,25 @@ module PackageHelpers exposing (suite) -import Dict +import Dict exposing (Dict) import Elm -import Elm.Annotation as Type import Elm.Expect import Elm.Op +import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation) import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) +import Expect import Gen.Element import Gen.Maybe import Internal.Compiler as Compiler -import Internal.Debug import Internal.Write -import Test exposing (..) +import Test exposing (Test, describe, test) +detectCycles : List ( String, TypeAnnotation ) -> List Bool detectCycles list = let + dict : Dict String TypeAnnotation dict = - list - |> Dict.fromList + Dict.fromList list in dict |> Dict.keys @@ -30,11 +29,12 @@ detectCycles list = ) +countCycles : List ( String, TypeAnnotation ) -> List number countCycles list = let + dict : Dict String TypeAnnotation dict = - list - |> Dict.fromList + Dict.fromList list in dict |> Dict.keys @@ -44,6 +44,7 @@ countCycles list = ) +hasCycles : Dict String TypeAnnotation -> String -> List String -> Bool hasCycles dict key found = case Dict.get key dict of Nothing -> @@ -51,16 +52,15 @@ hasCycles dict key found = Just type_ -> let + val : String val = Internal.Write.writeAnnotation type_ in - if List.member val found then - True - - else - hasCycles dict val (val :: found) + List.member val found + || hasCycles dict val (val :: found) +findDepth : Dict String TypeAnnotation -> String -> List String -> number -> number findDepth dict key found depth = case Dict.get key dict of Nothing -> @@ -68,6 +68,7 @@ findDepth dict key found depth = Just type_ -> let + val : String val = Internal.Write.writeAnnotation type_ in @@ -97,10 +98,12 @@ packageHelpers = , test "typechecking an Element.row doesn't hang forever" <| \_ -> let + myRow : Elm.Expression myRow = Gen.Element.row [ Gen.Element.spacing 5 ] [ Gen.Element.none ] + layout : Elm.Expression layout = Gen.Element.layout [] (Gen.Element.column [ Gen.Element.spacing 24 ] @@ -110,6 +113,7 @@ packageHelpers = ] ) + cycles : Bool cycles = layout |> Compiler.facts diff --git a/tests/Pattern.elm b/tests/Pattern.elm index 2ae8c93b..4173bc5a 100644 --- a/tests/Pattern.elm +++ b/tests/Pattern.elm @@ -1,15 +1,13 @@ module Pattern exposing (suite) import Elm exposing (Expression) -import Elm.Annotation as Type exposing (Annotation) +import Elm.Annotation as Type import Elm.Case import Elm.Case.Branch as Pattern import Elm.Expect -import Elm.Let import Elm.Op import Elm.ToString import Expect -import Gen.Maybe import Gen.String import Internal.Compiler as Compiler import Internal.Index as Index @@ -91,7 +89,7 @@ suite = Type.unit [ Pattern.triple (Pattern.unit ()) (Pattern.var "name") (Pattern.int 123 (Elm.int 123)) |> Pattern.map - (\( (), name, literalInt ) -> + (\( (), _, _ ) -> Elm.unit ) ] @@ -249,21 +247,21 @@ expectImports expectedImports expression = |> Expect.equal (Set.fromList expectedImports) -fromString = - \fromStringArg -> - Elm.apply - (Elm.value - { importFrom = [ "QueryParams" ] - , name = "fromString" - , annotation = - Just - (Type.function - [ Type.string ] - (Type.namedWith [] "QueryParams" []) - ) - } - ) - [ fromStringArg ] +fromString : Expression -> Expression +fromString fromStringArg = + Elm.apply + (Elm.value + { importFrom = [ "QueryParams" ] + , name = "fromString" + , annotation = + Just + (Type.function + [ Type.string ] + (Type.namedWith [] "QueryParams" []) + ) + } + ) + [ fromStringArg ] renderedAs : String -> Expression -> Expect.Expectation diff --git a/tests/TypeChecking.elm b/tests/TypeChecking.elm index a22c9d25..6f401382 100644 --- a/tests/TypeChecking.elm +++ b/tests/TypeChecking.elm @@ -5,14 +5,13 @@ import Elm.Annotation as Type import Elm.Case import Elm.Op import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) +import Expect import Internal.Compiler as Compiler -import Internal.Debug as Debug import Internal.Index as Index -import Test exposing (..) +import Test exposing (Test, describe, test) +successfullyInferredType : Compiler.Expression -> Expect.Expectation successfullyInferredType expression = let ( _, details ) = @@ -30,6 +29,7 @@ successfullyInferredType expression = ) +renderedAs : Elm.Expression -> String -> Expect.Expectation renderedAs expression str = Expect.equal (Elm.ToString.expression expression @@ -38,6 +38,7 @@ renderedAs expression str = str +declarationAs : Elm.Declaration -> String -> Expect.Expectation declarationAs decl str = Expect.equal (Elm.ToString.declaration decl @@ -169,6 +170,7 @@ generatedCode = , test "Function, arg order isn't reversed" <| \_ -> let + exp : Elm.Expression exp = Elm.function [ ( "str", Just Type.string ) @@ -220,6 +222,7 @@ map fn optional = ] +myMap2 : Elm.Expression myMap2 = Elm.fn2 ( "fn", Nothing ) @@ -229,6 +232,7 @@ myMap2 = ) +myMap : Elm.Expression myMap = Elm.fn2 ( "fn", Nothing ) @@ -240,12 +244,8 @@ myMap = "Present" ( "present", Type.var "a" ) (\a -> - let - result = - present [] - (Elm.apply fn [ a ]) - in - result + present [] + (Elm.apply fn [ a ]) ) , Elm.Case.branch0 "Null" (null []) , Elm.Case.branch0 "Absent" (absent []) @@ -255,22 +255,18 @@ myMap = present : List String -> Elm.Expression -> Elm.Expression present optionalModuleName a = - let - val = - Elm.apply - (Elm.value - { importFrom = optionalModuleName - , name = "Present" - , annotation = - Just - (Type.function [ Type.var "a2" ] (Type.namedWith optionalModuleName "Optional" [ Type.var "a2" ])) - - -- Nothing - } - ) - [ a ] - in - val + Elm.apply + (Elm.value + { importFrom = optionalModuleName + , name = "Present" + , annotation = + Just + (Type.function [ Type.var "a2" ] (Type.namedWith optionalModuleName "Optional" [ Type.var "a2" ])) + + -- Nothing + } + ) + [ a ] null : List String -> Elm.Expression