append
function for custom collection type{-# LANGUAGE NoImplicitPrelude #-}
module Main where
import Prelude
main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"
data C a = CCons a (C a) | CNil deriving (Eq)
test :: Bool
test = and [ append 1 CNil == CCons 1 CNil
, append 2 (CCons 1 CNil) == CCons 1 (CCons 2 CNil)
, append 3 (CCons 1 (CCons 2 CNil)) == CCons 1 (CCons 2 (CCons 3 CNil))
]
-- TODO: This program doesn't compile. Define the missing function(s) incl. type signatures!
{-# LANGUAGE NoImplicitPrelude #-}
module Main where
import Prelude
main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"
data C a = CCons a (C a) | CNil deriving (Eq)
test :: Bool
test = and [ append 1 CNil == CCons 1 CNil
, append 2 (CCons 1 CNil) == CCons 1 (CCons 2 CNil)
, append 3 (CCons 1 (CCons 2 CNil)) == CCons 1 (CCons 2 (CCons 3 CNil))
]
-- DONE
append :: a -> C a -> C a
append x CNil = CCons x CNil
append x (CCons a c) = CCons a (append x c)