sydney.lambda
2019-7-17 01:59:02

Would somebody please try and explain why the result of my type-checker prints like this?: (type-of '(λ ([x int]) x) base-tenv) => (proc #0=(int) #0#) Doesn’t seem to impact the functionality of the code and I’m using a sort of pretty-printer anyway, but I’m just curious as - if I don’t understand why this is happening - it could perhaps bite me in the future. Here’s the relevant code: (struct type () #:transparent) (struct int type () #:transparent) (struct bool type () #:transparent) (struct proc type (arg-type result-type) #:transparent) (define (type-of expr tenv) (match expr [`(λ ((,id ,ty)) ,body) (type-of-procedure id ty body tenv)])) (define (type-of-procedure id ty body tenv) (let* ([arg-type (external-form->type ty)] [result-type (type-of body (extend-tenv id arg-type tenv))]) (proc arg-type result-type))) (define (external-form->type texpr) (match texpr ['int (int)] ['bool (bool)] [`(λ (,ty) ,body-ty) (proc (external-form->type ty) (external-form->type body-ty))])) (define (extend-tenv id ty tenv) (hash-set tenv id ty)) If I change type-of-procedure to: (define (type-of-procedure id ty body tenv) (let* ([arg-type (external-form->type ty)] [result-type (type-of body (extend-tenv id (external-form->type ty) tenv))]) (proc arg-type result-type))) so as to (needlessly) re-evaluate the external form of ty, it doesn’t display that way. That gives me the impression that it’s “pointing” to the same thing somehow (like a circular list made using mutable conses) but other than that I’m completely stumped. Of course, the argument type is indeed the same as the return type of the body, but I can’t figure out how they’re exactly the same thing to such a degree that they would print using graph notation. If that’s anything to do with it at all, that is. Sorry for the code dump, I’ve held off asking this for a week or so now but it’s really bugging me I’m afraid. Thanks :slightly_smiling_face:


philip.mcgrath
2019-7-17 04:09:15

Only skimmed your code, but the #0= notation is for graph structure, aka sharing, aka cycles. It meant that not only do the two fields of your strict contain equal? lists, they contain the very same list (eq?)


sydney.lambda
2019-7-17 04:26:22

Thank you :slightly_smiling_face: I guess, even though I’m struggling to trace it directly, I understand the principle of why it’s happening so I should be alright.