On Thu, Feb 16, 2012 at 7:50 PM, Dominic Mulligan
<dominic.p...@googlemail.com> wrote:
> Hi,
>
> I'm trying to typecheck the following function on Vects (an analogue
> of the existing function on lists in the Prelude):
>
> last : Vect a (S n) -> a
> last (x::xs) =
> case xs of
> [] => x
> y::ys => last (y::ys)
>
this:
last : Vect a (S n) -> a
last {n=S k} (x::xs) =
case k of
O => x
_ => last xs
works. But I don't think it really answers your question.
Cheers,
Alexander
One way to fix this might be to use top level matching instead.
last : Vect a (S n) -> a
last (x :: []) = x
last (x :: y :: ys) = last (y :: ys)
It's probably possible to make the case construct a bit more flexible in this sort of situation. At the minute it's just not clever enough to generate the right type for the auxiliary function.
Edwin.