5 ms·
You can catch the low hanging fruit, sure. But that ends up being pretty useless at scale, because your "checks" can't be relied upon. Or, worse, the programmer
by lmm 3y ago
You can catch the low hanging fruit, sure. But that ends up being pretty useless at scale, because your "checks" can't be relied upon. Or, worse, the programmer ends up having to understand the rules of your type system without having any way to probe or express the types of parts of their program, since your language is pretending that it doesn't have a type system.
- quaunaut 3y agoThat's only if you don't design your language to be easily inferred. While I don't know the case for SBCL, a language like Elm has very heavy type inference that you can rely on better than most type systems.
- lmm 3y ago> While I don't know the case for SBCL, a language like Elm has very heavy type inference that you can rely on better than most type systems. Bullshit. Either it's a sound type system (perhaps with some escape hatches) - in which case why would you ever not expose it as a real static type system - or it's not and you can't rely on it. (There is no contradiction between having good inference and having a real static type system; e.g. if you're using Hindley-Milner then you have "perfect" type inference where you could remove all the type annotations from your program and it will still be correctly typed. But it's still very useful to have a syntax for annotating expressions with their types!)
- User23 3y agoCommon Lisp is strongly typed, it's just that types follow values rather than bindings. This presents some code generation challenges, but it will warn on correctness just fine. And of course if you really want an ML style BDSM type system in Common Lisp there's Coalton[1]. [1] https://github.com/coalton-lang/coalton https://github.com/coalton-lang/coalton
- lmm 3y ago> Common Lisp is strongly typed, it's just that types follow values rather than bindings. Then they're not types. Types go on terms, i.e. expressions, not on values. > This presents some code generation challenges, but it will warn on correctness just fine. Warn on correctness it may, but it's simply impossible for a setup like that to reliably error on incorrectness at compile time; a Turing-complete language like Common Lisp cannot determine any nontrivial property of expressions (in a way that works in all cases) without evaluating them. If your types go with your values then you can't check your types without evaluating your values, at which point compile time is long gone.
- fulafel 3y agoThey have been called types (and type errors, etc) for ages in dynamic languages, it's estabilished terminology.
- kazinator 3y ago> can't be relied upon Oh? Which ones? I believe I can fix that, but I can't make a move without a repro test case.
- lmm 3y agoUnfortunately the repro test cases tend to be urgent production issues. If the language was able to reliably check types, surely they would express that as an actual language feature. If the language creators don't trust their type system enough to call it a type system (and regard any uncaught error as a bug) then why should any mere user do so?
- JonChesterfield 3y agoThe lisp type systems are usually completely solid at runtime - you get errors on misuse of values, not data corruption - but the language can express constructs which are not checkable before execution, as it does not yet know whether the data it is operating on will hit type errors. The soundness question is different to the checking ahead of time question but the two are usually conflated under the name "type system".
- lmm 3y ago> The lisp type systems are usually completely solid at runtime - you get errors on misuse of values, not data corruption That's memory safety, a valuable property but nothing to do with types. If you have a sound type system then you can use that as part of your language's memory safety strategy, but that's not the only way to accomplish that. > The soundness question is different to the checking ahead of time question but the two are usually conflated under the name "type system". Misusing "type system" to talk about something that checks some runtime property of values is sadly common, but hopefully HN can rise about such muddled thinking.
- JonChesterfield 3y agoWe're using different definitions for "type". Which explains the above discussion but otherwise doesn't really get us anywhere. I'd guess your "type system" is a syntactic property of a language with strong termination properties, but you might have something else in mind. The runtime property of values being checked by the "type system" is the "type" of the value. Something like "you're adding a number to a list, error". Where 'a number' means 'is an element of the set of numbers', possibly defined implicitly by a predicate or possibly explicitly by an enumeration of elements of that set. When the error is reported (e.g. 'compile time' for some phase separation thing) is one property, which errors are detected is a different one. You could define "type" as compile time detection of syntactic errors, with some hand waving around what errors are, but that's not the only useful definition. For concrete examples, lisp and python have similar type systems, and forth and assembly have similar type systems, but python's one isn't very similar to assembly. SML is a different thing again. They all have constraints on values that can occur in various contexts.
- mepian 3y agoCommon Lisp certainly isn't "pretending that it doesn't have a type system", this is the chapter about it in the language's specification: http://www.lispworks.com/documentation/HyperSpec/Body/04_.htm http://www.lispworks.com/documentation/HyperSpec/Body/04_.ht...
- lmm 3y agoThat seems to describe something rather different from a type system. A type system is something that associates "types" with terms in your language, i.e. expressions have types. That's writing about some system for associating sets (not types) with values, which is a thing that you can do, but it's never going to be an adequate way of doing compile time checks; to get reliable compile time checks you end up having to implement an actual type system, and if you pretend you only have a sets-associated-with-values system then that will go badly.
- tmtvl 3y agoHang on, so "integer", "string", and "(function (integer) string)" aren't types? Could you maybe explain what a type is? Because I'm completely lost in this discussion.
- lmm 3y ago> Hang on, so "integer", "string", and "(function (integer) string)" aren't types? Could you maybe explain what a type is? Because I'm completely lost in this discussion. It's not about what the types themselves are, it's about how they relate to the rest of the program. A type is something associated with terms (roughly, expressions) in a language - you have to have rules for assigning types to every term, or to put it another way you have to exclude terms that you can't type from your language. So saying 2 is of type integer and + is of type integer -> integer -> integer is a start, but for those to be types you need to be able to say that (2 + 2) is of type integer, not just that 4 is of type integer once you've evaluated it.
- kazinator 3y ago