packages feed

lawful (empty) → 0.1.0.0

raw patch · 5 files changed

+138/−0 lines, 5 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Matt Noonan (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Matt Noonan nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,45 @@+# lawful: Assert that your typeclass instances are lawful++## What is this package for?++This small library provides a single two-parameter typeclass `Lawful c t`,+where `c` is a typeclass and `t` is a type. Declaring an instance of+`Lawful C T` is an assertion that "the instance for `C T` obeys the laws of+the class `C` (whatever *that* means!)"++For example, a lawful instance of `Eq T` should satisfy the reflexive+law `x == x` for all `x :: T`.  This is certainly true for most types, such+as `Int` or `[a]` when `Eq a` is lawful, so we can define++```haskell+Lawful Eq Int+Lawful Eq a => Lawful Eq [a]+```++But it *isn't* true for `Double`:++```+λ> nan = 0 / 0 :: Double+λ> nan == nan+False++```++## Why is there a `c t` constraint on `Lawful c t`?++This constraint lets you use a `Lawful c t` wherever a `c t` would be expected, +as in:++```haskell+same :: Lawful Eq a => a -> a -> Bool+same x y = x == y+```++## How do I know what laws are expected from a typeclass?++If everybody more-or-less agrees on what the right laws are, hopefully they bothered to+write them down somewhere. If they didn't, then sorry! You're on your own!++## Shouldn't all typeclass instances be lawful anyway, making this package useless?++Wouldn't that be nice?
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ lawful.cabal view
@@ -0,0 +1,26 @@+name:                lawful+version:             0.1.0.0+-- synopsis:+-- description:+homepage:            https://github.com/matt-noonan/lawful#readme+license:             BSD3+license-file:        LICENSE+author:              Matt Noonan+maintainer:          matt.noonan@gmail.com+copyright:           (c) 2018 Matt Noonan+category:            Safe+synopsis:            Assert the lawfulness of your typeclass instances.+description:         Assert the lawfulness of your typeclass instances.+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Lawful+  build-depends:       base >= 4.7 && < 5+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/matt-noonan/lawful
+ src/Lawful.hs view
@@ -0,0 +1,35 @@+{-# LANGUAGE MultiParamTypeClasses   #-}+{-# LANGUAGE FlexibleContexts        #-}+{-# LANGUAGE ConstraintKinds         #-}+{-# LANGUAGE UndecidableSuperClasses #-}++module Lawful (Lawful) where++-- | A `Lawful c t` instance asserts that the typeclass `c t`+--   obeys the expected laws of `c` (whatever that means).+class c t => Lawful c t++---------------------------------------------------------------------+--  Some lawful instances of `Eq`, `Ord`++-- Base types+instance Lawful Eq  Bool+instance Lawful Ord Bool++instance Lawful Eq  Int+instance Lawful Ord Int++instance Lawful Eq  Integer+instance Lawful Ord Integer++-- Lists+instance Lawful Eq  a => Lawful Eq [a]+instance Lawful Ord a => Lawful Ord [a]++-- Maybe+instance Lawful Eq  a => Lawful Eq  (Maybe a)+instance Lawful Ord a => Lawful Ord (Maybe a)++-- Either+instance (Lawful Eq  a, Lawful Eq  b) => Lawful Eq  (Either a b)+instance (Lawful Ord a, Lawful Ord b) => Lawful Ord (Either a b)