Re:Linear types are merged in GHC
by waltpad on Wednesday June 24, 2020 @07:48AM
(#23626781)
Well, if copies may be borrowed, as it is the case in Rust, I suppose that a type-linear function, as I called it, doesn't have to be computationally linear. The `mult` example we discussed could not be applied twice to the same value, unless it is declared as borrowing its parameters from the caller.
Elaborating on this, with a function signature like the following:
Re:Linear types are merged in GHC
by goldenkey on Thursday June 25, 2020 @04:08AM
(#23638077)
I see what you mean with the copying. I just thought based on OPs comments there would have been a strong correspondence between lambda calculus numbers (Church encoding) and the operations on them, and actual type-linear functions.
Elaborating on this, with a function signature like the following:
arguments x and y cannot point to the same value, because a value cannot be moved twice. A call like will generate an error.Conversely, with the following signature:
the call: will typecheck, because values are passed by reference.Now, nothing prevents one to implement the function square, based on the second version of mult:
which is type-linear on its parameter x, but computationally is not linear.Clearly your original question was spot on.