9import Control.Monad (foldM, guard, mzero, msum)
10import Control.Monad.Logic (LogicT, runLogicT, lift)
11import qualified Data.List as List
12import qualified Data.Map as Map
15import Elm.Package (Name, Version)
17import Deps.Explorer (Explorer)
18import qualified Deps.Explorer as Explorer
19import Elm.Project.Constraint (Constraint)
20import qualified Elm.Project.Constraint as Con
27solve :: Map Name Constraint -> Solver (Map Name Version)
29 mkSolver (State Map.empty cons)
36run :: Solver a -> Explorer (Maybe a)
38 runLogicT solver (const . return . Just) (return Nothing)
47 { _solution :: Map Name Version
48 , _unsolved :: Map Name Constraint
52mkSolver :: State -> Solver (Map Name Version)
53mkSolver (State solution unsolved) =
54 case Map.minViewWithKey unsolved of
58 Just ((name, constraint), otherUnsolved) ->
59 do allVersions <- lift $ Explorer.getVersions name
62 filter (Con.satisfies constraint) allVersions
64 let state1 = State solution otherUnsolved
65 state2 <- msum (map (addVersion state1 name) versions)
69addVersion :: State -> Name -> Version -> Solver State
70addVersion (State solution unsolved) name version =
71 do (Explorer.Info elm cons) <-
72 lift $ Explorer.getConstraints name version
74 guard (Con.goodElm elm)
75 newUnsolved <- foldM (addConstraint solution) unsolved (Map.toList cons)
76 return (State (Map.insert name version solution) newUnsolved)
79addConstraint :: Map Name Version -> Map Name Constraint -> (Name, Constraint) -> Solver (Map Name Constraint)
80addConstraint solution unsolved (name, newConstraint) =
81 case Map.lookup name solution of
83 if Con.satisfies newConstraint version then
89 case Map.lookup name unsolved of
91 return $ Map.insert name newConstraint unsolved
94 case Con.intersect oldConstraint newConstraint of
98 Just mergedConstraint ->
99 if oldConstraint == mergedConstraint then
102 return (Map.insert name mergedConstraint unsolved)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list