Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HASKELL - Complete the code module Ex06_FlowPatternMatchingSpec ( spec ) where import Test.Hspec main :: IO () main = hspec spec spec :: Spec spec

HASKELL - Complete the code

module Ex06_FlowPatternMatchingSpec ( spec ) where import Test.Hspec main :: IO () main = hspec spec spec :: Spec spec = do describe "Pattern matching" $ do it "can be used in factorial calc" $ do pending -- factorial 5 `shouldBe` 120 it "can fail when no default case" $ do pending -- charName 'a' `shouldBe` "Albert" -- charName'd' `shouldThrow` PatternMatchFail it "can be used on tuples" $ do pending -- addVectors (1,2)(3,4) `shouldBe` (4,6) it "can be used on triples" $ do pending -- first (1,2,3) `shouldBe` 1 -- second (1,2,3) `shouldBe` 2 -- third (1,2,3) `shouldBe` 3 it "can pattern list comprehensions" $ do pending -- let xs = [(1,3),(4,3),(2,4),(5,3),(5,6),(3,1)] -- [a+b | (a,b) <- xs] `shouldBe` [4,7,6,8,11,4] it "can be used for the head function" $ do pending -- head' [2,3,4] `shouldBe` 2 -- head' "Hello" `shouldBe` 'H' it "can safely process a list" $ do pending -- tell [] `shouldBe` "This list is empty" -- tell [1] `shouldBe` "This list has one element: 1" -- tell [1,2] `shouldBe` "This list has two elements: 1 and 2" -- tell [1,2,3] `shouldBe` "This list is too long" it "can count elements in list with recursion" $ do pending -- length' [] `shouldBe` 0 -- length' [1,2,3] `shouldBe` 3 it "can reduce add a list" $ do pending -- sum' [] `shouldBe` 0 -- sum' [1,2,3] `shouldBe` 6 it "can hold the original item with pattern" $ do pending -- firstLetter "" `shouldBe` "Empty string, whoops!" -- firstLetter "Dracula" `shouldBe` "The first letter of Dracula is D"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions