-------------------------------------------------------------------------------
-- Misc functions                                                            --
-------------------------------------------------------------------------------

-- | Finds a free discourse name (appends "_" at the end until free name found)
-- given the set of all discourse names
freeName :: (String, Int) -> Set NAME -> (NAME, Int)
freeName (s, i) ns =
    if Set.member n ns
       then freeName (s, i+1) ns
       else (n, i+1)
    where n = mkSimpleId (s++"_"++[intToDigit i])

-------------------------------------------------------------------------------
-- Functions to compute the set of individual constants (discourse items),   --
-- these work by recursing into all subelements                              --
-------------------------------------------------------------------------------

-- | maps @f@ to @ts@ and unifies the results
freeName :: (String, Int) -> Set NAME -> (NAME, Int)
freeName (s, i) ns =
    if Set.member n ns
       then freeName (s, i+1) ns
       else (n, i+1)
    where n = mkSimpleId (s++"_"++[intToDigit i])

-------------------------------------------------------------------------------
-- Functions to compute the set of individual constants (discourse items),   --
-- these work by recursing into all subelements                              --
-------------------------------------------------------------------------------

-- | maps @f@ to @ts@ and unifies the results
freeName (s, i) ns =
    if Set.member n ns
       then freeName (s, i+1) ns
       else (n, i+1)
    where n = mkSimpleId (s++"_"++[intToDigit i])

-------------------------------------------------------------------------------
-- Functions to compute the set of individual constants (discourse items),   --
-- these work by recursing into all subelements                              --
-------------------------------------------------------------------------------

-- | maps @f@ to @ts@ and unifies the results