4 ms·
You can avoid the error of Data.List.last by 'inlining' it (just like you could in your first example) last :: NonEmpty a -> a last (NonEmpty (a, [])) =
by ImprobableTruth 6y ago
You can avoid the error of Data.List.last by 'inlining' it (just like you could in your first example)
last :: NonEmpty a -> a
last (NonEmpty (a, [])) = a
last (NonEmpty (a, x:[])) = x
last (NonEmpty (a, x:xs)) = last (NonEmpty (a, xs))
- runeks 6y agoI see your point. But I’d argue that you avoid it in both cases, since without inlining the error-call is unreachable anyway.