Re:Dependent Haskell Is the Future (2018)
by lonelappde on Friday August 16, 2019 @07:38AM
(#20714121)
Can a dependently typed list be used in the common case where the length of the list is not known at compile time?
[ Parent
| on HN ]
Re:Dependent Haskell Is the Future (2018)
by Legogris on Friday August 16, 2019 @08:08AM
(#20714287)
Yes. Just like with generics, you can parametrize them, for example in Idris you have the type `Vect n a`, being a list of type `a` with length `n`. An append function could look like this:
app : Vect n a -> Vect m a -> Vect (n + m) a
app Nil ys = ys
app (x :: xs) ys = x :: app xs ys
Source: https://www.idris-lang.org/example/
Re:Dependent Haskell Is the Future (2018)
by andreabedini on Friday August 16, 2019 @08:02AM
(#20714248)
Yes, that’s the whole point of dependent types: types can depend on (runtime) values.
Re:Dependent Haskell Is the Future (2018)
by whateveracct on Friday August 16, 2019 @11:56AM
(#20716444)
Yep - we can even do this today in Haskell without -XDependentTypes :) using things like singletons