Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module FizzBuzz where
- data StringInt a = Int a | String a
- handleRule:: StringInt a -> a
- handleRule x
- | x % 3 == 0 = StringInt "Fizz"
- | x % 5 == 0 = StringInt "Buzz"
- | otherwise = x
- run:: [StringInt a] -> [a]
- run = map handleRule
- module FizzBuzzSpec (spec) where
- import Test.Hspec
- import FizzBuzz
- spec :: Spec
- spec = describe "FizzBuzz#run" $ do
- it "should have displayed Fizz for number 3" $
- run [1..10]:2 `shouldBe` "Fizz"
- it "should have displayed Buzz for number 5" $
- run [1..10]:4 `shouldBe` "Buzz"
- • Occurs check: cannot construct the infinite type: a ~ StringInt a
- • In the expression: x
- In an equation for ‘handleRule’:
- handleRule x
- | (%) x 3 == 0 = StringInt "Fizz"
- | (%) x 5 == 0 = StringInt "Buzz"
- | otherwise = x
- • Relevant bindings include
- x :: StringInt a (bound at src/FizzBuzz.hs:6:12)
- handleRule :: StringInt a -> a (bound at src/FizzBuzz.hs:6:1)
Add Comment
Please, Sign In to add comment