Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 Haskellimage text in transcribedimage text in transcribed

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

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

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions