Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

You can write a lisp that uses static typing. The book "The Little Typer" develops one such language as (I believe) a dialect of Scheme. Of course, that's just a toy language (and it doesn't have type inference, for example, but as far as I'm aware that's a hard problem when you add dependent types), but it shows it can be done.


sort by: page size:

Interesting, I haven't seen a lot of Lisps with static type inference. The language seem very interesting, especially the multi-threading.

My dream programming language is actually a Lisp with static-by-default typing that was powerful and useful. If you end up implementing something, PLEASE post it on HN or let me know, I'd love to check it out. :)

This is how I know about Typed Racket despite not being that keen on Scheme dialects (other than call/cc), I was very excited to see how compile-time typing could work in a Lisp/Scheme.


Lisp isn't any one thing, it's a language family. One could create a Lisp that is statically typed.

Sadly, statically typed Lisp is a contradiction in terms. It would be in the same category as dynamically typed Haskell.

But the experiment shows nicely how little you need to bootstrap something lispy.


Yeah, I haven’t used lisp enough, but I want to believe that there is something inherent in its simplicity that makes it categorically different from all of the other dynamically types languages I’ve tried which all would benefit from static types.

I mean Lisp. But It's pretty debatable whether Lisps are functional languages. Imo, static typing is a requirement, at least culturally.

I think a more helpful question would be "in what instances do I need syntax?". Could you build a type-system like Haskell has for LISP? Would it be usable?

In terms of syntax, I think there's a divide between the needs of static type-systems, versus dynamic ones. LISP is at its core a dynamic language. It makes sense to treat code as being data that can be manipulated. Getting rid of all that syntax gives you great power in terms of what you can do. And personally I find Clojure code to be much saner than code written in Ruby or Python, but that's another discussion.

However, the other side of the coin are Haskell or Miranda (its predecessor) or languages in the ML family or Scala. These languages go to great length to achieve much of LISP's expressiveness, while ensuring a great amount of static type-enforcement. Haskell is especially notable because Haskell is lazy and has many goodies, such as type-classes or rank-2 types. People say that when a piece of Haskell code successfully compiles it is usually correct. LISP can't do this, even though there have been experiments with pluggable type-systems.

For an excellent rant on the choice of Scheme for SICP (and not Miranda, Haskell's predecessor), checkout: http://www.cs.kent.ac.uk/people/staff/dat/miranda/wadler87.p...

So IMHO, syntax helps if you want static type-safety, because the language and the type-system exposed need to be expressive. Whether static type-safety is useful or not, it's a matter of debate, being highly dependent on the problem domain. One could argue that static type-safety is very useful if the shape of the data you're manipulating is well defined and doesn't change much, otherwise you're better off with a dynamic language, but that's another discussion.


And Common Lisp actually allows adding type declarations[1], which can make code much more performant!

Also, if you really, really want types, as in Haskell-like types... there's Coalton[2], a language that's embedded in Common Lisp (CL is that powerful it allows things like this) with a ML type system and more "modern" idioms for people used to functional programming.

[1] https://lispcookbook.github.io/cl-cookbook/type.html

[2] https://coalton-lang.github.io/


Common Lisp was on the right track with gradual typing and decent inference, which makes a nice compromise compared to jumping static hoops to wrap the problem around a more rigid language.

The type declaration syntax definitely could use some love, I think it's a shame a more convenient syntax was never standardized. And sum types etc would be nice of course. It's all perfectly possible.


Lisp also has run-time type checking. In contrary to statically compiled languages, lisp doesn't throw away it's types at run-time, and is always type-safe.

You might like Coalton, which is statically typed, functional language embedded within Common Lisp. However, it hasn't reached version 1.0 yet.

https://github.com/coalton-lang/coalton


LISPS are the only languages where I feel like dynamic typing works well.

Lisp has hard to read syntax and no static type system, so not really something to imitate.

Please reconsider your assumptions. PG has written two Lisp books in the nineties, one of them containing a Prolog interpreter. In fact, many Lisp programs utilize some form of logic programming. With regards to "strong static typing", types are but one way to think about things. Since Lisp affords powerful ways to shape the language, there is a culture of implementing and thinking about various paradigms, typing included. For example, the first Haskell implementation was written in Lisp, and there are other explorations of that particular paradigm. All programmers are blub programmers to some extent, but Lisp has the tools and the culture to fight it.

Is there any statically-typed FP language with Lisp's parenthesized syntax?

Common Lisp, at least, is also (dynamically) typed.

Lisp and Scheme are great. They would be my favorite programming languages, if they had a statically typed, Hindley-Milner type system.

As they stand, they are great learning tools, but I would never build something serious with them. Let alone questions about parallelism, concurrency, available libraries, development tools, etc.

Any suggestions are welcome.


Common Lisp has a type system, if I understood your meaning right.

Scheme has a Lispy syntax (good or bad depending on where you're standing, but probably not neutral) and doesn't have static type inference, which is the whole point of the article. Haskell is just enormously complex for anyone who doesn't have a very strong background in maths and category theory. Seriously, it's an amazingly cool language, but unless you can look at ST and not feel a little confused at first, you won't be able to shake the feeling that Haskell is smarter than you are.

OCaml is a reasonable middle path. It has a lot in common with Haskell (H-M typing, ML syntax, pattern matching) and is largely pure, but doesn't absolutely force purity on a language level the same way Haskell does. Strictness is the default, with laziness as an option, so there are no surprising space leaks. IO is performed with IO functions, not with some bizarre monad that is the description of an action that would be performed.

next

Legal | privacy