hspec

HSpec Nothing expectation failing to compile

落爺英雄遲暮 提交于 2019-12-01 00:53:07
I'm learning Haskell and I've written this function: safeHead :: [a] -> Maybe a safeHead [] = Nothing safeHead (x:xs) = Just x I'm now trying to test it with HSpec: import Test.Hspec main :: IO () main = hspec spec spec :: Spec spec = describe "safeHead" $ it "should return Nothing for empty list" $ safeHead [] `shouldBe` Nothing But that fails to compile: Error:(14, 19) ghc: No instance for (Eq a0) arising from a use of ‘shouldBe’ The type variable ‘a0’ is ambiguous Note: there are several potential instances: instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Base’ instance Eq a => Eq (GHC