packages feed

uniform-algebras (empty) → 0.1.0

raw patch · 7 files changed

+295/−0 lines, 7 filesdep +basesetup-changed

Dependencies added: base

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+0.0.10+    updating 0.0.9 versions in Workspace8 2019 for submission+    cleaned up (mostly)
+ README.md view
@@ -0,0 +1,25 @@+ ++# The uniform-algebras package +contains a few simplistic algebras, e.g.+- a zero which is not even a semigroup to be widely usable as a generic "nothing"; it is attempted to allow automatic instantiation (under construction),+- a ListForm class, which is a monoid and has generic operations to make and append to a list. +- a collection of operations for "pointless" code writing, especially tuples with 4 or 5 elements.++This is a starter package, with no dependencies except for base, other uniform packages will build on it.++# Pointers to somewhat related things: +- [uniform-pair](https://hackage.haskell.org/package/uniform-pair-0.1.15)+- [basement](https://hackage.haskell.org/package/basement) ++# Intension of "uniform" packages+The "uniform" packages are yet another attempt to select a useful subset from the overwhelming variety of the Haskell biotop. It was started in the 2010, grew over the years but was never packaged and put into Hackage; it is comparable to other similar attempts from which it has learned and occasionally copied code. ++The "uniform" approach is different from some others by:+- compatible with 'standard' Haskell, i.e. Haskell 2010 plus extensions as indicated in the modules,+- use the regular Haskell prelude,+- avoid name clashes as far as possible,+- combine logically connected operations in one place and in a form allowing coordinated use.++Issues with this approach: it is limited by the deeps of understanding of Haskell of the authors and his experience. It shows a focus on understanding semantics (and formal ontology) linked to algebra applied to practical problems (Geographic Information Systems). +It seems that efforts to construct coherent subsets of Haskell are limited by the complexity of the task -- the more comprehensive an environment should be the more complex is it to learn and use. The approach here is what emerged after some 25 years of using Haskell to write application oriented code, mostly to demonstrate theories in spatial information theory. 
+ Setup.lhs view
@@ -0,0 +1,6 @@+#!/usr/bin/runhaskell +> module Main where+> import Distribution.Simple+> main :: IO ()+> main = defaultMain+
+ Uniform/ListForm.hs view
@@ -0,0 +1,29 @@+---------------------------------------------------------------------+---Module      :   ListForms+-- a naive and simple data type for monoids+-- somewhat the minimum often used without much baggage+--+----------------------------------------------------------------------+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE TypeFamilies #-}++{-# OPTIONS -Wall #-}++module Uniform.ListForm+  ( module Uniform.ListForm,+    module Uniform.Zero +  )+where++import Uniform.Zero ( Zeros )++class (Monoid l, Zeros (LF l)) => ListForms l where+  type LF l+  prependOne :: LF l -> l -> l+  appendOne :: l -> LF l -> l+  mkOne :: LF l -> l+  appendTwo :: l -> l -> l++  prependOne a la = appendTwo (mkOne a) la+  appendOne la a = appendTwo la (mkOne a)+  appendTwo = error "not implemented appendTwo for ListForm (<>)"
+ Uniform/Pointless.hs view
@@ -0,0 +1,87 @@+---------------------------------------------------------------------+--+-- Module      :  Uniform.Pointless+--              collecting some of the operations used in+--              the book by+--              Bird \& deMoore \"The Algebra of Programming\"+----------------------------------------------------------------------++module Uniform.Pointless (module Uniform.Pointless) where++pair :: (t -> b) -> (t, t) -> (b, b)+pair f (a, b) = (f a, f b)++cross :: (t1 -> a, t2 -> b) -> (t1, t2) -> (a, b)+cross (f, g) (a, b) = (f a, g b)++swapPair :: (b, a) -> (a, b)+swapPair (a, b) = (b, a)++first :: (t -> a) -> (t, b) -> (a, b)+first f (a, b) = (f a, b)++second :: (t -> b) -> (a, t) -> (a, b)+second f (a, b) = (a, f b)++fst3 :: (a, b, c) -> a+fst3 (x, y, z) = x++snd3 :: (a, b, c) -> b+snd3 (x, y, z) = y++trd3 :: (a, b, c) -> c+trd3 (x, y, z) = z++fst4 :: (a, b, c, d) -> a+fst4 (x, y, z, w) = x++snd4 :: (a, b, c, d) -> b+snd4 (x, y, z, w) = y++trd4 :: (a, b, c, d) -> c+trd4 (x, y, z, w) = z++thd4 :: (a, b, c, d) -> c+thd4 = trd4++fth4 :: (a, b, c, d) -> d+fth4 (x, y, z, w) = w++fst5 :: (a, b, c, d, e) -> a+fst5 (x, y, z, w, u) = x++snd5 :: (a, b, c, d, e) -> b+snd5 (x, y, z, w, u) = y++thd5 :: (a, b, c, d, e) -> c+thd5 (x, y, z, w, u) = z++trd5 :: (a, b, c, d, e) -> c+trd5 = thd5++fth5 :: (a, b, c, d, e) -> d+fth5 (x, y, z, w, u) = w++ffh5 :: (a, b, c, d, e) -> e+ffh5 (x, y, z, w, u) = u++first3 :: (a1 -> b) -> (a1, a2, a3) -> (b, a2, a3)+first3 f (a1, a2, a3) = (f a1, a2, a3)++second3 :: (a2 -> b) -> (a1, a2, a3) -> (a1, b, a3)+second3 f (a1, a2, a3) = (a1, f a2, a3)++third3 :: (a3 -> b) -> (a1, a2, a3) -> (a1, a2, b)+third3 f (a1, a2, a3) = (a1, a2, f a3)++first4 :: (a1 -> b) -> (a1, a2, a3, a4) -> (b, a2, a3, a4)+first4 f (a1, a2, a3, a4) = (f a1, a2, a3, a4)++second4 :: (a2 -> b) -> (a1, a2, a3, a4) -> (a1, b, a3, a4)+second4 f (a1, a2, a3, a4) = (a1, f a2, a3, a4)++third4 :: (a3 -> b) -> (a1, a2, a3, a4) -> (a1, a2, b, a4)+third4 f (a1, a2, a3, a4) = (a1, a2, f a3, a4)++fourth4 :: (a4 -> b) -> (a1, a2, a3, a4) -> (a1, a2, a3, b)+fourth4 f (a1, a2, a3, a4) = (a1, a2, a3, f a4)
+ Uniform/Zero.hs view
@@ -0,0 +1,100 @@+---------------------------------------------------------------------+---Module      :   Zeros+--      a naive and simple data type+--      usable to stand in for most kinds of nothing+--      added Either and Maybe to import wherever needed+--+----------------------------------------------------------------------+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE DefaultSignatures #-}+{-# LANGUAGE TypeOperators #-}++{-# OPTIONS -Wall #-}++module Uniform.Zero+  ( module Uniform.Zero,+    module Data.Maybe,+    module Data.Either,+    -- module GHC.Generics,+  )+where++import Data.Either+  ( Either (..),+    either,+    fromLeft,+    fromRight,+    isLeft,+    isRight,+    lefts,+    partitionEithers,+    rights,+  )+import Data.Maybe+  ( Maybe (..),+    catMaybes,+    fromJust,+    fromMaybe,+    isJust,+    isNothing,+    listToMaybe,+    mapMaybe,+    maybe,+    maybeToList,+  )+import GHC.Generics++-- | a minimal algebraic type with nothing than an identity+--  useful to identify a specific value in a type+class Zeros z where+  zero :: z+  default zero :: (Generic z, GZero (Rep z)) => z+  zero = to gzero++  isZero, notZero :: Eq z => z -> Bool+  isZero z = zero == z+  notZero = not . isZero++class GZero a where+  gzero :: a x++instance GZero U1 where+  gzero = U1++instance Zeros a => GZero (K1 i a) where+  gzero = K1 zero++instance (GZero a, GZero b) => GZero (a :*: b) where+  gzero = gzero :*: gzero++instance GZero a => GZero (M1 i c a) where+  gzero = M1 gzero++instance Zeros Char where zero = ' '++instance Zeros () where zero = ()++instance Zeros Bool where zero = False++-- is this contrary to the Unix tradition?++instance Zeros Int where zero = 0++instance Zeros [a] where zero = []++instance (Zeros a, Zeros b) => Zeros (a, b) where zero = (zero, zero)++instance (Zeros a, Zeros b, Zeros c) => Zeros (a, b, c) where+  zero = (zero, zero, zero)++instance (Zeros a, Zeros b, Zeros c, Zeros d) => Zeros (a, b, c, d) where+  zero = (zero, zero, zero, zero)++instance+  (Zeros a, Zeros b, Zeros c, Zeros d, Zeros e) =>+  Zeros (a, b, c, d, e)+  where+  zero = (zero, zero, zero, zero, zero)++instance Zeros (Maybe a) where zero = Nothing
+ uniform-algebras.cabal view
@@ -0,0 +1,45 @@+cabal-version: 2.2++-- This file has been generated from package.yaml by hpack version 0.34.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: d5063147a590e342c7a089d4c99da9a156918b76b109cb499cfe5b0d26b3e716++name:           uniform-algebras+version:        0.1.0+synopsis:       Pointless functions and a simplistic zero and monoid+description:    Simple algebras avoiding too much mathematical underpinning+                .+                - zero with test isZero, notZero (not a semigroupoid)+                      exports also Maybe and Either+                .+                - pointless operations, e.g. tuples up to 4 or 5  +                .+                - ListForms (a monoid)+                .+                Please see the README on GitHub at <https://github.com/andrewufrank/uniform-algebras/readme>+category:       Algebra Uniform+bug-reports:    https://github.com/andrewufrank/uniform-algebras/issues+author:         Andrew Frank+maintainer:     Andrew U. Frank <uniform@gerastree.at>+copyright:      2021 Andrew U. Frank+license:        GPL-2.0-only+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++library+  exposed-modules:+      Uniform.ListForm+      Uniform.Pointless+      Uniform.Zero+  autogen-modules: Paths_uniform_algebras+  other-modules:+      Paths_uniform_algebras+  hs-source-dirs:+      ./.+  build-depends:+      base >=4.7 && <5+  default-language: Haskell2010