Giter Site home page Giter Site logo

typenums's Introduction

typenums

Hackage Build status Windows build status BSD3 license

Type level numbers using existing Nat functionality. Uses kind-polymorphic typeclasses and type families to facilitate more general code compatible with existing code using type-level Naturals.

Usage

Import either Data.TypeNums or Data.TypeLits instead of GHC.TypeLits. Some definitions conflict with GHC.TypeLits, so if you really must import it, use an explicit import list.

This library is intended to be used in a kind-polymorphic way, such that a type-level integer parameter can be written as a natural, and a rational can be written as either of the other two. As an example:

{-# LANGUAGE PolyKinds #-}

data SomeType (n :: k) = SomeType

useSomeType :: KnownInt n => SomeType n -> _
useSomeType = -- ...

Syntax

  • Positive integers are written as natural numbers, as before. Optionally they can also be written as Pos n.
  • Negative integers are written as Neg n.
  • Ratios are written as n :% d, where n can be a natural number, Pos n, or Neg n, and d is a natural number.

Addition, subtraction and multiplication at type level are all given as infix operators with standard notation, and are compatible with any combination of the above types. Equality and comparison constraints are likewise available for any combination of the above types.

N.B. The equality constraint conflicts with that in Data.Type.Equality. The (==) operator from Data.Type.Equality is re-exported as (==?) from both Data.TypeNums and Data.TypeLits.

typenums's People

Contributors

adituv avatar robmurray98 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.