Problem 1:

> But note i can't just type (λ (rng) (apply make-character rng)) into the 
REPL,

If you're using Typed Racket, you probably want type signatures in your 
lambdas as well.
In this case, you need to specify the type of `rng` (at least):

```
(λ ([rng : (List Integer Integer)]) (apply make-character rng))
```

Problem 2:

; readline-input:8:40: Type Checker: type mismatch
;   expected: (-> Integer * Character)
;   given: (-> Integer Integer Character)
;   in: make-character

I'm not sure about this one; it looks like you are currying _apply_... 
Don't you just want `(curry make-character)`? 
Like:

```
(define blahh ((curry make-character) 10))
```

Problem 2b: understanding the complaint.
The type checker is complaining that it wants something that takes in an 
arbitrary number of integers (0 or more), but you have given it something 
that takes in exactly two integers. Your inputs need to be a superset of 
the allowable inputs, not a subset.

; readline-input:8:40: Type Checker: type mismatch
;   expected: (-> Integer * Character)
;   given: (-> Integer Integer Character)
;   in: make-character



Possibly helpful:

> the discussion in typed racket reference "1.6 - Other Type Constructors" 
left me hanging a little bit on the function types

If you haven't read the Typed Racket Guide, section 4.2 and maybe 4.3 
should be easier going than the reference.
https://docs.racket-lang.org/ts-guide/types.html#%28part._.Function_.Types%29



On Saturday, July 25, 2020 at 12:52:43 PM UTC-5, Nate Griswold wrote:
>
> Hello. I am stuck on a probably simple type problem and was wondering if 
> someone could help:
>
> I'll just give the actual functions im using:
>
> ```
> (struct Character ([bytes16 : Bytes]))
> (define substr (make-bytes 128))
> (: make-character (-> Integer Integer Character))
> (define (make-character s e)
>   (Character (subbytes substr (* 2 s) (* 2 e))))
> ```
>
> What i want is a function like:
>
> ```
> (: blah (-> (List Integer Integer) Character))
> (define blah (λ (rng) (apply make-character rng)))
> ```
>
> Which works.
>
> But note i can't just type (λ (rng) (apply make-character rng)) into the 
> REPL, because i get:
>
> ; readline-input:5:14: Type Checker: Bad arguments to function in `apply':
> ; Domain: Integer Integer
> ; Arguments:  Any
> ;   in: (apply make-character rng)
>
> I think because i need the explicit (List Integer Integer) annotation to 
> unify with (Listof Integer)
>
> Anyway, i wanted to make my code simpler so i was wondering if i could 
> curry and partially apply. So i was digging around in the reference and 
> tried:
>
> ```
> (: blah2 (-> (List Integer Integer) Character))
> (define2 blah2 ((curry (inst apply Integer Character)) make-character)
> ```
>
> But i get:
>
> ; readline-input:8:40: Type Checker: type mismatch
> ;   expected: (-> Integer * Character)
> ;   given: (-> Integer Integer Character)
> ;   in: make-character
>
> Looking at the typed racket reference and the type of apply, thought the 
> star meant i could have many integers. Actually to be honest the discussion 
> in typed racket reference "1.6 - Other Type Constructors" left me hanging a 
> little bit on the function types, I am a pretty green on working with 
> racket types and types in general. I thought this would unify but i guess i 
> am completely wrong. Does anyone know what i am doing wrong exactly or what 
> a very abbreviated form for what i want (behavior of blah) is?
>
> Sorry if this is basic i am a little lost on it as you can probably tell.
>
> Thank you
>
> Nate
>
>
>

-- 
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/083c3f2f-dfbd-4957-8b3d-690cab6d674eo%40googlegroups.com.

Reply via email to