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

[ bsd3, data, deprecated, library ] [ Propose Tags ]
Deprecated in favor of singletons

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.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1.0, 0.0.1.1, 0.0.1.2, 0.0.2.0, 0.0.3.0, 0.0.3.1, 0.0.3.2, 0.0.3.3
Dependencies base (>=2.0 && <5) [details]
License BSD-3-Clause
Copyright (C) Hiromi ISHII 2013
Author Hiromi ISHII
Maintainer konn.jinro_at_gmail.com
Category Data
Home page https://github.com/konn/monomorphic
Source repo head: git clone git://github.com/konn/monomorphic.git
Uploaded by HiromiIshii at 2015-05-19T15:55:06Z
Distributions NixOS:0.0.3.3
Reverse Dependencies 5 direct, 13 indirect [details]
Downloads 7032 total (25 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-05-23 [all 1 reports]

Readme for monomorphic-0.0.3.3

[back to package description]

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.