Mam następujący kod (przekształcać jest podobna do konwersji)Jak rozwiązać nakładających instancja
instance {-# OVERLAPS #-} Transformable a a where
transform x = x
instance {-# OVERLAPPABLE #-} (Transformable l l', Transformable r r')
=> Transformable (Either l r) (Either l' r')
where
transform = bimap transform transform
Oczywiście, te przypadki zachodzą w przypadku, gdy próbuję przekształcić Either a b
do Either a b
i uzyskać następujące komunikat o błędzie (ParsingError
jest alias typ dla Either something somethingElse
)
Overlapping instances for Transformable
(parsingerror text) (parsingerror text)
arising from a use of ‘makereceipt’
matching instances:
Matching instances: Overlapping instances for Transformable
(ParsingError Text) (ParsingError Text)
arising from a use of ‘makeReceipt’
Matching instances:
instance [overlappable] (Transformable l l', Transformable r r') =>
Transformable (Either l r) (Either l' r')
instance [overlappable] (Transformable l l', Transformable r r') =>
Transformable (Either l r) (Either l' r')
-- Defined at Handler/GLEnterReceiptSheet/ReceiptRow.hs:154:31
instance [overlap ok] Transformable a a
-- Defined at Handler/GLEnterReceiptSheet/ReceiptRow.hs:151:27
próbowałem różnych kombinacji OVERLAPS
, OVERLAPPING
i OVERLAPPABLE
ale nic nie działa. Jak mogę to rozwiązać?
Próbowałem przeczytać instrukcję obsługi, ale nic nie rozumiem. Czy mógłbyś wyjaśnić różnicę między 'Transformable a a' a ~ b => Transformable a b' i dlaczego jeden jest niepoprawny, podczas gdy drugi jest w porządku. Wyglądają tak samo dla mnie. – mb14
@ mb14, złożoność dokumentacji "OverlappingInstances" jest jedną z rzeczy, które przekonały mnie, że to zły pomysł. Od tego czasu widziałem sporo dowodów na to, że jest "inwazyjny", łamiąc wszelkiego rodzaju dobrą intuicję. Naprawdę nie jestem fanem. – dfeuer
@ .Feur Zgadzam się, jednak w tym przypadku tak naprawdę nie mam wyboru. Najbardziej denerwujące jest to, że nakładające się instancje mają faktycznie zastosowanie, więc w praktyce nie ma nakładania się. Ponadto, nie miałbym tego problemu, gdybym mógł dodać ograniczenie nierówności w każdej instancji. – mb14