user782220
user782220

Reputation: 11187

Imperative languages with static, structural typing and global type inference

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.

Upvotes: 4

Views: 1047

Answers (3)

nawfal
nawfal

Reputation: 73163

OCaml is the only one I know which can be imperative/object-oriented that is statically typed, garbage collected and supports global type inference and structural typing, though it is essentially a functional language.

Scala isn't a functional language like OCaml but an imperative/object-oriented language that supports structural typing, but does not have the kind of type inference you're looking for. It still supports functional constructs, though.

If by "non-functional" you mean a language that doesn't support functional programming at all, then I don't think there is one.

Upvotes: 1

asterite
asterite

Reputation: 7919

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

https://github.com/manastech/crystal

Upvotes: 0

bug
bug

Reputation: 914

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.

Upvotes: 2

Related Questions