Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

NP with optional values

Intended for qualified import

import Data.SOP.OptNP (OptNP (..), ViewOptNP (..)) import qualified Data.SOP.OptNP as OptNP

## Synopsis

- type NonEmptyOptNP = OptNP 'False
- data OptNP empty f xs where
- at ∷ SListI xs ⇒ f x → Index xs x → NonEmptyOptNP f xs
- empty ∷ ∀ f xs. SListI xs ⇒ OptNP 'True f xs
- fromNP ∷ (∀ empty. OptNP empty f xs → r) → NP f xs → r
- fromNonEmptyNP ∷ ∀ f xs. IsNonEmpty xs ⇒ NP f xs → NonEmptyOptNP f xs
- fromSingleton ∷ NonEmptyOptNP f '[x] → f x
- singleton ∷ f x → NonEmptyOptNP f '[x]
- toNP ∷ OptNP empty f xs → NP (Maybe :.: f) xs
- data ViewOptNP f xs where
- OptNP_ExactlyOne ∷ f x → ViewOptNP f '[x]
- OptNP_AtLeastTwo ∷ ViewOptNP f (x ': (y ': zs))

- view ∷ ∀ f xs. NonEmptyOptNP f xs → ViewOptNP f xs
- combine ∷ ∀ (f ∷ Type → Type) xs. (SListI xs, HasCallStack) ⇒ Maybe (NonEmptyOptNP f xs) → Maybe (NonEmptyOptNP f xs) → Maybe (NonEmptyOptNP f xs)
- combineWith ∷ SListI xs ⇒ (∀ a. These1 f g a → h a) → Maybe (NonEmptyOptNP f xs) → Maybe (NonEmptyOptNP g xs) → Maybe (NonEmptyOptNP h xs)
- zipWith ∷ ∀ f g h xs. (∀ a. These1 f g a → h a) → NonEmptyOptNP f xs → NonEmptyOptNP g xs → NonEmptyOptNP h xs

# Documentation

type NonEmptyOptNP = OptNP 'False Source #

data OptNP empty f xs where Source #

Like an `NP`

, but with optional values

OptNil ∷ OptNP 'True f '[] | |

OptCons ∷ !(f x) → !(OptNP empty f xs) → OptNP 'False f (x ': xs) | |

OptSkip ∷ !(OptNP empty f xs) → OptNP empty f (x ': xs) |

#### Instances

HTrans (OptNP empty ∷ (k1 → Type) → [k1] → Type) (OptNP empty ∷ (k2 → Type) → [k2] → Type) Source # | |

Defined in Data.SOP.OptNP htrans ∷ ∀ c (xs ∷ l1) (ys ∷ l2) proxy f g. AllZipN (Prod (OptNP empty)) c xs ys ⇒ proxy c → (∀ (x ∷ k10) (y ∷ k20). c x y ⇒ f x → g y) → OptNP empty f xs → OptNP empty g ys Source # hcoerce ∷ ∀ (f ∷ k10 → Type) (g ∷ k20 → Type) (xs ∷ l1) (ys ∷ l2). AllZipN (Prod (OptNP empty)) (LiftedCoercible f g) xs ys ⇒ OptNP empty f xs → OptNP empty g ys Source # | |

HAp (OptNP empty ∷ (k → Type) → [k] → Type) Source # | |

HSequence (OptNP empty ∷ (k → Type) → [k] → Type) Source # | |

Defined in Data.SOP.OptNP hsequence' ∷ ∀ (xs ∷ l) f (g ∷ k0 → Type). (SListIN (OptNP empty) xs, Applicative f) ⇒ OptNP empty (f :.: g) xs → f (OptNP empty g xs) Source # hctraverse' ∷ ∀ c (xs ∷ l) g proxy f f'. (AllN (OptNP empty) c xs, Applicative g) ⇒ proxy c → (∀ (a ∷ k0). c a ⇒ f a → g (f' a)) → OptNP empty f xs → g (OptNP empty f' xs) Source # htraverse' ∷ ∀ (xs ∷ l) g f f'. (SListIN (OptNP empty) xs, Applicative g) ⇒ (∀ (a ∷ k0). f a → g (f' a)) → OptNP empty f xs → g (OptNP empty f' xs) Source # | |

All (Compose Show f) xs ⇒ Show (OptNP empty f xs) Source # | |

All (Compose Eq f) xs ⇒ Eq (OptNP empty f xs) Source # | |

type Same (OptNP empty ∷ (k1 → Type) → [k1] → Type) Source # | |

type Prod (OptNP empty ∷ (k → Type) → [k] → Type) Source # | |

type SListIN (OptNP empty ∷ (k → Type) → [k] → Type) Source # | |

Defined in Data.SOP.OptNP | |

type AllN (OptNP empty ∷ (k → Type) → [k] → Type) (c ∷ k → Constraint) Source # | |

Defined in Data.SOP.OptNP |

fromNonEmptyNP ∷ ∀ f xs. IsNonEmpty xs ⇒ NP f xs → NonEmptyOptNP f xs Source #

fromSingleton ∷ NonEmptyOptNP f '[x] → f x Source #

If `OptNP`

is not empty, it must contain at least one value

singleton ∷ f x → NonEmptyOptNP f '[x] Source #

# View

data ViewOptNP f xs where Source #

OptNP_ExactlyOne ∷ f x → ViewOptNP f '[x] | |

OptNP_AtLeastTwo ∷ ViewOptNP f (x ': (y ': zs)) |

view ∷ ∀ f xs. NonEmptyOptNP f xs → ViewOptNP f xs Source #

# Combining

combine ∷ ∀ (f ∷ Type → Type) xs. (SListI xs, HasCallStack) ⇒ Maybe (NonEmptyOptNP f xs) → Maybe (NonEmptyOptNP f xs) → Maybe (NonEmptyOptNP f xs) Source #

combineWith ∷ SListI xs ⇒ (∀ a. These1 f g a → h a) → Maybe (NonEmptyOptNP f xs) → Maybe (NonEmptyOptNP g xs) → Maybe (NonEmptyOptNP h xs) Source #

zipWith ∷ ∀ f g h xs. (∀ a. These1 f g a → h a) → NonEmptyOptNP f xs → NonEmptyOptNP g xs → NonEmptyOptNP h xs Source #