How do we list an unknown type?

4 views
Skip to first unread message

Justin York

unread,
Apr 7, 2011, 6:40:42 PM4/7/11
to byu-cs-330-winter-2011
When generating constraints for the written assignment, how do we show that a function has an unknown return type?

Dan Burton

unread,
Apr 7, 2011, 7:04:51 PM4/7/11
to byu-cs-330-...@googlegroups.com, Justin York
The return type of a function is not entirely "unknown", rather, it's constrained to be the same as the type of its body.

Dan Burton
801-513-1596

Justin York

unread,
Apr 7, 2011, 7:07:31 PM4/7/11
to Dan Burton, byu-cs-330-...@googlegroups.com
I should have specified that the return type of first is unknown because a list can contain anything.

Bryan Morse

unread,
Apr 7, 2011, 7:18:58 PM4/7/11
to byu-cs-330-...@googlegroups.com
For type inference, it's not so much that a function's return type is unknown -- rather, think of it as not known YET. The function's type signature should initially be stated in terms of type variables, and the relevant constraints should be generated. During the unification step, the type variables should then be determined. If the function's type signature is still in terms of undetermined type variables, it's polymorphic.

For "built-in" polymorphic operators, they too have specific type signatures. It's just that these may be in terms of type variables. Specifically, the type signature for first is list(alpha) -> alpha. That's not the same as unknown. The type variable alpha will be figured out from how it's used. Lists in type inference systems are homogenous, so they can't quite contain anything.

Reply all
Reply to author
Forward
0 new messages