wtypec - Question 1

8 views
Skip to first unread message

Jay McCarthy

unread,
Nov 23, 2011, 3:21:17 PM11/23/11
to BYU CS 330 Fall 2011
Many people answered this question wrong because they do not know what the word "variant" means.

A list is a data type with two variants: empty and cons.

The assignment says this: "Consider our typing rules for datatypes. A datatype declaration defines a new type (such as nlist), and each constructor (eg, cons) creates a value of that type. As a result, however, selectors (such as first) cannot statically determine whether or not they have been given the correct variant (there are two variants of lists, for instance) of the datatype, and must rely on a check from the run-time system."

We've been using "variant" like this since the very beginning when we introduced different shapes in the Racket intro and the first use of define-type in #lang plai.

Many people seemed to answer this question as if it is about having one type called "list of numbers" and another called "list of booleans". Those are not variants. Those are different types already.

Jay

--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93
Reply all
Reply to author
Forward
0 new messages