compress xs@(_:_:_) = (ifte <$> ((==) <$> head <*> head.tail) <$> ((compress.).(:) <$> head <*> tail.tail) <*> ((:) <$> head <*> compress.tail) ) xs
В результате возникает ошибка типа, но я не понимаю, почему. Это должно быть эквивалентно
compress xs@(_:_:_) = (ifte (((==) <$> head <*> head.tail) xs) (((compress.).(:) <$> head <*> tail.tail) xs) (((:) <$> head <*> compress.tail) xs))
, что не так.
примечание: ifte = (\ x y z -> if x then y else z)
, <$>
и <*>
взяты из Control.Applicative
.
EDIT: ошибка:
Couldn't match expected type `[a]' with actual type `[a] -> [a]'
In the expression:
(ifte <$> ((==) <$> head <*> head . tail)
<$>
((compress .) . (:) <$> head <*> tail . tail)
<*>
((:) <$> head <*> compress . tail))
$ xs
In an equation for `compress':
compress xs@(_ : _ : _)
= (ifte <$> ((==) <$> head <*> head . tail)
<$>
((compress .) . (:) <$> head <*> tail . tail)
<*>
((:) <$> head <*> compress . tail))
$ xs
Я столкнулся с этой проблемой, пытаясь написать бесточечное решение проблемы 8 из Девяносто девять задач Haskell< /а>. Я пытался сделать это, изменив точечное решение, которое я написал, которое было
compress::Eq a => [a]->[a]
compress [] = []
compress (x:[]) = (x:[])
compress (x:y:xs) = ifte ((==) x y) (compress (x:xs)) (x:(compress (y:xs)))