BiobaseTypes-0.1.1.1: Collection of types for bioinformatics

Safe HaskellNone
LanguageHaskell2010

Biobase.Types.Index

Description

Biological sequence data is oftentimes indexed either 0- or 1-based. The Index type developed provides static guarantees that there is no confusion what index is in use.

This module does not export the ctor Index. If you want to (unsafely) use it, import Biobase.Types.Index.Type directly. Use fromInt0 to make clear that you count from 0 and transform to an Index t. I.e. fromInt0 0 :: Index 1 yields the lowest 1-base index.

Synopsis

Documentation

checkIndex :: forall t. KnownNat t => Index t -> Index t Source

Uses index to guarantee that the Index is ok.

reIndex :: forall n m. (KnownNat n, KnownNat m) => Index n -> Index m Source

Re-Index an index of type Index n as Index m. This is always safe, as 0 :: Index 0 gives 1 :: Index 1 for example. I.e. valid indices become valid indices.

(+.) :: forall t. KnownNat t => Index t -> Int -> Index t Source

Helper function that allows addition of an Index and an Int, with the Int on the right.

unsafePlus :: forall t. KnownNat t => Index t -> Int -> Index t Source

Unsafe plus.

(-.) :: forall t. KnownNat t => Index t -> Int -> Index t Source

Helper function that allows subtraction of an Index and an Int, with the Int on the right.

unsafeMinus :: forall t. KnownNat t => Index t -> Int -> Index t Source

Unsafe minus.

toInt0 :: forall t. KnownNat t => Index t -> Int Source

Return the index as an Int-style index that is zero-based.

fromInt0 :: forall t. KnownNat t => Int -> Index t Source

As an index from an Int-style zero-based one.

TODO We might want to check that the argument is [0..].

type I0 = Index 0 Source

Zero-based indices.

type I1 = Index 1 Source

One-based indices.

index :: forall t. KnownNat t => Int -> Index t Source

Turn an Int into an Index safely.

maybeIndex :: forall t. KnownNat t => Int -> Maybe (Index t) Source

Produce Just and Index or Nothing.