HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleindexed-list-literals-0.2.1.3Haskell2010

Data.IndexedListLiterals

  • 3 types
  • 1 class
  • 3 values
classclass IndexedListLiterals input (length :: Nat) output | output length -> input, input -> output length where
#

A type class which allows you to write tuples which can be transformed to and from a list the length of the list is also provided as a Nat

Methods

  • toList :: input -> [output]
    > toList (Only 1)
      [1]
    > toList (1,2,3)
      [1,2,3]
    > toList ZeroTuple
      []
  • fromList' :: [output] -> input

    a partial fromList with bad error messages

Instances21IndexedListLiterals, …
  • IndexedListLiterals (Only a) 1 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (ZeroTuple a) 0 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a) 2 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a) 3 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a) 4 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a) 5 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a) 6 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a) 7 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a) 8 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a) 9 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a) 10 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a) 11 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a) 12 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a) 13 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a) 14 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a, a) 15 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a) 16 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a) 17 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a) 18 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a) 19 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
  • IndexedListLiterals (a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a) 20 aDefined in indexed-list-literals-0.2.1.3 · Data.IndexedListLiterals
newtypenewtype Only a
#

The 1-tuple type or single-value "collection".

This type is structurally equivalent to the Identity type, but its intent is more about serving as the anonymous 1-tuple type missing from Haskell for attaching typeclass instances.

Parameter usage example:

encodeSomething (Only (42::Int))

Result usage example:

xs <- decodeSomething
forM_ xs $ \(Only id) -> {- ... -}

Constructors

Instances10Functor, Eq, Data, Ord, Read, Show, …
datadata ZeroTuple (a :: k)
#

Intuitively the zero tuple is () or Void but this breaks the Functional Dependency "input -> output length" stopping reliable inference, so this constructor is used to preserve type information

Instances1IndexedListLiterals
valuefromList
  1. :: (KnownNat length, ILL input length output)
  2. => [output]
  3. -> Maybe input
#
> fromList [1,2,3] :: Maybe (Int, Int, Int)
  Just (1,2,3)
> fromList ["word","up"] :: Maybe (String, String, String)
  Nothing
> fromList ['z'] :: Maybe (Only Char)
  Just (Only 'z')
valuefromListP
  1. :: (KnownNat length, ILL input length output)
  2. => len length
  3. -> [output]
  4. -> Maybe input
#

the fromList variants take a list and convert it into a tuple it's sort of the inverse of toList

> fromListP (len @3) [1,2,3]
  Just (1,2,3)
> fromListP (len @3) ["word","up"]
  Nothing
> fromListP (len @1) ['z']
  Just (Only 'z') @