Why are sizes signed in the Futhark programming language?
futhark-lang.org·4h·
Discuss: Hacker News
Flag this post

Posted on March 20, 2023

In Futhark, array sizes have type i64 - the type of signed 64-bit integers. This is observable whenever we use a size parameter as a term-level variable:

def length [n] 't (xs: [n]t) : i64 = n

Since Futhark arrays cannot have a negative size, one might reasonably ask why sizes are not of type u64 - the type of unsigned 64-bit integers - which specifically cannot represent negative numbers. This question often comes from functional programmers, who are used to making invalid states unrepresentable through types. Perhaps they have even encountered size-indexed vectors such as Data.Vect in Idris, where the type system …

Similar Posts

Loading similar posts...