Tôi đang gặp khó khăn với lens và zippers. Xem xét bên dưới đang chạy trong ghci
bước vào dây kéo với ống kính `to`
> import Control.Lens
> import Control.Zipper
>
> :t within (ix 1) $ zipper ([1,2,3] :: [Int])
> within (ix 1) $ zipper ([1,2,3] :: [Int])
:: Control.Monad.MonadPlus m => m (Zipper Top Int [Int] :>> Int)
Có data A t = A t
, làm thế nào tôi có thể tạo ra loại dây kéo như: Control.Monad.MonadPlus m => m (Zipper Top Int [Int] :>> A Int)
?
tôi đã cố gắng within (ix 1 . to A) $ zipper ([1,2,3] :: [Int])
nhưng nó mang lại một lỗi:
Could not deduce (Contravariant
(Bazaar (Indexed Int) (A Int) (A Int)))
arising from a use of ‘to’
from the context (Control.Monad.MonadPlus m)
bound by the inferred type of
it :: Control.Monad.MonadPlus m =>
m (Zipper Top Int [Int] :>> A Int)
at Top level
In the second argument of ‘(.)’, namely ‘to A’
In the first argument of ‘within’, namely ‘(ix 1 . to A)’
In the expression: within (ix 1 . to A)
Có cách nào để làm điều đó mà không specyfing '(\ (A a) -> a)' chức năng? Tôi có thể vượt qua đây 'undefined' nếu trong trường hợp của tôi nó không phải là hiển nhiên? – remdezx
Không thực sự. Vấn đề là bạn sẽ không thể quay trở lại. Sử dụng 'upward' để thoát ra sẽ cho' undefined'. – cchalmers
Tôi hiểu ... Có lựa chọn nào khác ngoài 'Iso' không? – remdezx