-- Demonstrate algebraic data types: product type
data Sequence a = S Int [a]
deriving (Eq, Show)
fromList :: [a] -> Sequence a
fromList xs = S (length xs) xs
(+++) :: Sequence a -> Sequence a -> Sequence a
S lx xs +++ S ly ys = S (lx + ly) (xs ++ ys)
len :: Sequence a -> Int
len (S lx _) = lx
main :: IO ()
main = do
print $ fromList [0..9]
print $ len (fromList ['a'..'m'] +++ fromList ['n'..'z'])