fin-0.0.1: Nat and Fin: peano naturals and finite numbers

Safe HaskellNone
LanguageHaskell2010

Data.Fin.Enum

Contents

Description

This module is designed to be imported qualified:

import qualified Data.Fin.Enum as E
Synopsis

Documentation

class Enum a where #

Generic enumerations.

Examples:

>>> from ()
0
>>> to 0 :: ()
()
>>> to 0 :: Bool
False
>>> map to F.universe :: [Bool]
[False,True]
>>> map (to . (+1) . from) [LT, EQ, GT] :: [Ordering] -- Num Fin is modulo arithmetic
[EQ,GT,LT]

Associated Types

type EnumSize a :: Nat #

The size of an enumeration.

Methods

from :: a -> Fin (EnumSize a) #

Converts a value to its index.

from :: (Generic a, GFrom a, EnumSize a ~ GEnumSize a) => a -> Fin (EnumSize a) #

Converts a value to its index.

to :: Fin (EnumSize a) -> a #

Converts from index to the original value.

to :: (Generic a, GTo a, EnumSize a ~ GEnumSize a) => Fin (EnumSize a) -> a #

Converts from index to the original value.

Instances
Enum Bool #

Bool ~ 2

Instance details

Defined in Data.Fin.Enum

Associated Types

type EnumSize Bool :: Nat #

Methods

from :: Bool -> Fin (EnumSize Bool) #

to :: Fin (EnumSize Bool) -> Bool #

Enum Ordering #

Ordering ~ 3

Instance details

Defined in Data.Fin.Enum

Associated Types

type EnumSize Ordering :: Nat #

Enum () #

() ~ 1

Instance details

Defined in Data.Fin.Enum

Associated Types

type EnumSize () :: Nat #

Methods

from :: () -> Fin (EnumSize ()) #

to :: Fin (EnumSize ()) -> () #

Enum Void #

Void ~ 0

Instance details

Defined in Data.Fin.Enum

Associated Types

type EnumSize Void :: Nat #

Methods

from :: Void -> Fin (EnumSize Void) #

to :: Fin (EnumSize Void) -> Void #

Generic implementation

gfrom :: (Generic a, GFrom a) => a -> Fin (GEnumSize a) #

Generic version of from.

type GFrom a = GFromRep (Rep a) #

Constraint for the class that computes gfrom.

gto :: (Generic a, GTo a) => Fin (GEnumSize a) -> a #

Generic version of to.

type GTo a = GToRep (Rep a) #

Constraint for the class that computes gto.

type GEnumSize a = EnumSizeRep (Rep a) Nat0 #

Compute the size from the type.