User loginNavigation |
HM-style type inference with non-unique selectors?
I figure this is the best place to squeeze my question in, so here goes.
A selector is either data constructor or a record field. In HM-style languages those are largely required to have unique names across entire program. Is there any way to lift this requirement and still have (partial) type inference? The hypothesis here is that unresolvable name clashes should be rare. When they do occur, the programmer should give an explicit type annotation. Consider this: data D1 = Foo Int | Bar Double data D2 = Foo | Baz -- name clash, but not fatal yet f1 (Foo x) = x f1 (Bar y) = round y f2 Foo = "Foo" f2 Baz = "Baz" -- The inference algorithm should be able to figure out the type for f1 and f2 -- f1 :: D1 -> Int -- f2 :: D2 -> [Char] f3 (Foo x) = x f3 _ = 42 f4 Foo = "Foo" f4 _ = "Error" -- Still should be possible to figure out types for f3 and f4, because -- Foo in D1 and Foo in D2 have different arities -- f3 :: D1 -> Int -- f4 :: D2 -> [Char] f5 = Foo -- ambiguity: Int->D1 or D2? -- the compiler should signal an errorIs there an inference algorithm that does just that? If such questions are inappropriate for this forum, please feel free to delete my account and ban my IP :) By ihamsa at 2004-12-18 15:11 | LtU Forum | previous forum topic | next forum topic | other blogs | 6070 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago