Common Lisp Static Type Checking

We could impose static type checking within #202204251732 using SBCL implementation for global variables and functions. This means that type error could be caught in compile time rather than relying on 202204251734.

For example, we could declare a function that accept two number type values and then return a number type value. This is shown as follows:

(declaim (ftype (function (number number) number) adder))
; Similar to Haskell syntax
; adder :: Int -> Int -> Int
(defun adder (n1 n2)
  (+ n1 n2))

This told the Lisp compiler to verify whether the function adder matched the declaration in the macro declaim. ftype means function type where the first parameter indicate how should the function looks like and the second parameter is the targeted function. function indicates that it is a normal function, (number number) presents that both function parameters should be in number type, and the last parameter number shows that the return type of it should be in number type.

Similar declaration could be used in defparameter with type:

(declaim (type number a))
(defparameter a 10)
#lisp #type-check #haskell