13 Jul 2016, 02:40

Using structural types with a lot of type inference

Snipped and backdated from a previous Reddit post of mine.

As /u/x-paste was suggesting in the [Official] Object Orientation Discussion thread about ad-hoc data structures, I still think you can get the niceness and flexibility of just throwing code togeather while still having strong typing.

That or have gradual typing to avoid the messy example I wrote for the otherwise simple eval() and can just use any like in TypeScript and don’t bother with being extremely sound and specific.

Or you would still check everything at runtime but be a bit more smart about it like using guards in Elixir (which runs on Erlang):

http://blog.johanwarlander.com/2015/07/19/on-elixir-and-static-typing

Either way, I’ve thrown together some general ideas and wanted to see what you guys think. I’m questioning how far you really want to be able to take static typing with type inference. I know from the poll a sizeable amount of people were looking for something functional along with OO.

Dealing with Nominal and Structural Typing

I was thinking about a way to “soundly” deal with having a type system where you could have both nominal and structural typing and be able to use each where appropriate. And likewise, wrote an example of how this would work in some fake syntax:

https://gist.github.com/jaxrtech/591555b239a97844183ba48da8d82339

Structural Type Inference

I when a bit crazy with how powerful the type system can be and what is offered for free with type inference alone.

I wanted to see if it was possible to get away with inferring the type of something you probably could write in JavaScript or a dynamic language where you’re just passing anonymous data structures everywhere.

https://gist.github.com/jaxrtech/18c96a4a1f0a4da50152e54982ef0987