Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-syntax-type-infer
add types to elm-syntax
https://github.com/lue-bird/elm-syntax-type-infer
elm elm-syntax type-inference
Last synced: about 1 month ago
JSON representation
add types to elm-syntax
- Host: GitHub
- URL: https://github.com/lue-bird/elm-syntax-type-infer
- Owner: lue-bird
- License: mit
- Created: 2024-11-24T17:39:07.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-11-24T18:23:55.000Z (about 1 month ago)
- Last Synced: 2024-11-24T18:28:03.344Z (about 1 month ago)
- Topics: elm, elm-syntax, type-inference
- Language: Elm
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
Add type information to the nodes
of an [elm-syntax](https://dark.elm.dmy.fr/packages/stil4m/elm-syntax/latest/) tree.```elm
import Elm.Syntax.Node
import Elm.Syntax.Expression
import ElmSyntaxTypeInfer{ declaration =
Elm.Syntax.Node.empty
{ expression =
Elm.Syntax.Node.empty
(Elm.Syntax.Expression.ListExpr
[ Elm.Syntax.Node.empty
(Elm.Syntax.Expression.Integer 1)
]
)
, name = Elm.Syntax.Node.empty "majorVersions"
, arguments = []
}
, signature = Nothing
, documentation = Nothing
}
|> ElmSyntaxTypeInfer.declarationExpression
{ importedTypes = ElmSyntaxTypeInfer.elmCoreTypes
, moduleOriginLookup = exampleModuleOriginLookup
, otherModuleDeclaredTypes =
[]
|> ElmSyntaxTypeInfer.moduleDeclarationsToTypes
exampleModuleOriginLookup
}
|> Result.map
(\typedDeclaration ->
typedDeclaration.declaration
|> Elm.Syntax.Node.value
|> .expression
|> .type_
)
-->
Ok
(ElmSyntaxTypeInfer.TypeConstruct
{ moduleOrigin = [ "List" ]
, name = "List"
, arguments =
[ ElmSyntaxTypeInfer.TypeNumberVariable
( [ "0", "implementation" ], "number" )
]
}
)exampleModuleOriginLookup : ElmSyntaxTypeInfer.ModuleOriginLookup
exampleModuleOriginLookup =
[]
|> ElmSyntaxTypeInfer.importsToModuleOriginLookup
ElmSyntaxTypeInfer.elmCoreTypes
```## TODO
- finish current implementation (TODO comments)
- is unification between in and output types always the same? Especially with regards to type variable constriaints
- are variable constraints upheld in all places (equivalence for example?)
- (mutually) recursive type aliases can run into an infinite loop
- mutually recursive types (e.g. substituting `a -> { x : b }` and `b -> { x : a }`) can run into an infinite loop### performance problems?
Right now, this can't handle medium to large files at an acceptable speed.