Going through learn you some haskell I’m curious if there are mechanisms in haskell that would allow something like last (reverse [1..])
to return the expected value?
I tried a number of variations similar to
> foldl1 (\acc _ -> acc) (reverse [1..])
^CInterrupted
but to no avail.
I know
> foldr1 (\acc _ -> acc) (scanl1 (\acc _ -> acc) [1..])
1
and
> :type [1..]
[1..] :: (Num a, Enum a) => [a]
so is there some kind of reversed enumerator I could call last on e.g. [..1]
where:
> :type [..1]
[..1] :: (Enum a, Num a) => [a]
> last [..1]
1
??