Skip to content
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

Potentially untypable program #28

Open
Mathnerd314 opened this issue Jun 24, 2022 · 3 comments
Open

Potentially untypable program #28

Mathnerd314 opened this issue Jun 24, 2022 · 3 comments

Comments

@Mathnerd314
Copy link

I guess HM with infinite types can type the example I gave at CCC today, but what about this?

I = {x->x};  
K = {x->{y->x}};  
W = {x->(x x)};  
term = {z->{y ->((y (z I))(z K))}};
test = (term W);
(test {x -> {y -> (pair (x 3) (((y "a") "b") "c")) } })

This uses test at a non-lambda value so should be incompatible with the deduced HM type you gave, { {A:{A->A} -> {A->B} } -> B }, that forces everything to be a lambda.
But of course it runs fine and produces (3,"b").

@cliffclick
Copy link
Owner

cliffclick commented Jun 27, 2022 via email

@Mathnerd314
Copy link
Author

Mathnerd314 commented Jun 27, 2022

Well, what I put for "Haskell type" is actually the type I think an intersection type system would infer. Haskell only came into play because I used it to infer the type of the fully reduced form, test = λ y . y (λ x . x) (λ y . λ x . λ y . x), since I don't have a working intersection type implementation. This uses the property of "subject expansion" that holds for intersection type systems (but not for Haskell's type system or most other type system) - subject expansion means that if term M reduces to term N, and N has type T, then M also has type T.

I worked out by hand the intersection types for your examples as follows, based on my reading of this paper:

Term Type
I = {x->x} a -> a
K = {x->{y->x}} a -> b -> a
W = {x->(x x)} ((a -> b) ∩ a) -> b
term = {z->{y ->((y (z I))(z K))}} (((a -> a) -> d) ∩ ((b -> c -> b) -> e)) -> (d -> e -> f) -> f
test = (term W) (a -> a) -> (d -> c -> e -> c) -> b ) -> b
(test {x -> {y -> (pair (x 3) (((y "a") "b") "c") (Int, String)
{z->{y ->((z I) (z K))}} (((d -> d) -> e -> c) ∩ ((a -> b -> a) -> e)) -> f -> c
{z-> ((z I) (z K))} (((a -> a) -> c -> b) ∩ ((d -> e -> d) -> c)) -> b

I don't think failure of your algorithm on these examples necessarily means there's an AA bug. I've seen an argument that the semantics of these programs are confusing and that static type systems ruling them out make programs easier to understand. But it is true that these examples work in an untyped semantics, so they show that your system cannot type all successfully-running programs.

@cliffclick
Copy link
Owner

cliffclick commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants