Instead, it has two ways of doing parametric types like matrices:
1. Using the type system, as seen in e.g. nalgebra (https://docs.rs/nalgebra/latest/nalgebra/base/struct.Matrix....)
2. Using macros for codegen, as seen in almost all other linear algebra crates, e.g. ultraviolet (https://crates.io/crates/ultraviolet)
The drawback of (1) is that it's hard to understand or extend, and the type errors are insane, and put Boost to shame. The drawback of (2) is that's just a macro. Of course (1) and (2) are not interoperable.
C++ templates are really underappreciated, because they are a single mechanism that gives you both powerful generics and macro-like codegen, while being easy to adopt gradually. (E.g. you can add concepts when it gets unwieldy, but you don't have to rewrite the whole thing.)
let result: Matrix<i32, 2, 2> = matrix_a * matrix_b;
https://github.com/MayorMonty/mtrxLISP has only one type. The all mighty runtime type. It's a uni-typed language.
(deftype option (subtype)
"The type of a value that is either nil or a value of SUBTYPE."
`(or null ,subtype))
(defun* get-latest-statement ((account account))
"If any statements have been made on the ACCOUNT, returns the latest.
Otherwise returns nil."
(:returns (option statement))
(car (last (account-statements account))))
I like defstar, it's a neat package.While CL (the standard) doesn’t require compile time type checking AFAIK, certain implementations, such as SBCL (probably the most popular non-commercial implementation), does offer compile time type checking.
More on CL types, type checking, etc.: https://lispcookbook.github.io/cl-cookbook/type.html
Yes, it was called a "powerful type system".
But a type system with only one type isn't powerful, more the contrary.
https://existentialtype.wordpress.com/2011/03/19/dynamic-lan...
But the now linked page was an interesting read. At least SBCL has indeed real types. I didn't know that until now.
Compile-time type checking
You may provide type information for variables, function arguments etc via `proclaim`, `declaim` and `declare`. However, similar to the `:type` slot introduced in CLOS section, the effects of type declarations are undefined in Lisp standard and are implementation specific. So there is no guarantee that the Lisp compiler will perform compile-time type checking.
However, it is possible, and SBCL is an implementation that does thorough type checking.This exists since early 80s. The first language definition book appeared 1984: Common Lisp the Language.
One could think that it is a gradual type system. Type declarations are optional and are used for several purposes. Many implementations use type declaration and optionally type inference as input for optimizing compilers. In the 80s the first implementation to add limited forms of static type inferencing and checking was CMUCL. SBCL is a later fork of CMUCL.
The challenge is to integrate dynamic types, static types into a language which is often used interactively - including a lot of dynamic features, where programs can change at runtime or parts of the language might change during runtime. Thus the type system has its problems and hasn't been improved since the 90s... Not many implementations have adopted the type system implementation of CMUCL & SBCL.
Generally the SBCL compiler, even though it is based on 80s technology, is quite helpful when developing Lisp code.
Obviously, the expressions 1234, "foo" and '(hello world) do not have the same type.
Calling Mr. Harper a "troll" is quite a strong statement…
So languages that do this seriously—Agda, Idris, ATS—are usually somewhat Turing-incomplete in order to sidestep this and related problems of too-expressive (sound) type systems and, though it’s perfectly possible to write useful programs in them, it requires a more disciplined and restricted approach than usual, and you’re going have to spend some time proving things.
There are also languages—notably C++ and Haskell—that do this less seriously, in that their systems are capable of expressing naturals but are either unsound (allowing some programs that passed the typechecker to misbehave due to type-related problems), semidecidable (allowing the typechecker to hang on erroneous programs), too weak (not allowing you to prove equalities you need), or all of the above. On the upside, those are also the ones flexible enough that normal people can program in them (as long as they don’t try typing every length and size they see, then it becomes as painful as ever).
(Other responses have mentioned interesting type systems for dynamic languages, such as those in Racket and Common Lisp. I think those mostly fall into the “unsound” bucket above, due to runtime checks, but I don’t know much about them. Should be worth looking into as well.)
you mean that the _type systems_ of these languages are somewhat Turing-incomplete, not the languages themselves, right?
Long story short, these languages are based on the “Howard-Curry isomorphism” which says that we can view type signatures as theorems and programs with that signature proofs of that theorem.
A program which runs forever is a proof of false (you could see it as saying “after infinity time I’ll have your answer I swear”). So these languages are designed to prevent that from being possible.
Depending on what you want to achieve there are plenty of tricks and techniques to encode a divergent program in a sound dependent-type theory, but the best approach to use will depend on the problem statement.
Either is a possibility.
Agda and Idris have full dependent types, that is every value computation is allowed to be used as a type parameter, so all value computations are forced to terminate in a way apparent to the typechecker and are consequently not Turing-complete. (As a sibling comment mentions, aside from hanging your compile when run an infinite loop is an example of empty so a proof of false, thus if the compiler decides it’s uninterested in the details and trusts it to work instead of actually running it it’s actually worse.)
ATS I think has a Turing-incomplete proof language distinct from the Turing-complete program language, but I’ve never been able to get through its rather arcane documentation so I’m not sure. Frama-C or SPARK is one example where I’m certain that’s the case (the program language is C or Ada, respectively), except the proof language is “throw intermediate statements at the SAT solver and see what sticks”.
Besides the other mentions Scala 3 has type level arithmetic built in.
Quick peek:
https://gist.github.com/deanwampler/b1176dc939abc092681368c9...
You could do things like that also in Scala 2. But the code to make it work would be quite involved.