jcoo092
2020-6-13 08:11:32

Another Typed Racket question: I am trying to use in-fxvector, which apparently (according to the raco make error message) requires me to import unsafe-fxvector-length , and it seems that I should do so by using require/typed.

So, I have put (require/typed racket/unsafe/ops [unsafe-fxvector-length (FxVector -> Fixnum)]) at the top of the relevant file. Best as I can tell from the documentation (https://docs.racket-lang.org/ts-reference/special-forms.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._require%2Ftyped%29%29) that is the correct way to import the function. The compiler still complains however, saying > Type Checker: missing type for identifier; > consider using require/typed' to import it > identifier: unsafe-fxvector-length > from module: unsafe/ops.rkt Any suggestions on what I need to do to usein-fxvector? I assume it's just that I haven't quite for therequire/typed` declaration correct, but I can’t work out what the right thing to put is.


sorawee
2020-6-13 08:40:09

I don’t think it requires you to import unsafe-fxvector-length


sorawee
2020-6-13 08:40:15

Can I see the error message?


sorawee
2020-6-13 08:40:44

You should be able to use in-fxvector without importing anything that is in its implementation


sorawee
2020-6-13 08:44:45

Oh


sorawee
2020-6-13 08:44:53

there are bugs in Typed Racket


jcoo092
2020-6-13 08:46:27

The error message is: > raco make src/montecarlopi.rkt > src/montecarlopi.rkt:47:2: Type Checker: missing type for identifier; > consider using `require/typed’ to import it > identifier: unsafe-fxvector-length > from module: unsafe/ops.rkt > in: (for ((ts (in-fxvector threads-per-place-vec)) (is (in-fxvector iters-per-place-vec))) (montecarlopi/place is ts tx-ch)) (you can view the file in question at https://github.com/jcoo092/CML_benchmarks/blob/TypedRacket/TypedRacket/src/montecarlopi.rkt#L43)


sorawee
2020-6-13 08:59:24

Ah, I see what’s going on now


sorawee
2020-6-13 09:00:10

When in-fxvector is used in ordinary expressions, it expands to in-fxvector*, which is typed by Typed Racket


sorawee
2020-6-13 09:00:42

But when in-fxvector is used in for, it expands to a more efficient operation, which has unsafe-fxvector-length


sorawee
2020-6-13 09:00:46

and it needs to be typed


jcoo092
2020-6-13 09:05:07

:thinking_face:


sorawee
2020-6-13 09:07:44

I would ping @samth


sorawee
2020-6-13 09:08:39

sorawee
2020-6-13 09:10:45

sequence position in for is apparently a can of worms


sorawee
2020-6-13 09:11:20

(in-list 1) ; not type checked (for ([x (in-list 1)]) 2) ; type checked


jcoo092
2020-6-13 09:12:44

I can certainly believe that it would be an issue. Seems like one of those fiddly areas that at first glance looks like it would be simple, but in reality can cause all sorts of problems.



jcoo092
2020-6-13 09:25:31

Thanks for all the info! :slightly_smiling_face: I tried imitating the base-env file that you linked to (very much in a ‘cargo cult’ sort of way), but unsurprisingly Racket didn’t like that either.

I think I’ll wait a while with this one and carry on with other things I need to do. Hopefully in a while one of the Typed Racket team or someone will be able to suggest something.


dbriemann
2020-6-13 14:39:52

Yes it is my own but I thought there was some simple more dynamic way of getting that info. Thanks


dbriemann
2020-6-13 14:40:35

I guess technically I could have used any value but since my function was called is-valid? I really wanted it to return a boolean


dcmicoltacespedes
2020-6-14 01:45:53

Hi, why this code: (define (pieces-are-equal? piece1) (cond [(equal? (piece-space1 piece1)(piece-space2 piece1)) #t] [else #f] )) (define (higher-pieces piece1 piece2) (cond [(> (and(piece-space1 piece1)(piece-space2 piece1)) (and(piece-space1 piece2)(piece-space2 piece2))) #t] [else #f] ) ) (define (higher-list-pieces list) (cond [(empty? list) "no hay fichas"] [(boolean=? (pieces-are-equal? (first list)) #t) (first list)]; if only there one piece double [(boolean=? (and(pieces-are-equal? (first list))(and(higher-pieces(first list) (first(rest list)))))#t) (higher-list-pieces (cons (first list)(cddr list)))]; if the list have various doubles, returns the double higher [(boolean=? (higher-pieces (first list) (first (rest list)))#t) (higher-list-pieces (cons (first list)(cddr list)))]; if there not doubles returns the piece higher [else (higher-list-pieces (rest list))] ) ) throws me this error: first: contract violation expected: (and / c list? (not / c empty?)) given: '() and it show me this part (first (rest list)) in the fourth condition

the code work with other lists,like this, (list (make-piece 3 6)(make-piece 4 4)(make-piece 4 5)(make-piece 4 6)(make-piece 5 5)(make-piece 5 6)(make-piece 6 6))

but it don’t with this list

(higher-list-pieces (list (make-piece 2 3)(make-piece 2 4)(make-piece 2 5)(make-piece 2 6)(make-piece 3 3)(make-piece 3 4)(make-piece 3 5)))


rokitna
2020-6-14 06:51:54

That error message is saying that first should be called with a nonempty list, but it’s being called with the empty list '() instead. (There’s no way to get the first element of an empty list, since it doesn’t have one.)

Before you call (first (rest list)), try checking to make sure there are at least two elements in list so that (rest list) isn’t empty. I notice you describe one of the branches as “if only there one piece double,” so you might be intending for that branch to take care of the one-element case, but that’s not actually what it’s checking for right now.


rokitna
2020-6-14 06:53:08

The code works with a list that ends with a piece that has both its spaces equal, like your first example, because the equality of those spaces is actually what that branch is checking for.