18 lines
596 B
Haskell
18 lines
596 B
Haskell
import Data.List( delete, nub, sort )
|
|
|
|
-- Remove the first part of xs from ys and then recurse.
|
|
difference (x:xs) ys = difference xs (delete x ys)
|
|
-- Once the list is empty we can just use y.
|
|
difference [] (y:_) = y
|
|
|
|
-- Get the count of some element x in xs.
|
|
count xs x = length [x' | x' <- xs, x' == x]
|
|
|
|
-- Return a list of all the frequencies for unique elements of xs.
|
|
frequencies xs = map (count xs) us where us = nub xs
|
|
|
|
-- If the frequency lists have the same elements,
|
|
-- they can be replaced. i.e., they are isomorphic.
|
|
isomorphic xs ys = sort (frequencies xs) == sort (frequencies ys)
|
|
|