Skip to content

Instantly share code, notes, and snippets.

@v0d1ch
Last active January 21, 2019 21:36
Show Gist options
  • Save v0d1ch/9eebe587109521238fef06fd8068f9fc to your computer and use it in GitHub Desktop.
Save v0d1ch/9eebe587109521238fef06fd8068f9fc to your computer and use it in GitHub Desktop.
CPS haskell
cpsTail :: [a] -> o -> ([a] -> o) -> o
cpsTail [] d = \f -> d
cpsTail (a:as) d = \f -> f as
cpsLoop :: (forall o. [a] -> o -> ([a] -> o) -> o) -> [a] -> [a]
cpsLoop f l = f l l id
safeTail :: [a] -> Maybe [a]
safeTail [] = Nothing
safeTail (x:xs) = Just xs
loop :: (a -> Maybe a) -> a -> a
loop f a = maybe a (loop f) (f a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment