Skip to content

Instantly share code, notes, and snippets.

@heuristicfencepost
Created August 3, 2011 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heuristicfencepost/1121816 to your computer and use it in GitHub Desktop.
Save heuristicfencepost/1121816 to your computer and use it in GitHub Desktop.
Implementations of "tails" function in Data.List as well as a vaguely related function
antitails x = reverse (foldr f1 [] x) ++ [""]
where f1 newchar acc = [[newchar]] ++ (map (newchar:) acc)
mytailsl x = (foldl f1 [] x) ++ [""]
where f1 acc newchar = (map (f2 newchar) acc) ++ [[newchar]]
where f2 currchar currstr = reverse (currchar : (reverse currstr))
mytailsr x = (foldr f1 [] x) ++ [""]
where f1 newchar [] = [[newchar]]
f1 newchar acc = [newchar:(head acc)] ++ acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment