HORIZON HASKELLDocslts/ghc-9.14.x99ffbb82026-10-19Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 99ffbb8 · 2026-10-19

Modulesop-extras-0.4.1.1Haskell2010

Data.SOP.Telescope

See Telescope

Intended for qualified import

import           Data.SOP.Telescope (Telescope(..))
import qualified Data.SOP.Telescope as Telescope
Contents
  1. Telescope
  2. Utilities
  3. Bifunctor analogues of SOP functions
  4. Extension, retraction, alignment
  5. Simplified API
  6. Additional API
Synopsis

Telescope

datadata Telescope (g :: k -> Type) (f :: k -> Type) (xs :: [k]) where

Telescope

A telescope is an extension of an NS, where every time we "go right" in the sum we have an additional value.

The Telescope API mostly follows sop-core conventions, supporting functor (hmap, hcmap), applicative (hap, hpure), foldable (hcollapse) and traversable (hsequence'). However, since Telescope is a bi-functor, it cannot reuse the sop-core classes. The naming scheme of the functions is adopted from sop-core though; for example:

bi h (c) zipWith
|  |  |    |
|  |  |    \ zipWith: the name from base
|  |  |
|  |  \ constrained: version of the function with a constraint parameter
|  |
|  \ higher order: 'Telescope' (like 'NS'/'NP') is a /higher order/ functor
|
\ bifunctor: 'Telescope' (unlike 'NS'/'NP') is a higher order /bifunctor/

In addition to the standard SOP operators, the new operators that make a Telescope a telescope are extend, retract and align; see their documentation for details.

Constructors

Instances12HTrans, HAp, HSequence, HTraverse_, Eq, Ord, …

Utilities

Bifunctor analogues of SOP functions

Extension, retraction, alignment

valuealign
  1. :: Monad m
  2. => InPairs (Requiring g' (Extend m g f)) xs

    How to extend

  3. -> Tails (Requiring f' (Retract m g f)) xs

    How to retract

  4. -> NP (f' -.-> (f -.-> f'')) xs

    Function to apply at the tip

  5. -> Telescope g' f' xs

    Telescope we are aligning with

  6. -> Telescope g f xs
  7. -> m (Telescope g f'' xs)

Align a telescope with another, then apply a function to the tips

Aligning is a combination of extension and retraction, extending or retracting the telescope as required to match up with the other telescope.

Simplified API

Additional API

newtypenewtype SimpleTelescope (f :: k -> Type) (xs :: [k])

Telescope with both functors set to the same f

Instances8HAp, HCollapse, HSequence, HTraverse_, CollapseTo, Prod, …
valuescanl
  1. :: InPairs (ScanNext h g) (x ': xs)
  2. -> h x
  3. -> Telescope g f (x ': xs)
  4. -> Telescope (Product h g) (Product h f) (x ': xs)

Telescope analogue of scanl on lists

This function is modelled on

scanl :: (b -> a -> b) -> b -> [a] -> [b]

but there are a few differences:

  • Since every seed has a different type, we must be given a function for each transition.

  • Unlike scanl, we preserve the length of the telescope (scanl prepends the initial seed)

  • Instead of generating a telescope containing only the seeds, we instead pair the seeds with the elements.