Type fail when using "left" lens from fclabels
I made a minimal example for testing fclabels. Using a lens to get the "correct" value from any value. Why does it fail? Am I missing anything?
module Label where
import Data.Label
import Data.Label.Base
test = get right (Right "test")
{- Will fail with this message:
Label.hs:5:12:
No instance for (Control.Arrow.ArrowZero Data.Label.Point.Total)
arising from a use of `right'
Possible fix:
add an instance declaration for
(Control.Arrow.ArrowZero Data.Label.Point.Total)
In the first argument of `get', namely `right'
In the expression: get right (Right "test")
In an equation for `test': test = get right (Right "test")
Failed, modules loaded: none.
-- Tested with fclabels-2.0.2
-}
source to share
The error is rather obscure, but it becomes clearer when we look at the types and documentation get
and right
:
get :: (f :-> a) -> f -> a
type :-> f o = Lens Total f o
right :: (ArrowZero arr, ArrowApply arr, ArrowChoice arr)
=> Lens arr (Either a b -> Either a o) (b -> o)
-- Lens pointing to the right value in an Either. (Partial and polymorphic)
As such get
, the one you are using is only for regular lenses, but right
not a full lens, as it won't work if the value was Left
. The error says that a carrier type is required for a partial lens ArrowZero
, but total lenses cannot.
If you experiment with ghci
, you only get this error from a call get right
without any arguments.
If you changed the import Data.Label
to Data.Label.Partial
then your code will work. test
ends with type Maybe String
.
source to share