{-# OPTIONS_GHC -fglasgow-exts #-}

module Data.Collection where

import qualified List

class Collection c v | c -> v where
    -- Query
    null :: c -> Bool
    size :: c -> Int
    
    null = (0 ==) . size
    size = List.length . toList

    -- Construction 
    empty     :: c 
    singleton :: v -> c

    empty       = fromList []
    singleton v = fromList [v]

    -- Manipulation
    insert :: v -> c -> c

    -- Conversion
    toList   :: c -> [v]
    fromList :: [v] -> c

    fromList = List.foldl (flip insert) empty

fromCollection :: (Collection c1 v, Collection c2 v) => c1 -> c2
fromCollection = fromList . toList

