data-diverse-4.3.0.0: Extensible records and polymorphic variants.

Safe HaskellSafe
LanguageHaskell2010

Data.Diverse.CaseFunc

Synopsis

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

Reiterate (CaseFunc k r) xs Source # 

Methods

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

k x => Case (CaseFunc k r) ((:) Type x xs) Source # 

Methods

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

type CaseResult Type * (CaseFunc k r) x Source # 
type CaseResult Type * (CaseFunc k r) x = 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

Reiterate (CaseFunc' k) xs Source # 

Methods

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

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

Methods

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

type CaseResult Type * (CaseFunc' k) x Source # 
type CaseResult Type * (CaseFunc' k) x = 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 NoContraint for k@

Constructors

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

Instances

Reiterate (CaseFunc1 k k1 k0 r) xs Source # 

Methods

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

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

Methods

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

type CaseResult Type * (CaseFunc1 k k1 k0 r) (f x) Source # 
type CaseResult Type * (CaseFunc1 k k1 k0 r) (f x) = f r

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

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

Constructors

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

Instances

Reiterate (CaseFunc1' k k1 k0) xs Source # 

Methods

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

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

Methods

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

type CaseResult Type * (CaseFunc1' k k1 k0) (f x) Source # 
type CaseResult Type * (CaseFunc1' k k1 k0) (f x) = f x