-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference for lists: way complicated #31
Comments
One idea would be to put a special case when an App is found, see if it's an application of a Cons onto an element, but how can we then find the next element / connect it with the previous? |
No special cases please! :) An expression like Cons x xs is (from the perspective of the type checker) just a function application, so if you can type check function applications you can type check this as well. Much like in your interpreter, you need to add Cons to the environment with its correct type. Cons is type a -> [a] -> [a], and it's polymorphic so its type would be This assumes TConstr can do applications of type constructors, like PConstr in your patterns, not just the constructors themselves. |
@JonasDuregard The thing is that in the abstract syntax, it is modelled as |
That is what I meant by them being just function applications. The case you need to think about is EConstr. It is currently wildly incorrect (type constructors are not the same as value constructors!). If your inferencer correctly infers the type of (EConstr "Cons") to |
Regarding "finding the next element", that is the job of the interpreter. The type checker has no notion of this, it traverses the expression it type checks not the values the expression would evaluate to. |
Regarding recursion, it's a bit tricky when polymorphism is involved. It seems the standard approach for
|
Lists are represented as recursive application of the constructor Cons in the abstract syntax, which makes it very hard to grasp and implement in the type inference algorithm. Input/ideas/solutions on this, or alternative representation for the AS would be very helpful.
The text was updated successfully, but these errors were encountered: