Guest User

Untitled

a guest
Jul 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. module FizzBuzz where
  2.  
  3. data StringInt a = Int a | String a
  4.  
  5. handleRule:: StringInt a -> a
  6. handleRule x
  7. | x % 3 == 0 = StringInt "Fizz"
  8. | x % 5 == 0 = StringInt "Buzz"
  9. | otherwise = x
  10.  
  11. run:: [StringInt a] -> [a]
  12. run = map handleRule
  13.  
  14. module FizzBuzzSpec (spec) where
  15.  
  16. import Test.Hspec
  17. import FizzBuzz
  18.  
  19. spec :: Spec
  20. spec = describe "FizzBuzz#run" $ do
  21. it "should have displayed Fizz for number 3" $
  22. run [1..10]:2 `shouldBe` "Fizz"
  23. it "should have displayed Buzz for number 5" $
  24. run [1..10]:4 `shouldBe` "Buzz"
  25.  
  26. • Occurs check: cannot construct the infinite type: a ~ StringInt a
  27. • In the expression: x
  28. In an equation for ‘handleRule’:
  29. handleRule x
  30. | (%) x 3 == 0 = StringInt "Fizz"
  31. | (%) x 5 == 0 = StringInt "Buzz"
  32. | otherwise = x
  33. • Relevant bindings include
  34. x :: StringInt a (bound at src/FizzBuzz.hs:6:12)
  35. handleRule :: StringInt a -> a (bound at src/FizzBuzz.hs:6:1)
Add Comment
Please, Sign In to add comment