MyNixOS website logo
Description

Measure container capacity. Use it to safely change container.

This module introduces typeclasses

  • HasCard = "Has cardinality". In other words, "it's possible to measure current count of elements for this container"

  • HasCardT = "Has cardinality (for container types of kind (* -> *))". In other words, "it's possible to measure current count of elements for this container (for container types of kind (* -> *))"

  • HasCardConstr = "Has cardinality constraint". In other words, "there is a capacity constraint for this container".

  • HasCardConstrT = "Has cardinality constraint (for container types of kind (* -> *))". In other words, "there is a capacity constraint for this container type of kind (* -> *)".

  • HasCardUCT = "Has cardinality-unsafe container transform". Define transform that may thow an error, if contents of from don't fit in to .

  • HasCardUCT_T = "Has cardinality-unsafe container transform (for container types of kind (* -> *))". Same thing as HasCardUCT, but for containers of kind (* -> *).

No, it's not about playing cards. It's about cardinalities. Wikipedia: "/In mathematics, the cardinality of a set is a measure of the number of elements of the set. For example, the set A = {2, 4, 6} contains 3 elements, and therefore A has a cardinality of 3./" In this package I dare to extend the definition a bit to "C. is a measure of the number of elements in a container"

Usual containers are (together with their cardinality ranges):

  • Identity a (1 element)

  • Maybe a (0..1 element)

  • [a] (0..inf elements)

  • Map k e (0..inf elements)

I extended this to the folowing list:

  • EmptySet a (0 elements)

  • Identity a (1 element)

  • Maybe a (0..1 element)

  • [a] (0..inf elements)

  • NeverEmptyList a (1..inf elements)

  • Map k e (0..inf elements)

Typeclass HasCardUCT together with function sContTrans (safe container transform) provides a facility to safely change container from one to another keepeng the content. If content doesn't fit to target container, Nothing is returned. However, when transforming from list [a] to (Maybe a) it won't check list length further first 2 elements. The complexity and power of this package is that it provides a facility to lazily evaluate amount of content in the container.

To interface package functions

import Data.Cardinality
Metadata

Version

0.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows