Take the 2-minute tour ×

I know of languages like Haskell being statically typed and having type inference. But are there non-functional languages that have global type inference, the equivalent of something like C with type inference and structural typing.

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

OCaml is the only one which I can know of as an imperative, object oriented language that is statically typed, garbage collected and supports type inference and structural typing, though it supports functional constructs as well.

Otherwise there is C# which is a clean/elegant modern high level language, which is all what OCaml is as far programming paradigms go, but doesn't support structural typing. Scala on the other hand do have structural typing but may not have the kind of type inference you're looking for.

If by "non-functional" you mean a language that doesn't support functional programming at all, then I don't think there is one. Java is close, but then again no structural typing.

share|improve this answer
OCaml - an imperative language? That's a minority view, to say the least :D –  Alexei Averchenko Feb 24 '13 at 19:11
Well, as a langauge that supports both paradigms I think it counts for the sake of the question. –  bug Apr 4 '13 at 22:45
add comment

OCaml isn't the only contender anymore. A number of structurally-typed imperative languages have appeared in recent years:

  • F# is, like OCaml, a multiparadigm language that supports complex pattern matching and both imperative and functional programming. Being an OCaml derivative, the two languages are in fact so similar that barring minor feature differences they are practically source-compatible. The main [dis?]advantage is that it runs on .NET.
  • Go is the lovechild of the original Unix / Plan 9 / Inferno team since their induction into Google, based on their decades of work on the compilers for those systems. Go supports structural polymorphism in the sense that object composition is its primary sub-typing mechanic, and that method interfaces do not need to be explicitly implemented.
  • Haxe is an ActionScript derivative made to compile to an impressive variety of platforms including C++ (!). It supports fully structural types and enums (equvalent to OCaml unions) alongside C#-style object heirarchies, and boasts a sophisticated macro system.
share|improve this answer
I really can't overstate how impressed I am with the Haxe project. There's even talk of adding features such as Haskell-equivalent type classes and kinds...in fact, it's already possible to implement monads &c via macros. –  bug Apr 4 '13 at 22:52
oh I missed F#. –  nawfal Apr 6 '13 at 7:54
add comment

There's also Crystal, but it's in pre-alpha stage:


share|improve this answer
add comment

Your Answer


