Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jakab922/72d3b410a0d595b5acee to your computer and use it in GitHub Desktop.
Save jakab922/72d3b410a0d595b5acee to your computer and use it in GitHub Desktop.
{-# LANGUAGE ViewPatterns #-}
import qualified Data.Sequence as S
import System.Environment
import Control.Monad
data List a = Nil | Cons a (List a)
mylast :: S.Seq a -> Maybe a
mylast (S.viewr -> xs S.:> x) = Just x
mylast (S.viewr -> S.EmptyR) = Nothing
main = do
x <- liftM (read. head) getArgs :: IO Int
putStrLn . show $ mylast $ S.fromList [1..x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment