congruence-relation (empty) → 0.1.0.0
raw patch · 4 files changed
+115/−0 lines, 4 filesdep +arraydep +basedep +containerssetup-changed
Dependencies added: array, base, containers
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- congruence-relation.cabal +19/−0
- src/Data/Congruence/Decidable.hs +74/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Jonathan Sterling++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ congruence-relation.cabal view
@@ -0,0 +1,19 @@+name: congruence-relation+version: 0.1.0.0+synopsis: Decidable congruence relations for Haskell: up to you whether this is a joke+description: The laws of 'Eq' only require that you have a decidable equivalence relation defined on a type; they do not force you to guarantee abstraction with respect to the relation, i.e. you can write anti-extensional operations without violating the laws. This package provides an alternative for when functionality with respect to an equivalence relation is desired.+license: MIT+license-file: LICENSE+author: Jonathan Sterling+maintainer: jon@jonmsterling.com+category: Data+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: Data.Congruence.Decidable+ build-depends: base >=4.7 && <4.8,+ containers >=0.5.5.0,+ array >=0.4.0.0+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Data/Congruence/Decidable.hs view
@@ -0,0 +1,74 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE UnicodeSyntax #-}++module Data.Congruence.Decidable where++import Data.Array+import Data.Int+import Data.Map+import Data.Sequence+import Data.Set+import Data.Tree+import Data.Word++-- | We define a congruence relation to be an equivalence relation which+-- satisfies the following functionality law for for @α,β ∷ *@, @m,n ∷ α@ and+-- @f ∷ α → β@:+--+-- @ 'Congruence' α, 'Eq' β, (m == n) true ⊢ (f m == f n) true @+--+-- One way to look at the 'Congruence' class is through the lens of setoids;+-- then it classifies those types for whom "being the domain of an operation"+-- and being the "domain of a function" are synonymous. Another way to look at+-- it is in the following sense: @'Congruence' α@ forces all functions out of+-- @α@ to be extensional.+--+-- But usually, when developing setoids, you have a separate type of functions+-- which respect value equivalence, and then every function has a proof+-- obligation; then the raw functions of the outer theory are "operations"+-- until they can be shown to be functional. This is tractable in type theory,+-- but in Haskell and ML, it is not: when we can, it is better to rely upon+-- data abstraction and composition to enforce our laws for us, so that proofs+-- come for free.+--+class Eq α ⇒ Congruence α where++instance Congruence α ⇒ Congruence [α]+instance Congruence α ⇒ Congruence (Maybe α)+instance (Congruence α, Congruence β) ⇒ Congruence (Either α β)++instance Congruence α ⇒ Congruence (Set α)+instance Congruence α ⇒ Congruence (Seq α)+instance Congruence α ⇒ Congruence (Tree α)+instance (Congruence α, Congruence β) ⇒ Congruence (Map α β)+instance (Ix i, Congruence i, Congruence α) ⇒ Congruence (Array i α)++instance Congruence ()+instance Congruence Bool+instance Congruence Char+instance Congruence Int+instance Congruence Int16+instance Congruence Int32+instance Congruence Int64+instance Congruence Int8+instance Congruence Integer+instance Congruence Ordering+instance Congruence Word+instance Congruence Word16+instance Congruence Word32+instance Congruence Word64+instance Congruence Word8++instance (Congruence a, Congruence b, Congruence c, Congruence d) ⇒ Congruence (a, b, c, d)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e) ⇒ Congruence (a, b, c, d, e)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f) ⇒ Congruence (a, b, c, d, e, f)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g) ⇒ Congruence (a, b, c, d, e, f, g)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h) ⇒ Congruence (a, b, c, d, e, f, g, h)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i) ⇒ Congruence (a, b, c, d, e, f, g, h, i)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i, Congruence j) ⇒ Congruence (a, b, c, d, e, f, g, h, i, j)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i, Congruence j, Congruence k) ⇒ Congruence (a, b, c, d, e, f, g, h, i, j, k)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i, Congruence j, Congruence k, Congruence l) ⇒ Congruence (a, b, c, d, e, f, g, h, i, j, k, l)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i, Congruence j, Congruence k, Congruence l, Congruence m) ⇒ Congruence (a, b, c, d, e, f, g, h, i, j, k, l, m)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i, Congruence j, Congruence k, Congruence l, Congruence m, Congruence n) ⇒ Congruence (a, b, c, d, e, f, g, h, i, j, k, l, m, n)+instance (Congruence a, Congruence b, Congruence c, Congruence d, Congruence e, Congruence f, Congruence g, Congruence h, Congruence i, Congruence j, Congruence k, Congruence l, Congruence m, Congruence n, Congruence o) ⇒ Congruence (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)+