Location of type-checker in PureScript source code

kikofernandez [4:02 AM]
Hi everyone, I was looking through the source code to see how PureScript type checks expressions. Does anyone know where does that happen?
for instance, I was looking through the TypeChecker.hs but I cannot find any match on Abs (abstractions).

kritzcreek [4:03 AM]
@kikofernandez PureScript has a bidirectional typechecker, so the typechecking is split between the infer and the check functions

kikofernandez [4:04 AM]
got it. there seems to be some infer in Types.hs

kritzcreek [4:04 AM]
I’m just looking up the modules

kikofernandez [4:04 AM]
thanks

kritzcreek [4:04 AM]
so yeah, TypeChecker/Types.hs has both infer and check
where the bulk of the implementation is in infer' and check'
typeclass constraints are solved in Entailment.hs, but because we have functional dependencies entails can reach back into infer and check
I think I’m lying, and it’s just unify that can be called from entails

kikofernandez [1 day ago]
is this so that it has better type inference?

kritzcreek [1 day ago]
You can’t support features like Rank-N-Types otherwise

kritzcreek [1 day ago]
it also yields better inference, better performance, and (potentially) better error messages

kikofernandez [11 hours ago]
Hi again,
I have been reading the compiler’s code to understand better how you do the whole type checking. I fail to understand something simple: how do you make sure that the type checking of each module already contains all the data declarations imported from other modules. Do you do multiple phases and collect this information putting into your State Environment monad?

kikofernandez [11 hours ago]
This part was not clear to me. I went as far as to look for the Make.hs, which is the one that does the type checking and gets all the modules

kikofernandez [11 hours ago]
(no hurry, I am just wondering)

kikofernandez [11 hours ago]
(thanks)

kritzcreek [10 hours ago]
So the analysis of transitive module dependencies is implemented here: https://github.com/purescript/purescript/blob/3fb37ee34df9a9327f1dbcd8642ab025d5f5c771/src/Language/PureScript/ModuleDependencies.hs

A successfully compiled module is represented as an ExternsFile, which is a format that contains all information needed to compile against the module as a dependency. The ExternsFiles of all transitive dependencies are then folded into the Environment we check a module against.

See https://github.com/purescript/purescript/blob/05744cbf3be0c5e047df685fe0e826f062f478a3/src/Language/PureScript/Externs.hs#L148
and
https://github.com/purescript/purescript/blob/a8e0911222f46411776978a13866eb097175162c/src/Language/PureScript/Make.hs#L59

kikofernandez [10 hours ago]
ok, so you end up with the transitive closure of modules. that’s the part I didn’t see

kikofernandez [10 hours ago]
thank you so much

kritzcreek [10 hours ago]
You’re welcome, don’t hesitate to ask any question you might have :slightly_smiling_face:

kikofernandez [10 hours ago]
thanks! We are trying to find a pattern for building compilers using Haskell. We created an OOP language, compiler written in Haskell, and we want to observe the differences in the implementation of compilers written using Haskell.