[racket-dev] TR: Is there a type for this?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Thu Nov 29 00:34:37 EST 2012

I'm trying to give the `flvector-map' function a sensible type. A 
stubbed-out attempt follows, along with an application of it that fails 

#lang typed/racket

(require racket/flonum)

(: flvector-map
    (case-> ((Flonum -> Flonum) FlVector -> FlVector)
            ((Flonum Flonum Flonum * -> Flonum)
             FlVector FlVector FlVector * -> FlVector)))
(define flvector-map
     [(f xs)  (error 'unimplemented)]
     [(f xs ys . zss)  (error 'unimplemented)]))

(flvector-map fl+ (flvector 1.0) (flvector 2.0))

This works fine:

   (flvector-map + (flvector 1.0) (flvector 2.0))

I assume it's because `+' takes any number of arguments, but `fl+' takes 
exactly two.

I've written fully polymorphic map-like functions before, using `...', 
for which applying a binary function was no problem. (See `array-map' in 
the `math/array' docs.) The first thing I tried, then, was using `...' 
without type variables, but that doesn't work.

Is there a way to spell the type I want here?

Neil ⊥

Posted on the dev mailing list.