Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xarvh committed Sep 23, 2021
1 parent 9bbc8fa commit c3a33b7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/Compiler/TypeInference.elm
Expand Up @@ -929,6 +929,8 @@ bindTypeVariableTo inferredType ( replacedName, replacedType ) =
return inferredType


{-| TODO rename to something else?
-}
typeVarsFromType : Type -> Set Name
typeVarsFromType ty =
case ty of
Expand Down
39 changes: 23 additions & 16 deletions src/Compiler/TypeInference_Test.elm
Expand Up @@ -93,12 +93,19 @@ typeRecord { extensible, attrs } =
--


testDefs : Dict String Type
testDefs =
Dict.empty
|> Dict.insert "Test.add" (function tyNumber (function tyNumber tyNumber))
|> Dict.insert "Test.reset" (typeFunction { from = tyNumber, fromIsMutable = True, to = tyNone })


infer : String -> String -> Result String { forall : Set String, type_ : Type, mutable : Bool }
infer name code =
code
|> TH.stringToCanonicalModuleWithPos
|> Result.map (Dict.union Prelude.prelude >> TI.allDefsToEnvAndValues)
|> Result.andThen (\( env, values ) -> TI.fromAllValueDefs env values)
|> Result.andThen (\( env, values ) -> TI.fromAllValueDefs (addTestDefs env) values)
|> TH.resErrorToString code
|> Result.andThen
(\env ->
Expand All @@ -116,22 +123,22 @@ infer name code =
)


addTestDefs : TI.Env -> TI.Env
addTestDefs env =
let
add : String -> Type -> Dict String TI.InstanceVariable -> Dict String TI.InstanceVariable
add name ty =
Dict.insert name
{ definedAt = CA.posDummy
, ty = ty
, freeTypeVariables = TI.typeVarsFromType ty
, isMutable = False
}
in
{ env | instanceVariables = Dict.foldl add env.instanceVariables testDefs }



{- TODO restore
preamble : Dict String TI.
preamble =
let
em x =
{ type_ = x
, forall = Set.empty
, mutable = False
}
in
[ ( "Test.add", em <| function tyNumber (function tyNumber tyNumber) )
, ( "Test.reset", em <| typeFunction { from = tyNumber, fromIsMutable = True, to = tyNone } )
]
|> Dict.fromList
-}
----
--- "t2" -> "a"
--
Expand Down
18 changes: 17 additions & 1 deletion src/Types/CanonicalAst.elm
Expand Up @@ -16,7 +16,23 @@ type alias AllDefs =
Dict String RootDef


{-| moduleName + start + end must be unique for every expression, because they are used to build a unique id
{-|
TODO replace with
type Pos =
R -- replaced for pretty printing
N -- native
T -- defined as test
I -- defined by inference module
P String Int Int -- actual position
This way:
* I can remove all dummies
* I can track where stuff was defined
* takes less space when logging
* Error messages can account for it and print meaningful and readable information
-}
type alias Pos =
{ n : String
Expand Down

0 comments on commit c3a33b7

Please sign in to comment.