MyNixOS website logo
Description

Ducktyped set interface for Haskell containers.

Please see the README on Github at https://github.com/athanclark/sets#readme

sets

This package provides overloaded terms, commonly used with set-like types, like Map and Set from containers. There are also unorthodox, mostly useless data types defined here - playing with ordering, uniqueness and finiteness.

Usage

The following actions are overloaded:

Binary Operators:

  • union
  • intersection
  • difference
  • complement

Top and Bottom Elements:

  • empty
  • total

Element-Wise Operations:

  • singleton
  • insert
  • delete

Metrics and Comparison:

  • size
  • isSubsetOf isProperSubsetOf

Each of the operations has their own typeclass. We have also made newtype wrappers for lists, for different restrictions:

  • Ordered Sets
    • Multiple
  • Unordered Sets
    • Unique
    • Multiple

This way, we can expect the following to work:

uniqueAppend :: Eq a => [a] -> [a] -> [a]
uniqueAppend xs ys = unUUSet $ fromFoldable xs `union` fromFoldable ys

orderedAppend :: Ord a => [a] -> [a] -> [a]
orderedAppend xs ys = unOMSet $ fromFoldable xs `union` fromFoldable ys

We've also made a few newtypes to encode our binary operations, for Monoid and Semigroup instances:

instance (HasUnion s, HasEmpty s) => Monoid (Union s) where
  mempty = empty
  mappend = union

Multiple Set Types

To use the overloaded terms, they need to be the only ones in scope. To make this correct, we need to import our container with caution:

import qualified Data.Set as Set
import Data.Map (Map) -- only the type name to designate behavior

foo :: Map
foo = x `union` y

bar :: Set.Set
bar = a `union` b

This way, we can keep our code more readable while still having set-like intuition.

Testing and Benchmarking

You can view the results here (warning: it's a 7MB text file - your browser will hate you)

The tests are built with QuickCheck - it's pretty easy to get them working for you:

cabal install --enable-tests
cabal test --show-details=always

(...or for the stack folk...)

stack build
stack test

To benchmark (it usually takes about 10 minutes on my laptop), run the command!

cabal install --enable-benchmarks
cabal bench

(...stiggitty-stack is co-wiggity-whack...)

stack build
stack bench --benchmark-arguments="--output profile.html"
Metadata

Version

0.0.6.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows