Add file
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
module Multiset where
|
||||
import qualified Data.Map.Strict as M
|
||||
import Control.Monad
|
||||
|
||||
powlistN :: Int -> [a] ->[[a]]
|
||||
powlistN _ [] = [[]]
|
||||
powlistN n (x:xs)
|
||||
| n <=0 = [[]]
|
||||
| otherwise = ((x:) <$> powlistN (n-1) xs) ++ powlistN n xs
|
||||
|
||||
-- exponential, so don't use it on long lists
|
||||
powlist :: [a] -> [[a]]
|
||||
powlist = filterM (const [True,False])
|
||||
|
||||
toMultiset :: Ord a => [a] -> M.Map a Int
|
||||
toMultiset = foldr (uncurry $ M.insertWith (+)) M.empty . map (,1)
|
||||
Reference in New Issue
Block a user