4 ms·
I had to double-take because CL also has a THE also for declaring types, but it's a bit different; THE declares the type of an expression, not a variable (there
by aidenn0 5y ago
I had to double-take because CL also has a THE also for declaring types, but it's a bit different; THE declares the type of an expression, not a variable (there is a separate type declaration for variables).
so e.g. (the fixnum (+ x 1)) would assert that (+ x 1) produces a fixnum.
- timdeve 5y agoThat is also the case in Carp, x being an expression here.
- aidenn0 5y agoAh, okay. So is there a way to declare that a variable will always be of a given type in Carp?
- timdeve 5y agoCarp is statically-typed with type inference so writing (the Int x) would be enough for the compiler to forbid any usage of x as another type. Writing (Int.+ x 1) would accomplish the same as Int.+ only accepts Int. You can also annotate function with a type signature. (sig add (Fn [Int Int] Int)) (defn add [x y] (+ x y)) Is the same as: (defn add [x y] (the Int (+ (the Int x) (the Int y))))