Support type-annotated `struct` definitions
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 112
- Forks
- 73
- Avg merge
- 9h 41m
- Merged PRs (30d)
- 1
Description
When one defines a type based on a struct, one often wants to
constrain the types of fields. In the student languages' signature
(type) annotations, this can be achieved by providing a signature for
the struct's constructor:
(define-struct name [first last])
(: make-name (String String -> (NameOf String String)))
While this works, Name would still refer to a struct with two
fields of any type, whereas the type NameOf String String denotes
the "constrained" type with two strings as fields.
Another issue is that predicate name? would still accept any
instance of name, whereas it should only return #true for
instances with fields of the right types.
It would be convenient if one could add type constraints to the fields
of a define-struct form, or anyway having a mechanism to easily
define a struct with certain type constraints on its fields.
For example something like:
(define-struct name [(: first String) (: last String)])
Such a definition would also define the following type definitions and
constraints:
Namewould be a signature form equivalent to what is currently calledNameOf String Stringmake-namewould be given the signatureString String -> (NameOf String String)name?would return#trueiff its argument is an instance ofnamewith both fields that areStringsname-firstandname-lastwould have the signature(NameOf String String) -> String
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing student-language signature handling for define-struct and NameOf, including how make-name, the predicate, and accessors are specified. Done means agreeing on the syntax and semantics for constrained fields, then covering the constructor, predicate, and accessor behavior described in the issue with tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100