Skip to content

Better Typing

Latest
Compare
Choose a tag to compare
@arendsee arendsee released this 10 May 11:45
· 82 commits to master since this release

The main changes since the 0.43.0 release are the addition of typeclasses, basic value checking, and explicit function type parameters.

Typeclasses cannot yet be used as explicit constraints in function signatures, so their value in modeling data is limited. But at least we can now have one add function name for both integers and doubles. Also, packing and unpacking has been re-implemented using a new Packable type class. This means we no longer need the special pack and unpack descriptors in signatures.

Value checking is important since morloc can define multiple definitions for one term. For example, it is legal to write:

x = 1
x = 2

This would not redefine x, as is done in many languages, but would rather associate both values with the variable name and attempt to disambiguate them later (which in the past implementation would have arbitrarily picked the last one). Now I have a very rudimentary value checker that will check for contradictions between primitives. It cannot descend past a source function call. In the future, I will need to extend the value checker to compare different sourced functions. This will likely have an LLM solution.

Explicit function parameters are now added to function signatures to provide an order for the generic type variables. For example:

snd a b :: (a, b) -> b

This deviates from Haskell syntax, but clarifies the relationship between the morloc type signature and type signatures in other languages, such as the C++ prototype:

template <class A, class, B>
B snd(tuple<A,B>);

This also allows us to conveniently refer to functions as parameterized types, e.g.: snd Int Bool. Possibly such type functions could be used in signatures as well. I will explore this later.