У меня есть функция foo
:
foo :: [a] -> (a -> b) -> [b]
foo [] f = []
foo (x:xs) f = foo xs f
И следующие два свойства, которым он должен удовлетворять:
prop_1 :: [Int] -> Bool
prop_1 xs = foo xs id == xs
prop_2 :: [Int] -> (Int -> Int) -> (Int -> Int) -> Bool
prop_2 xs f g = foo (foo xs f) g == foo xs (g . f)
Когда я попытался протестировать функцию с помощью quickCheck, я получил следующую ошибку:
Ambiguous type variable 't0' arising from a use of '=='
prevents the constraint '(Eq t0)' from being solved.
Probable fix: use a type annotation to specify what 't0' should be.
These potential instances exist:
instance (Eq a, Eq b) => Eq (Either a b)
-- Defined in 'Data.Either'
instance Eq GeneralCategory -- Defined in 'GHC.Unicode'
instance Eq Ordering -- Defined in 'ghc-prim-0.5.0.0:GHC.Classes'
...plus 24 others
...plus 107 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
In the expression: foo (foo xs f) g == foo xs (g . f)
In an equation for 'prop_2':
prop_2 xs f g = foo (foo xs f) g == foo xs (g . f)
Failed, modules loaded: none.
Я не уверен, почему я получаю эту ошибку и как я могу ее решить. Любые идеи приветствуются.
prop_2
в оболочке? Вы использовали:{
и:}
для записи и подписи, и функции в одном блоке? - person Willem Van Onsem   schedule 28.06.2019foo xs (g . f)
, так что это обычно означает, что сигнатуры типов не говорят, что здесь[Int]
. - person Willem Van Onsem   schedule 28.06.2019foo
эквивалентнаconst []
, поэтому ваше первое свойство всегда будет давать сбой. Во-вторых,prop_2
не может быть запущенquickCheck
, потому что нет экземпляраShow (Int -> Int)
(это требуется дляquickCheck
, чтобы он мог печатать примеры счетчиков) - person sara   schedule 28.06.2019