2 ms·
> For languages with nominal typing and primitives you need to box the type yes. But the compiler can elide the box for you. Haskell and Idris do this. Haskel
by dunham 2y ago
> For languages with nominal typing and primitives you need to box the type yes.
But the compiler can elide the box for you. Haskell and Idris do this.
Haskell's newtype gives a nominal wrapper around a type without (further) boxing at at runtime. It is erased at compile time. Haskell does box their primitives, but via optimization they are used unboxed in some cases (like inside the body of a function). This technique could be applied to a language that doesn't box its primitives.
Idris also does this for any type that is shaped like a newtype (one data constructor, one argument). In that case, both on the scheme and javascript backend, a newtyped Int are represented as "bare" numbers. E.g. with:
type Foo = MkFoo Int
a `MkFoo 5` value is just `5` in the generated javascript or scheme code.