data-diverse-4.7.1.0: Extensible records and polymorphic variants.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Diverse.CaseFunc

Synopsis
  • newtype CaseFunc (k :: Type -> Constraint) r (xs :: [Type]) = CaseFunc (forall x. k x => x -> r)
  • newtype CaseFunc' (k :: Type -> Constraint) (xs :: [Type]) = CaseFunc' (forall x. k x => x -> x)
  • newtype CaseFunc1 (k :: Type -> Constraint) (k1 :: (Type -> Type) -> Constraint) (k0 :: Type -> Constraint) r (xs :: [Type]) = CaseFunc1 (forall f x. (k (f x), k1 f, k0 x) => f x -> f r)
  • newtype CaseFunc1_ (k :: Type -> Constraint) (k1 :: (Type -> Type) -> Constraint) (k0 :: Type -> Constraint) r x (xs :: [Type]) = CaseFunc1_ (forall f. (k (f x), k1 f, k0 x) => f x -> f r)
  • newtype CaseFunc1' (k :: Type -> Constraint) (k1 :: (Type -> Type) -> Constraint) (k0 :: Type -> Constraint) (xs :: [Type]) = CaseFunc1' (forall f x. (k (f x), k1 f, k0 x) => f x -> f x)

Documentation

newtype CaseFunc (k :: Type -> Constraint) r (xs :: [Type]) Source #

This handler stores a polymorphic function that returns a different type.

let y = pick (5 :: Int) :: Which '[Int, Bool]
switch y (CaseFunc @Typeable (show . typeRep . (pure @Proxy))) `shouldBe` Int
let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nul
afoldr (:) [] (forMany (CaseFunc @Typeable (show . typeRep . (pure @Proxy))) x) `shouldBe`
    ["Int", "Bool", "Char", "Maybe Char", "Int", "Maybe Char"]

Constructors

CaseFunc (forall x. k x => x -> r) 

Instances

Instances details
Reiterate (CaseFunc k r) xs Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

reiterate :: CaseFunc k r xs -> CaseFunc k r (Tail xs) Source #

k x => Case (CaseFunc k r) (x ': xs) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

case' :: CaseFunc k r (x ': xs) -> Head (x ': xs) -> CaseResult (CaseFunc k r) (Head (x ': xs)) Source #

type CaseResult (CaseFunc k r :: [Type] -> TYPE LiftedRep) (x :: Type) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

type CaseResult (CaseFunc k r :: [Type] -> TYPE LiftedRep) (x :: Type) = r

newtype CaseFunc' (k :: Type -> Constraint) (xs :: [Type]) Source #

This handler stores a polymorphic function that doesn't change the type.

let x = (5 :: Int) ./ (6 :: Int8) ./ (7 :: Int16) ./ (8 :: Int32) ./ nil
    y = (15 :: Int) ./ (16 :: Int8) ./ (17 :: Int16) ./ (18 :: Int32) ./ nil
afmap (CaseFunc' @Num (+10)) x `shouldBe` y

Constructors

CaseFunc' (forall x. k x => x -> x) 

Instances

Instances details
Reiterate (CaseFunc' k) xs Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

reiterate :: CaseFunc' k xs -> CaseFunc' k (Tail xs) Source #

k x => Case (CaseFunc' k) (x ': xs) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

case' :: CaseFunc' k (x ': xs) -> Head (x ': xs) -> CaseResult (CaseFunc' k) (Head (x ': xs)) Source #

type CaseResult (CaseFunc' k :: [Type] -> TYPE LiftedRep) (x :: Type) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

type CaseResult (CaseFunc' k :: [Type] -> TYPE LiftedRep) (x :: Type) = x

newtype CaseFunc1 (k :: Type -> Constraint) (k1 :: (Type -> Type) -> Constraint) (k0 :: Type -> Constraint) r (xs :: [Type]) Source #

This handler stores a polymorphic function that work on higher kinds, eg Functor You may want to use C0 for k@

Constructors

CaseFunc1 (forall f x. (k (f x), k1 f, k0 x) => f x -> f r) 

Instances

Instances details
Reiterate (CaseFunc1 k k1 k0 r) xs Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

reiterate :: CaseFunc1 k k1 k0 r xs -> CaseFunc1 k k1 k0 r (Tail xs) Source #

(k (f x), k1 f, k0 x) => Case (CaseFunc1 k k1 k0 r) (f x ': xs) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

case' :: CaseFunc1 k k1 k0 r (f x ': xs) -> Head (f x ': xs) -> CaseResult (CaseFunc1 k k1 k0 r) (Head (f x ': xs)) Source #

type CaseResult (CaseFunc1 k k1 k0 r :: [Type] -> TYPE LiftedRep) (f x :: Type) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

type CaseResult (CaseFunc1 k k1 k0 r :: [Type] -> TYPE LiftedRep) (f x :: Type) = f r

newtype CaseFunc1_ (k :: Type -> Constraint) (k1 :: (Type -> Type) -> Constraint) (k0 :: Type -> Constraint) r x (xs :: [Type]) Source #

Constructors

CaseFunc1_ (forall f. (k (f x), k1 f, k0 x) => f x -> f r) 

Instances

Instances details
Reiterate (CaseFunc1_ k k1 k0 r x) xs Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

reiterate :: CaseFunc1_ k k1 k0 r x xs -> CaseFunc1_ k k1 k0 r x (Tail xs) Source #

(k (f x), k1 f, k0 x) => Case (CaseFunc1_ k k1 k0 r x) (f x ': xs) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

case' :: CaseFunc1_ k k1 k0 r x (f x ': xs) -> Head (f x ': xs) -> CaseResult (CaseFunc1_ k k1 k0 r x) (Head (f x ': xs)) Source #

type CaseResult (CaseFunc1_ k k1 k0 r x :: [Type] -> TYPE LiftedRep) (f x :: Type) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

type CaseResult (CaseFunc1_ k k1 k0 r x :: [Type] -> TYPE LiftedRep) (f x :: Type) = f r

newtype CaseFunc1' (k :: Type -> Constraint) (k1 :: (Type -> Type) -> Constraint) (k0 :: Type -> Constraint) (xs :: [Type]) Source #

A varation of CaseFunc1 that doesn't change the return type

Constructors

CaseFunc1' (forall f x. (k (f x), k1 f, k0 x) => f x -> f x) 

Instances

Instances details
Reiterate (CaseFunc1' k k1 k0) xs Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

reiterate :: CaseFunc1' k k1 k0 xs -> CaseFunc1' k k1 k0 (Tail xs) Source #

(k (f x), k1 f, k0 x) => Case (CaseFunc1' k k1 k0) (f x ': xs) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

Methods

case' :: CaseFunc1' k k1 k0 (f x ': xs) -> Head (f x ': xs) -> CaseResult (CaseFunc1' k k1 k0) (Head (f x ': xs)) Source #

type CaseResult (CaseFunc1' k k1 k0 :: [Type] -> TYPE LiftedRep) (f x :: Type) Source # 
Instance details

Defined in Data.Diverse.CaseFunc

type CaseResult (CaseFunc1' k k1 k0 :: [Type] -> TYPE LiftedRep) (f x :: Type) = f x