In idris, there's a universe called UniqueType
the values of the types in which can only be used once. As far as I know, it can be used to write high-performance code.
But the fact that a value can only be used once is usually too limited, so there's a way to borrow a value instead of consuming it:
data Borrowed : UniqueType -> BorrowedType where ...
The Borrowed
data type is defined as above in Idris. Why doesn't it simply return Type
but introduce another universe of types (BorrowedType
)?
As the documentation explains, there are restriction on
BorrowedType
-typedBorrowed
values:This restriction (and
lend
's leniency) is implemented by special typing rules in the typechecker. Those rules need something to apply to, which is whyBorrowedType
has to be a separate kind than regularType
(for which there aren't speciallend
/Read
typing rules).