Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created October 6, 2010 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beastaugh/613472 to your computer and use it in GitHub Desktop.
Save beastaugh/613472 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Data.Set.Naive
( empty
, member
, subset
, properSubset
, superset
, properSuperset
, powerset
, showSet
) where
import Data.List (elem, foldl', subsequences)
import qualified Data.Text as T (pack, replace)
empty :: Eq a => [a] -> Bool
empty = (==[])
member :: Eq a => a -> [a] -> Bool
member = elem
subset :: Eq a => [a] -> [a] -> Bool
subset x y = x `member` powerset y
properSubset :: Eq a => [a] -> [a] -> Bool
properSubset x y = x `subset` y && x /= y
superset :: Eq a => [a] -> [a] -> Bool
superset x y = y `subset` x
properSuperset :: Eq a => [a] -> [a] -> Bool
properSuperset x y = x `superset` y && x /= y
powerset :: [a] -> [[a]]
powerset = subsequences
showSet = T.replace "]" "}" .
T.replace "[" "{" .
T.replace "[]" "0" .
T.pack . show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment