# Fixed size list signatures in htdp/isl+

**URL:** <https://racket.discourse.group/t/fixed-size-list-signatures-in-htdp-isl/2247>\
**Category:** General\
**Created:** [August 25, 2023, 12:18pm UTC](https://racket.discourse.group/t/fixed-size-list-signatures-in-htdp-isl/2247 "2023-08-25T12:18:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bremner](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@bremner](https://racket.discourse.group/u/bremner)\
**Post date:** [August 25, 2023, 12:18pm UTC](https://racket.discourse.group/t/fixed-size-list-signatures-in-htdp-isl/2247/1 "2023-08-25T12:18:25Z")

</div>

I wanted to try one of the exercises from

[6&nbsp;Functional Abstraction](https://cs.uwaterloo.ca/~plragde/flaneries/FICS/Functional_Abstraction.html)

using signatures instead of contracts, but I hit what seems to be a  
limitation of the signatures in ISL+. In particular there seems to be no  
way to express a list of a fixed number of elements, which is used in  
Exercise 26. I realize the exercise could be updated to use structs  
instead, but fixed sized lists seem like a popular idea in "beginner  
code". Does it make sense to add something like (List a b c) to  
signatures (in the style of typed/racket), or is it better to discourage  
this style in the teaching languages?

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [August 25, 2023, 1:08pm UTC](https://racket.discourse.group/t/fixed-size-list-signatures-in-htdp-isl/2247/2 "2023-08-25T13:08:18Z")

</div>

```plaintext
#lang htdp/asl

(define fixed-size? (signature (predicate (λ (x) (= (length x) 3)))))

(: f [(combined (ListOf Integer) fixed-size?) -> Natural])
(define (f x) 2)

(f '[3 2 1])

```

---

<div class="post-metadata">

**Author:** ![bremner](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@bremner](https://racket.discourse.group/u/bremner)\
**Post date:** [August 26, 2023, 12:32pm UTC](https://racket.discourse.group/t/fixed-size-list-signatures-in-htdp-isl/2247/3 "2023-08-26T12:32:57Z")

</div>

EmEf via Racket Discourse [notifications@racket.discoursemail.com](mailto:notifications@racket.discoursemail.com)  
writes:

> ```racket
> #lang htdp/asl
> 
> (define fixed-size? (signature (predicate (λ (x) (= (length x) 3)))))
> 
> (: f [(combined (ListOf Integer) fixed-size?) -> Natural])
> (define (f x) 2)
> 
> (f '[3 2 1])
> 
> ```

Thank you, that is indeed a viable approach to fixing the list  
length. Your answer also helped me realize that structs are really a  
better answer for the original exercise, since it is not just the length  
of the list but also the type of the first element and the type of the  
second element that matter. So some "match-like" specification would  
work (if it existed), but just specifying the length is not enough.

David

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [August 26, 2023, 12:57pm UTC](https://racket.discourse.group/t/fixed-size-list-signatures-in-htdp-isl/2247/4 "2023-08-26T12:57:08Z")

</div>

\*sl is designed to support principles of systematic program design that work in the absence of `match` like constructs in the languages students will encounter. Part of the goal is to develop the mental discipline to cope with absence of static checking, whether this means no type system at all — say in Python (please don’t mention it’s type hints) — or a (n HM) type (inference) system such as ML’s or Haskell’s. All of them come with gaps, meaning conditions that are (at best) checked at run time.

If the workd had only (Typed) Racket-like languages, \*sl would look very different.

Adding checked signatures is a compromise that we will explore at Northeastern this coming semester.
