MyNixOS website logo
Description

Library to convert polymorphic datatypes to/from its monomorphic represetation.

This library provides the type-class and functions to convert between polymorphic data-types and its monomorphic representation type, such as length-indexed vectors, singletons for type-level natural numbers, etc.

The monomorphic library

Build Status

What is this?

This library provides the type-class and functions to convert polymorphic data-types to/from its monomorphic representation types. It is convenient to provide a monomorphic interface for dependently-typed programs.

Usage

Consider the following example:

data Nat = Z | S Nat
data SNat (n :: Nat) where
  SZ :: SNat Z
  SS :: SNat n -> SNat (S n)

instance Monomorphicable SNat where
  type MonomorphicRep SNat = Int
  promote 0     = Monomorphic SZ
  promote n
    | n < 0     = error "negative number"
    | otherwise =
        case promote (n - 1) of
          Monomorphic sn -> Monomorphic (SS sn)
  demote (Monomorphic sn) = toInt sn

data Vector (a :: *) (n :: Nat) where
  VNil :: Vector a Z
  (:-) :: a -> Vector a n -> Vector a (S n)

instance Monomorphicable (Vector a) whre
  type MonomorphicRep (Vector a) = [a]
  demote  (Monomorphic n) = toList n
  promote [] = Monomorphic Nil
  promote (x:xs) =
    case promote xs of
      Monomorphic xs' -> Monomorphic $ x :- xs'

Monomorphic k is the wrapper type to eliminate the polymorphic part of the types. The Monomorphicable type-class provides the functions to convert polymorphic value from/to its monomorphic representation, say MonomorphicRep k associated type.

In the example above, SNat n can be monomorphically represented by Int. There are some convenient functions to manipulate monomorphic types and functions. For more detail, see API documentation.

Metadata

Version

0.0.3.3

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