shayne-fletcher / ghc-lib-parser-ex

GHC API parse tree utilities
Other
10 stars 4 forks source link

Add function 'extensionImplications' #23

Closed shayne-fletcher closed 4 years ago

ndmitchell commented 4 years ago

Still super worried about the complexity!

import qualified Data.Map as Map
import Data.Tuple.Extra

implications :: [(String, Bool, String)]
implications = undefined

implicationsMap :: Map.Map String ([String], [String])
implicationsMap = Map.fromListWith f [(a, ([c | b], [c | not b])) | (a,b,c) <- implications]
    where f (x1,y1) (x2,y2) = (x1++x2, y1++y2)

That's much simper. Might require you lifting into your Ext type, or also going via the Show because you don't have Ord, but simpler and very definitely not O(n^2) or O(n^3) (I really worry about a find and a nub in the middle).

shayne-fletcher commented 4 years ago

Very nice.

shayne-fletcher commented 4 years ago

Thanks for the help and suggestions. Think this is about done. Want a last look?

shayne-fletcher commented 4 years ago

@ndmitchell I think this idea was why you suggested Data.Tuple.Extra?

    implicationsMap = Map.fromListWith (<>)
      [(show a, ([c | b], [c | not b]))
        | (a, flag, c) <- impliedXFlags, let b = flag == turnOn]

Seems to test out OK (use of <> -- not sure why/how it's in scope without Data.Tuple.Extra). Too cryptic?

Ah I see. It comes in via Prelude (up to 3-tuples).

ndmitchell commented 4 years ago

I was originally doing to do something like both (++) from Data.Tuple.Extra, but that's not quite right. Using <> seems fine.