Mine
public text v1 · immutableimport Control.Monad.Cont
import Control.Monad
fromEnd :: Int -> [a] -> Maybe a
fromEnd n l = flip runCont id (callCC $ (\cc -> fromEnd' n l cc >> return Nothing))
where
fromEnd' :: Int -> [a] -> (Maybe a -> Cont (Maybe a) ()) -> Cont (Maybe a) Int
fromEnd' n [] retCC = return n
fromEnd' n l retCC = do
n' <- fromEnd' n (tail l) retCC
when (n' == 0) $ retCC (Just $ head l)
return $ pred n'