How to work with assertEqual with parameterized types

I am trying to do exercises in Real World Haskell in TDD style using HUnit . As you probably guessed, I have not been able to do so far, so I'm absolutely new when it comes to Haskell. Given the following code, how can I solve the following error, ghci produces:

An ambiguous variable of type a' in the constraints: Show 'resulting from the use of assertEqual' at List_Test.hs:6:27-58 Eq a' resulting from the use of `assertEqual 'in List_Test.hs: 6: 27-58 Probable correction: add a type signature that corrects these type variables

List_Test.hs:

module List_Test
where
import List
import Test.HUnit

fromEmptyList = TestCase $ assertEqual "" [] (toList (Nil))

main = runTestTT fromEmptyList

List.hs:

module List
where
data List a = Cons a (List a)
            | Nil
              deriving (Show)

toList Nil = []
toList (Cons a b) = (:) a (toList b) 

, toList . - .

+3
1

, GHC , toList Nil .

*List> :i toList
toList :: List a -> [a]     -- Defined at List.hs:7:0-5

, a, , a - , " a". - , toList:

fromEmptyList = TestCase $ assertEqual "" [] (toList (Nil) :: [Int])

List_Test ( main , main), :

$ runghc List_Test.hs 
Cases: 1  Tried: 1  Errors: 0  Failures: 0
+6

Source: https://habr.com/ru/post/1717590/


All Articles