From c34fdbcaa8a2259a1bf3cc9c87cf4e6e686c60e0 Mon Sep 17 00:00:00 2001 From: David Chambers Date: Sat, 18 Jan 2020 14:32:38 +0100 Subject: [PATCH] Version 0.21.0 --- LICENSE | 2 +- README.md | 176 +++++++++++++++++++++++++++++---------------------- index.js | 2 +- package.json | 2 +- 4 files changed, 104 insertions(+), 78 deletions(-) diff --git a/LICENSE b/LICENSE index 5e1249c..1adbe02 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Sanctuary +Copyright (c) 2020 Sanctuary Copyright (c) 2016 Plaid Technologies, Inc. Permission is hereby granted, free of charge, to any person diff --git a/README.md b/README.md index ad1305f..89b241f 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Conceptually, a type is a set of values. One can think of a value of type `Type` as a function of type `Any -> Boolean` that tests values for membership in the set (though this is an oversimplification). -#### `Unknown :: Type` +#### `Unknown :: Type` Type used to represent missing type information. The type of `[]`, for example, is `Array ???`. @@ -190,67 +190,75 @@ to include an infinite number of types in an environment: - `List (List (List String))` - `...` -#### `Any :: Type` +#### `Void :: Type` + +Uninhabited type. + +May be used to convey that a type parameter of an algebraic data type +will not be used. For example, a future of type `Future Void String` +will never be rejected. + +#### `Any :: Type` Type comprising every JavaScript value. -#### `AnyFunction :: Type` +#### `AnyFunction :: Type` Type comprising every Function value. -#### `Arguments :: Type` +#### `Arguments :: Type` Type comprising every [`arguments`][arguments] object. -#### `Array :: Type -⁠> Type` +#### `Array :: Type -⁠> Type` Constructor for homogeneous Array types. -#### `Array0 :: Type` +#### `Array0 :: Type` Type whose sole member is `[]`. -#### `Array1 :: Type -⁠> Type` +#### `Array1 :: Type -⁠> Type` Constructor for singleton Array types. -#### `Array2 :: Type -⁠> Type -⁠> Type` +#### `Array2 :: Type -⁠> Type -⁠> Type` Constructor for heterogeneous Array types of length 2. `['foo', true]` is a member of `Array2 String Boolean`. -#### `Boolean :: Type` +#### `Boolean :: Type` Type comprising `true` and `false`. -#### `Date :: Type` +#### `Date :: Type` Type comprising every Date value. -#### `ValidDate :: Type` +#### `ValidDate :: Type` Type comprising every [`Date`][] value except `new Date (NaN)`. -#### `Descending :: Type -⁠> Type` +#### `Descending :: Type -⁠> Type` [Descending][] type constructor. -#### `Either :: Type -⁠> Type -⁠> Type` +#### `Either :: Type -⁠> Type -⁠> Type` [Either][] type constructor. -#### `Error :: Type` +#### `Error :: Type` Type comprising every Error value, including values of more specific constructors such as [`SyntaxError`][] and [`TypeError`][]. -#### `Fn :: Type -⁠> Type -⁠> Type` +#### `Fn :: Type -⁠> Type -⁠> Type` Binary type constructor for unary function types. `$.Fn (I) (O)` represents `I -> O`, the type of functions that take a value of type `I` and return a value of type `O`. -#### `Function :: NonEmpty (Array Type) -⁠> Type` +#### `Function :: NonEmpty (Array Type) -⁠> Type` Constructor for Function types. @@ -260,93 +268,108 @@ Examples: type; and - `$.Function ([a, b, a])` represents the `(a, b) -> a` type. -#### `HtmlElement :: Type` +#### `HtmlElement :: Type` Type comprising every [HTML element][]. -#### `Identity :: Type -⁠> Type` +#### `Identity :: Type -⁠> Type` [Identity][] type constructor. -#### `Maybe :: Type -⁠> Type` +#### `JsMap :: Type -⁠> Type -⁠> Type` + +Constructor for native Map types. `$.JsMap ($.Number) ($.String)`, +for example, is the type comprising every native Map whose keys are +numbers and whose values are strings. + +#### `JsSet :: Type -⁠> Type` + +Constructor for native Set types. `$.JsSet ($.Number)`, for example, +is the type comprising every native Set whose values are numbers. + +#### `Maybe :: Type -⁠> Type` [Maybe][] type constructor. -#### `NonEmpty :: Type -⁠> Type` +#### `Module :: Type` + +Type comprising every ES module. + +#### `NonEmpty :: Type -⁠> Type` Constructor for non-empty types. `$.NonEmpty ($.String)`, for example, is the type comprising every [`String`][] value except `''`. The given type must satisfy the [Monoid][] and [Setoid][] specifications. -#### `Null :: Type` +#### `Null :: Type` Type whose sole member is `null`. -#### `Nullable :: Type -⁠> Type` +#### `Nullable :: Type -⁠> Type` Constructor for types that include `null` as a member. -#### `Number :: Type` +#### `Number :: Type` Type comprising every primitive Number value (including `NaN`). -#### `PositiveNumber :: Type` +#### `PositiveNumber :: Type` Type comprising every [`Number`][] value greater than zero. -#### `NegativeNumber :: Type` +#### `NegativeNumber :: Type` Type comprising every [`Number`][] value less than zero. -#### `ValidNumber :: Type` +#### `ValidNumber :: Type` Type comprising every [`Number`][] value except `NaN`. -#### `NonZeroValidNumber :: Type` +#### `NonZeroValidNumber :: Type` Type comprising every [`ValidNumber`][] value except `0` and `-0`. -#### `FiniteNumber :: Type` +#### `FiniteNumber :: Type` Type comprising every [`ValidNumber`][] value except `Infinity` and `-Infinity`. -#### `NonZeroFiniteNumber :: Type` +#### `NonZeroFiniteNumber :: Type` Type comprising every [`FiniteNumber`][] value except `0` and `-0`. -#### `PositiveFiniteNumber :: Type` +#### `PositiveFiniteNumber :: Type` Type comprising every [`FiniteNumber`][] value greater than zero. -#### `NegativeFiniteNumber :: Type` +#### `NegativeFiniteNumber :: Type` Type comprising every [`FiniteNumber`][] value less than zero. -#### `Integer :: Type` +#### `Integer :: Type` Type comprising every integer in the range [[`Number.MIN_SAFE_INTEGER`][min] .. [`Number.MAX_SAFE_INTEGER`][max]]. -#### `NonZeroInteger :: Type` +#### `NonZeroInteger :: Type` Type comprising every [`Integer`][] value except `0` and `-0`. -#### `NonNegativeInteger :: Type` +#### `NonNegativeInteger :: Type` Type comprising every non-negative [`Integer`][] value (including `-0`). Also known as the set of natural numbers under ISO 80000-2:2009. -#### `PositiveInteger :: Type` +#### `PositiveInteger :: Type` Type comprising every [`Integer`][] value greater than zero. -#### `NegativeInteger :: Type` +#### `NegativeInteger :: Type` Type comprising every [`Integer`][] value less than zero. -#### `Object :: Type` +#### `Object :: Type` Type comprising every "plain" Object value. Specifically, values created via: @@ -356,38 +379,38 @@ created via: - the `new` operator in conjunction with `Object` or a custom constructor function. -#### `Pair :: Type -⁠> Type -⁠> Type` +#### `Pair :: Type -⁠> Type -⁠> Type` [Pair][] type constructor. -#### `RegExp :: Type` +#### `RegExp :: Type` Type comprising every RegExp value. -#### `GlobalRegExp :: Type` +#### `GlobalRegExp :: Type` Type comprising every [`RegExp`][] value whose `global` flag is `true`. See also [`NonGlobalRegExp`][]. -#### `NonGlobalRegExp :: Type` +#### `NonGlobalRegExp :: Type` Type comprising every [`RegExp`][] value whose `global` flag is `false`. See also [`GlobalRegExp`][]. -#### `StrMap :: Type -⁠> Type` +#### `StrMap :: Type -⁠> Type` Constructor for homogeneous Object types. `{foo: 1, bar: 2, baz: 3}`, for example, is a member of `StrMap Number`; `{foo: 1, bar: 2, baz: 'XXX'}` is not. -#### `String :: Type` +#### `String :: Type` Type comprising every primitive String value. -#### `RegexFlags :: Type` +#### `RegexFlags :: Type` Type comprising the canonical RegExp flags: @@ -400,23 +423,23 @@ Type comprising the canonical RegExp flags: - `'im'` - `'gim'` -#### `Symbol :: Type` +#### `Symbol :: Type` Type comprising every Symbol value. -#### `Type :: Type` +#### `Type :: Type` Type comprising every `Type` value. -#### `TypeClass :: Type` +#### `TypeClass :: Type` Type comprising every [`TypeClass`][] value. -#### `Undefined :: Type` +#### `Undefined :: Type` Type whose sole member is `undefined`. -#### `env :: Array Type` +#### `env :: Array Type` An array of [types][]: @@ -432,7 +455,10 @@ An array of [types][]: - [Fn](#Fn) ([Unknown][]) ([Unknown][]) - [HtmlElement](#HtmlElement) - [Identity](#Identity) ([Unknown][]) + - [JsMap](#JsMap) ([Unknown][]) ([Unknown][]) + - [JsSet](#JsSet) ([Unknown][]) - [Maybe](#Maybe) ([Unknown][]) + - [Module](#Module) - [Null](#Null) - [Number](#Number) - [Object](#Object) @@ -445,7 +471,7 @@ An array of [types][]: - [TypeClass](#TypeClass) - [Undefined](#Undefined) -#### `test :: Array Type -⁠> Type -⁠> a -⁠> Boolean` +#### `test :: Array Type -⁠> Type -⁠> a -⁠> Boolean` Takes an environment, a type, and any value. Returns `true` if the value is a member of the type; `false` otherwise. @@ -457,7 +483,7 @@ The environment is only significant if the type contains sanctuary-def provides several functions for defining types. -#### `NullaryType :: String -⁠> String -⁠> Array Type -⁠> (Any -⁠> Boolean) -⁠> Type` +#### `NullaryType :: String -⁠> String -⁠> Array Type -⁠> (Any -⁠> Boolean) -⁠> Type` Type constructor for types with no type variables (such as [`Number`][]). @@ -530,7 +556,7 @@ rem (42) (0); // See http://example.com/my-package#NonZeroInteger for information about the NonZeroInteger type. ``` -#### `UnaryType :: Foldable f => String -⁠> String -⁠> Array Type -⁠> (Any -⁠> Boolean) -⁠> (t a -⁠> f a) -⁠> Type -⁠> Type` +#### `UnaryType :: Foldable f => String -⁠> String -⁠> Array Type -⁠> (Any -⁠> Boolean) -⁠> (t a -⁠> f a) -⁠> Type -⁠> Type` Type constructor for types with one type variable (such as [`Array`][]). @@ -557,30 +583,30 @@ For example: const show = require ('sanctuary-show'); const type = require ('sanctuary-type-identifiers'); -// MaybeTypeRep :: TypeRep Maybe -const MaybeTypeRep = {'@@type': 'my-package/Maybe'}; +// maybeTypeIdent :: String +const maybeTypeIdent = 'my-package/Maybe'; // Maybe :: Type -> Type const Maybe = $.UnaryType ('Maybe') ('http://example.com/my-package#Maybe') ([]) - (x => type (x) === MaybeTypeRep['@@type']) + (x => type (x) === maybeTypeIdent) (maybe => maybe.isJust ? [maybe.value] : []); // Nothing :: Maybe a const Nothing = { - 'constructor': MaybeTypeRep, 'isJust': false, 'isNothing': true, + '@@type': maybeTypeIdent, '@@show': () => 'Nothing', }; // Just :: a -> Maybe a const Just = x => ({ - 'constructor': MaybeTypeRep, 'isJust': true, 'isNothing': false, + '@@type': maybeTypeIdent, '@@show': () => `Just (${show (x)})`, 'value': x, }); @@ -612,7 +638,7 @@ fromMaybe (0) (Just ('XXX')); // Since there is no type of which all the above values are members, the type-variable constraint has been violated. ``` -#### `BinaryType :: Foldable f => String -⁠> String -⁠> Array Type -⁠> (Any -⁠> Boolean) -⁠> (t a b -⁠> f a) -⁠> (t a b -⁠> f b) -⁠> Type -⁠> Type -⁠> Type` +#### `BinaryType :: Foldable f => String -⁠> String -⁠> Array Type -⁠> (Any -⁠> Boolean) -⁠> (t a b -⁠> f a) -⁠> (t a b -⁠> f b) -⁠> Type -⁠> Type -⁠> Type` Type constructor for types with two type variables (such as [`Array2`][]). @@ -644,15 +670,15 @@ For example: ```javascript const type = require ('sanctuary-type-identifiers'); -// PairTypeRep :: TypeRep Pair -const PairTypeRep = {'@@type': 'my-package/Pair'}; +// pairTypeIdent :: String +const pairTypeIdent = 'my-package/Pair'; // $Pair :: Type -> Type -> Type const $Pair = $.BinaryType ('Pair') ('http://example.com/my-package#Pair') ([]) - (x => type (x) === PairTypeRep['@@type']) + (x => type (x) === pairTypeIdent) (({fst}) => [fst]) (({snd}) => [snd]); @@ -662,9 +688,9 @@ def ('Pair') ({}) ([a, b, $Pair (a) (b)]) (fst => snd => ({ - 'constructor': PairTypeRep, 'fst': fst, 'snd': snd, + '@@type': pairTypeIdent, '@@show': () => `Pair (${show (fst)}) (${show (snd)})`, })); @@ -709,7 +735,7 @@ showCard (Pair ('X') ('♠')); // See http://example.com/my-package#Rank for information about the Rank type. ``` -#### `EnumType :: String -⁠> String -⁠> Array Any -⁠> Type` +#### `EnumType :: String -⁠> String -⁠> Array Any -⁠> Type` Type constructor for [enumerated types][] (such as [`RegexFlags`][]). @@ -731,7 +757,7 @@ const Denomination = $.EnumType ([10, 20, 50, 100, 200]); ``` -#### `RecordType :: StrMap Type -⁠> Type` +#### `RecordType :: StrMap Type -⁠> Type` `RecordType` is used to construct anonymous record types. The type definition specifies the name and type of each required field. A field is @@ -784,7 +810,7 @@ dist (0); // The value at position 1 is not a member of ‘{ x :: FiniteNumber, y :: FiniteNumber }’. ``` -#### `NamedRecordType :: NonEmpty String -⁠> String -⁠> Array Type -⁠> StrMap Type -⁠> Type` +#### `NamedRecordType :: NonEmpty String -⁠> String -⁠> Array Type -⁠> StrMap Type -⁠> Type` `NamedRecordType` is used to construct named record types. The type definition specifies the name and type of each required field. A field is @@ -841,7 +867,7 @@ volume ({radius: 2}); // See http://example.com/my-package#Cylinder for information about the Cylinder type. ``` -#### `TypeVariable :: String -⁠> Type` +#### `TypeVariable :: String -⁠> Type` Polymorphism is powerful. Not being able to define a function for all types would be very limiting indeed: one couldn't even define the @@ -898,7 +924,7 @@ cmp (0) ('1'); // Since there is no type of which all the above values are members, the type-variable constraint has been violated. ``` -#### `UnaryTypeVariable :: String -⁠> Type -⁠> Type` +#### `UnaryTypeVariable :: String -⁠> Type -⁠> Type` Combines [`UnaryType`][] and [`TypeVariable`][]. @@ -945,7 +971,7 @@ example, is `v`. One could replace `Functor => f` with `Map k` or with This shallow inspection makes it possible to constrain a value's "outer" and "inner" types independently. -#### `BinaryTypeVariable :: String -⁠> Type -⁠> Type -⁠> Type` +#### `BinaryTypeVariable :: String -⁠> Type -⁠> Type -⁠> Type` Combines [`BinaryType`][] and [`TypeVariable`][]. @@ -960,12 +986,12 @@ To define a binary type variable `t a b` one must provide: The more detailed explanation of [`UnaryTypeVariable`][] also applies to `BinaryTypeVariable`. -#### `Thunk :: Type -⁠> Type` +#### `Thunk :: Type -⁠> Type` `$.Thunk (T)` is shorthand for `$.Function ([T])`, the type comprising every nullary function (thunk) that returns a value of type `T`. -#### `Predicate :: Type -⁠> Type` +#### `Predicate :: Type -⁠> Type` `$.Predicate (T)` is shorthand for `$.Fn (T) ($.Boolean)`, the type comprising every predicate function that takes a value of type `T`. @@ -1059,14 +1085,14 @@ concat (null) (null); Multiple constraints may be placed on a type variable by including multiple `TypeClass` values in the array (e.g. `{a: [Foo, Bar, Baz]}`). -[Descending]: https://github.com/sanctuary-js/sanctuary-descending/tree/v1.2.0 -[Either]: https://github.com/sanctuary-js/sanctuary-either/tree/v1.2.0 +[Descending]: https://github.com/sanctuary-js/sanctuary-descending/tree/v2.0.0 +[Either]: https://github.com/sanctuary-js/sanctuary-either/tree/v2.0.0 [FL:Semigroup]: https://github.com/fantasyland/fantasy-land#semigroup [HTML element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element -[Identity]: https://github.com/sanctuary-js/sanctuary-identity/tree/v1.2.0 -[Maybe]: https://github.com/sanctuary-js/sanctuary-maybe/tree/v1.2.0 +[Identity]: https://github.com/sanctuary-js/sanctuary-identity/tree/v2.0.0 +[Maybe]: https://github.com/sanctuary-js/sanctuary-maybe/tree/v2.0.0 [Monoid]: https://github.com/fantasyland/fantasy-land#monoid -[Pair]: https://github.com/sanctuary-js/sanctuary-pair/tree/v1.2.0 +[Pair]: https://github.com/sanctuary-js/sanctuary-pair/tree/v2.0.0 [Setoid]: https://github.com/fantasyland/fantasy-land#setoid [Unknown]: #Unknown [`Array`]: #Array diff --git a/index.js b/index.js index 717185e..5b049c5 100644 --- a/index.js +++ b/index.js @@ -497,7 +497,7 @@ // functionUrl :: String -> String function functionUrl(name) { - var version = '0.20.1'; // updated programmatically + var version = '0.21.0'; // updated programmatically return 'https://github.com/sanctuary-js/sanctuary-def/tree/v' + version + '#' + name; } diff --git a/package.json b/package.json index 7111955..aa64a6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sanctuary-def", - "version": "0.20.1", + "version": "0.21.0", "description": "Run-time type system for JavaScript", "license": "MIT", "repository": {