Question: needs to be coded using Haskell module Ex06_FlowPatternMatchingSpec ( spec ) where import Test.Hspec import Test.Hspec import Test.QuickCheck import Prelude. Unicode import Data. Monoid. Unicode

needs to be coded using Haskellneeds to be coded using Haskell module Ex06_FlowPatternMatchingSpec ( spec ) whereimport Test.Hspec import Test.Hspec import Test.QuickCheck import Prelude. Unicode import Data. Monoid.

module Ex06_FlowPatternMatchingSpec ( spec ) where import Test.Hspec import Test.Hspec import Test.QuickCheck import Prelude. Unicode import Data. Monoid. Unicode factorial :: Int -> Int factorial x | x String tell [] = "This list is empty" tell [x] = "This list has one element: " ++ show x tell (x:y:[]) = "This list has two elements: ++ show x ++ tell (x:y:xs) = "This list is too long" " and " ++ show y length' [] = 0 Tength' (x:xs) = 1 + length' xs sum' [] = 0 sum' (x:xs) = x + sum' xs firstLetter [] = "Empty string, whoops!" firstLetter l@(x:xs) = "The first letter of " ++ 1 ++ " is " ++ [x] main i 19 (1) tell :: [Int] -> String tell [] = "This list is empty" tell [x] = "This list has one element: " ++ show x tell (x:y:[]) = "This list has two elements: " ++ show x ++ tell (x:y:xs) = "This list is too long" " and " ++ show y length' [] = 0 length' (x:xs) = 1 + length' xs sum' [] = 0 sum' (x:xs) = x + sum' xs firstLetter [] = "Empty string, whoops!" firstLetter 1(x:xs) = "The first letter of " ++ 1 ++ " is " ++ [x] main :: 10 () main = hspec spec spec :: Spec spec = do describe "Pattern matching" $ do it "can be used in factorial calc" $ do factorial 5 'shouldBe' 120 it "can fail when no default case" $ do charName 'a' shouldBe "Albert" -- charName'd' 'shouldThrow' PatternMatchFail it "can be used on tuples" $ do pending it "can be used on triples" $ do pending it "can pattern list comprehensions" $ do pending it "can be used for the head function" $ do pending it "can safely process a list" $ do pending it "can count elements in list with recursion" $ do pending it "can reduce add a list" $ do pending it "can hold the original item with pattern" $ do pending

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!