Project Inquiry

Implement Prelude.product

Challenge
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude hiding (product)

main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"

test :: Bool
test = foldl (&&) True [ product [] == 1
                       , product [0.5] == 0.5
                       , product [1, 2] == 2
                       , product [2, 3, 4] == 24
                       , product [1.0, 1.5, 2.0, 2.5] == 7.5
                       ]

-- TODO
product :: (Num a) => [a] -> a
product = undefined
Solution
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude hiding (product)

main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"

test :: Bool
test = foldl (&&) True [ product [] == 1
                       , product [0.5] == 0.5
                       , product [1, 2] == 2
                       , product [2, 3, 4] == 24
                       , product [1.0, 1.5, 2.0, 2.5] == 7.5
                       ]

-- DONE
product :: (Num a) => [a] -> a
product []     = 1
product (x:xs) = x * product xs