mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-07 10:12:51 -06:00
Eliminate mutual dependencies between the GF compiler and the PGF library
+ References to modules under src/compiler have been eliminated from the PGF library (under src/runtime/haskell). Only two functions had to be moved (from GF.Data.Utilities to PGF.Utilities) to make this possible, other apparent dependencies turned out to be vacuous. + In gf.cabal, the GF executable no longer directly depends on the PGF library source directory, but only on the exposed library modules. This means that there is less duplication in gf.cabal and that the 30 modules in the PGF library will no longer be compiled twice while building GF. To make this possible, additional PGF library modules have been exposed, even though they should probably be considered for internal use only. They could be collected in a PGF.Internal module, or marked as "unstable", to make this explicit. + Also, by using the -fwarn-unused-imports flag, ~220 redundant imports were found and removed, reducing the total number of imports by ~15%.
This commit is contained in:
20
src/runtime/haskell/PGF/Utilities.hs
Normal file
20
src/runtime/haskell/PGF/Utilities.hs
Normal file
@@ -0,0 +1,20 @@
|
||||
-- | Basic utilities
|
||||
module PGF.Utilities where
|
||||
import Data.Set(empty,member,insert)
|
||||
|
||||
|
||||
-- | Like 'nub', but O(n log n) instead of O(n^2), since it uses a set to lookup previous things.
|
||||
-- The result list is stable (the elements are returned in the order they occur), and lazy.
|
||||
-- Requires that the list elements can be compared by Ord.
|
||||
-- Code ruthlessly taken from http://hpaste.org/54411
|
||||
nub' :: Ord a => [a] -> [a]
|
||||
nub' = loop empty
|
||||
where loop _ [] = []
|
||||
loop seen (x : xs)
|
||||
| member x seen = loop seen xs
|
||||
| otherwise = x : loop (insert x seen) xs
|
||||
|
||||
|
||||
-- | Replace all occurences of an element by another element.
|
||||
replace :: Eq a => a -> a -> [a] -> [a]
|
||||
replace x y = map (\z -> if z == x then y else z)
|
||||
Reference in New Issue
Block a user