User loginNavigation |
archivesHM-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 :) Absence
My father passed away Thursday night.
I will be away for at least a week. Please keep LtU for me while I am away. |
Browse archivesActive forum topics |
Recent comments
22 weeks 19 hours ago
22 weeks 22 hours ago
22 weeks 22 hours ago
44 weeks 2 days ago
48 weeks 4 days ago
50 weeks 1 day ago
50 weeks 1 day ago
1 year 5 days ago
1 year 5 weeks ago
1 year 5 weeks ago