Hi,

I am trying to write an APL compiler (a typed J implementation) with a 
typed racket backend. APLs have first-class functions that apply to both 
scalars and arrays, so there are 2 cases for functions of 2 arguments:

   - the *array -- array* case
   - the *scalar -- scalar* case

*Scalar -- array* and *array -- scalar* cases get their scalar argument 
lifted to arrays, and are therefore equivalent to the *array -- array* case.
Now, with an interpreter if I assign a function to an identifier, it can 
use just textual replacement to evaluate the function glyph in the runtime 
context (that's the way J does it). For example:

id =: +  ;;assign the 'add' function to 'id'

1 id 1       ;;evaluate to '2' using the scalar context on replacement with 
'+'

1 1 id 1 1    ;;evaluates to '2 2' using the array context on replacement 
with '+'


But at compile-time I can't use that trick, can I? So I end up with 
something like:
#lang typed/racket

(define id (case-lambda
             [([x : One] [y : One]) (+ y)]
             [([x : (Immutable-Vectorof One)] [y : (Immutable-Vectorof One
)]) (for/vector ([i x] [j y]) (+ i j))]))

(id 1 1)
(id #(1 1) #(1 1))

Which fails although the case-lambda is actually legal typed racket 
<https://github.com/racket/typed-racket/issues/517>, because the second 
clause is considered dead code and one cannot dispatch on type.
In my (hobbyist) understanding, the solution seems to require multiple 
dispatch? Or is there another way to do that in typed racket?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/63e5ec59-23f1-4fc7-8045-beb32409bbca%40googlegroups.com.

Reply via email to