Type checking vs type inference

1.4k views Asked by At

Can anyone explain the difference between type-checking and type-inference problem ?

I have tried to search for the difference, but I couldn't not find any compelling source that clearly explains the difference. If possible include examples also.

1

There are 1 answers

0
Sylwester On BEST ANSWER

Given the code:

(define (sum lst)
  (if (null? lst)
      0
      (+ (car lst) 
         (sum (cdr lst)))))

Is there anything you could say about what lst has to be or what the procedures return type? A compiler might do the same and it would be called type inference.

Type checking is checking of the types specified in the code or inferred. It will fail if there are inconsistencies in the code or it's not clear from inferring that it adds up.