Project Inquiry

Implement prepend function for custom collection type

Challenge
{-# 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 [ prepend 1 CNil == CCons 1 CNil
           , prepend 2 (CCons 1 CNil) == CCons 2 (CCons 1 CNil)
           ]

-- TODO: This program doesn't compile. Define the missing function(s) incl. type signatures!
Solution
{-# 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 [ prepend 1 CNil == CCons 1 CNil
           , prepend 2 (CCons 1 CNil) == CCons 2 (CCons 1 CNil)
           ]

-- DONE
prepend :: a -> C a -> C a
prepend x c = CCons x c