module Data.Label.Base
(
head
, tail
, left
, right
, just
, fst
, snd
, swap
, fst3
, snd3
, trd3
, readShow
)
where
import Prelude hiding (fst, snd, head, tail)
import Control.Arrow (arr, Kleisli(..), ArrowApply, ArrowZero, ArrowChoice)
import Data.Maybe (listToMaybe)
import Data.Label.Partial (Partial)
import Data.Label
import qualified Data.Label.Mono as Mono
import qualified Data.Label.Poly as Poly
import qualified Data.Tuple as Tuple
head :: (ArrowZero arr, ArrowApply arr, ArrowChoice arr)
=> Mono.Lens arr [a] a
tail :: (ArrowZero arr, ArrowApply arr, ArrowChoice arr)
=> Mono.Lens arr [a] [a]
(head, tail) = $(getLabel ''[])
left :: (ArrowZero arr, ArrowApply arr, ArrowChoice arr)
=> Poly.Lens arr (Either a b -> Either o b) (a -> o)
right :: (ArrowZero arr, ArrowApply arr, ArrowChoice arr)
=> Poly.Lens arr (Either a b -> Either a o) (b -> o)
(left, right) = $(getLabel ''Either)
just :: (ArrowChoice cat, ArrowZero cat, ArrowApply cat)
=> Poly.Lens cat (Maybe a -> Maybe b) (a -> b)
just = $(getLabel ''Maybe)
fst :: ArrowApply arr => Poly.Lens arr ((a, b) -> (o, b)) (a -> o)
snd :: ArrowApply arr => Poly.Lens arr ((a, b) -> (a, o)) (b -> o)
(fst, snd) = $(getLabel ''(,))
swap :: ArrowApply arr => Poly.Lens arr ((a, b) -> (c, d)) ((b, a) -> (d, c))
swap = let io = Iso (arr Tuple.swap) (arr Tuple.swap) in Poly.iso io io
fst3 :: ArrowApply arr => Poly.Lens arr ((a, b, c) -> (o, b, c)) (a -> o)
snd3 :: ArrowApply arr => Poly.Lens arr ((a, b, c) -> (a, o, c)) (b -> o)
trd3 :: ArrowApply arr => Poly.Lens arr ((a, b, c) -> (a, b, o)) (c -> o)
(fst3, snd3, trd3) = $(getLabel ''(,,))
readShow :: (Read a, Show a) => Iso Partial String a
readShow = Iso r s
where r = Kleisli (fmap Tuple.fst . listToMaybe . readsPrec 0)
s = arr show