This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from fantasyland/ord-experimental
adds ord
- Loading branch information
Showing
11 changed files
with
185 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const concat = (x, y) => x.concat(y); | ||
|
||
module.exports = concat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const concat = require('./concat'); | ||
|
||
const mconcat = (xs, empty) => xs.length ? xs.reduce(concat) : empty(); | ||
|
||
module.exports = mconcat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const {tagged} = require('daggy'); | ||
const {empty, of, concat, equals} = require('fantasy-land'); | ||
|
||
const Ord = M => { | ||
|
||
const _Ord = tagged('x'); | ||
|
||
_Ord[of] = _Ord; | ||
_Ord[Ord.min] = M[Ord.min]; | ||
_Ord[Ord.max] = M[Ord.max]; | ||
|
||
_Ord.prototype.compare = function(y) { | ||
return M.compare(this.x, y.x); | ||
}; | ||
_Ord.prototype[equals] = function(y) { | ||
return M.compare(this.x, y.x) === Ord.EQ; | ||
}; | ||
_Ord.prototype.lt = function(y) { | ||
return M.compare(this.x, y.x) === Ord.LT; | ||
}; | ||
_Ord.prototype.gt = function(y) { | ||
return M.compare(this.x, y.x) === Ord.GT; | ||
}; | ||
|
||
return _Ord; | ||
}; | ||
|
||
Ord.EQ = 0; | ||
Ord.GT = 1; | ||
Ord.LT = -1; | ||
|
||
Ord.compare = 'compare'; | ||
Ord.min = 'min'; | ||
Ord.max = 'max'; | ||
|
||
module.exports = Ord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const {adapters: {nodeunit: λ}} = require('fantasy-check'); | ||
const {identity} = require('fantasy-combinators'); | ||
|
||
const sʹ = require('fantasy-land/laws/setoid'); | ||
|
||
const {Ord} = require('../fantasy-monoids'); | ||
|
||
const Ordʹ = Ord({ min: () => undefined | ||
, max: () => undefined | ||
, compare: (x, y) => x === y ? Ord.EQ: x < y ? Ord.LT: Ord.GT | ||
}); | ||
|
||
|
||
exports.setoid = { | ||
|
||
'reflexivity': λ.law(sʹ.reflexivity)(Ordʹ.of), | ||
'symmetry': λ.law(sʹ.symmetry)(Ordʹ.of), | ||
'transitivity': λ.law(sʹ.transitivity)(Ordʹ.of) | ||
}; |