Skip to content

Instantly share code, notes, and snippets.

@tonymorris

tonymorris/lazyreverse.hs

Last active Jul 7, 2016
Embed
What would you like to do?
reversel ::
[a]
-> [a]
reversel xs =
let go (_:xs) ~(y:ys) =
y : go xs ys
go [] ~[] =
[]
in go xs (reverse xs)
r ::
Int
-> [a]
-> Int
r n =
length . take n . reversel . reversel
-- > r 1223 ['a'..]
-- 1223
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment