Signature types

Hello!

I'm playing around with the newish Signatures feature on some very simple code and am not sure if this isn't expected to work yet (I read it's experimental in the previous patch) or I'm doing something wrong:

(require 2htdp/image)

(: image-area (Image -> Number))

(define (image-area i) 0) ; stub

The Interactions window shows this error:

Image: this variable is not defined

I have also tried subbing "Rectangle" or "image" for Image with the same error. I have successfully used this syntax with, for example, a Number -> Number function.

Any insight?

Thanks!

2 Likes
#lang htdp/isl

;; import, with signature 
(require 2htdp/image)
(define Image (signature (predicate image?)))

;; define function 
(: f (Image -> Number))
(define f (λ (i) 0))

;; experiment 
(f empty-image)
(f 2)

— It turns out that you need to create signatures from properties — which we didn’t do for the image libs when we shifted signatures to the *SL languages.
— Since BSL and BSL+ do not come with higher-order functions, the above won’t work in those languages for now. Time permitting we will figure out a work-around for 8.11 or up.

4 Likes

Thank you so much for taking the time to help! That worked perfectly as a workaround :).