From 1f85cf29531a49900ca97488565df7cf826ce2b6 Mon Sep 17 00:00:00 2001 From: Decio Ferreira Date: Tue, 10 Dec 2024 23:19:53 +0000 Subject: [PATCH] move System.IO into using Dict instead of Data.Map --- src/System/IO.elm | 130 +++++++++++++++++++++--------------------- src/Terminal/Repl.elm | 27 ++++----- src/Utils/Main.elm | 57 +++++++++--------- 3 files changed, 108 insertions(+), 106 deletions(-) diff --git a/src/System/IO.elm b/src/System/IO.elm index 69e34bfc9..acda3e0dc 100644 --- a/src/System/IO.elm +++ b/src/System/IO.elm @@ -75,7 +75,7 @@ port module System.IO exposing -} import Codec.Archive.Zip as Zip -import Data.Map as Dict exposing (Dict) +import Dict exposing (Dict) import Json.Encode as Encode import Utils.Crash exposing (crash) @@ -102,7 +102,7 @@ run app = { realWorld = { args = flags.args , currentDirectory = flags.currentDirectory - , envVars = Dict.fromList identity flags.envVars + , envVars = Dict.fromList flags.envVars , homedir = flags.homedir , progName = flags.progName , state = initialReplState @@ -146,7 +146,7 @@ run app = type alias Model = { realWorld : RealWorld - , next : Dict Int Int Next + , next : Dict Int Next } @@ -240,31 +240,31 @@ update msg model = |> Tuple.mapSecond (\cmd -> Cmd.batch [ updatedCmd, cmd ]) ( newRealWorld, GetLine next ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (GetLineNext next) model.next }, sendGetLine index ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (GetLineNext next) model.next }, sendGetLine index ) ( newRealWorld, HPutStr next (Handle fd) content ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (HPutLineNext next) model.next }, sendHPutStr { index = index, fd = fd, content = content } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (HPutLineNext next) model.next }, sendHPutStr { index = index, fd = fd, content = content } ) ( newRealWorld, WriteString next path content ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (WriteStringNext next) model.next }, sendWriteString { index = index, path = path, content = content } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (WriteStringNext next) model.next }, sendWriteString { index = index, path = path, content = content } ) ( newRealWorld, Read next fd ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ReadNext next) model.next }, sendRead { index = index, fd = fd } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ReadNext next) model.next }, sendRead { index = index, fd = fd } ) ( newRealWorld, HttpFetch next method urlStr headers ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (HttpFetchNext next) model.next }, sendHttpFetch { index = index, method = method, urlStr = urlStr, headers = headers } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (HttpFetchNext next) model.next }, sendHttpFetch { index = index, method = method, urlStr = urlStr, headers = headers } ) ( newRealWorld, GetArchive next method url ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (GetArchiveNext next) model.next }, sendGetArchive { index = index, method = method, url = url } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (GetArchiveNext next) model.next }, sendGetArchive { index = index, method = method, url = url } ) ( newRealWorld, HttpUpload next urlStr headers parts ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (HttpUploadNext next) model.next }, sendHttpUpload { index = index, urlStr = urlStr, headers = headers, parts = parts } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (HttpUploadNext next) model.next }, sendHttpUpload { index = index, urlStr = urlStr, headers = headers, parts = parts } ) ( newRealWorld, HFlush next (Handle fd) ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (HFlushNext next) model.next }, sendHFlush { index = index, fd = fd } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (HFlushNext next) model.next }, sendHFlush { index = index, fd = fd } ) ( newRealWorld, WithFile next path mode ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (WithFileNext next) model.next } + ( { model | realWorld = newRealWorld, next = Dict.insert index (WithFileNext next) model.next } , sendWithFile { index = index , path = path @@ -285,79 +285,79 @@ update msg model = ) ( newRealWorld, HFileSize next (Handle fd) ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (HFileSizeNext next) model.next }, sendHFileSize { index = index, fd = fd } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (HFileSizeNext next) model.next }, sendHFileSize { index = index, fd = fd } ) ( newRealWorld, ProcWithCreateProcess next createProcess ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ProcWithCreateProcessNext next) model.next }, sendProcWithCreateProcess { index = index, createProcess = createProcess } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ProcWithCreateProcessNext next) model.next }, sendProcWithCreateProcess { index = index, createProcess = createProcess } ) ( newRealWorld, HClose next (Handle fd) ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (HCloseNext next) model.next }, sendHClose { index = index, fd = fd } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (HCloseNext next) model.next }, sendHClose { index = index, fd = fd } ) ( newRealWorld, ProcWaitForProcess next ph ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ProcWaitForProcessNext next) model.next }, sendProcWaitForProcess { index = index, ph = ph } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ProcWaitForProcessNext next) model.next }, sendProcWaitForProcess { index = index, ph = ph } ) ( newRealWorld, ExitWith next code ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ExitWithNext next) model.next }, sendExitWith code ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ExitWithNext next) model.next }, sendExitWith code ) ( newRealWorld, DirFindExecutable next name ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirFindExecutableNext next) model.next }, sendDirFindExecutable { index = index, name = name } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirFindExecutableNext next) model.next }, sendDirFindExecutable { index = index, name = name } ) ( newRealWorld, ReplGetInputLine next prompt ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ReplGetInputLineNext next) model.next }, sendReplGetInputLine { index = index, prompt = prompt } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ReplGetInputLineNext next) model.next }, sendReplGetInputLine { index = index, prompt = prompt } ) ( newRealWorld, DirDoesFileExist next filename ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirDoesFileExistNext next) model.next }, sendDirDoesFileExist { index = index, filename = filename } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirDoesFileExistNext next) model.next }, sendDirDoesFileExist { index = index, filename = filename } ) ( newRealWorld, DirCreateDirectoryIfMissing next createParents filename ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirCreateDirectoryIfMissingNext next) model.next }, sendDirCreateDirectoryIfMissing { index = index, createParents = createParents, filename = filename } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirCreateDirectoryIfMissingNext next) model.next }, sendDirCreateDirectoryIfMissing { index = index, createParents = createParents, filename = filename } ) ( newRealWorld, LockFile next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (LockFileNext next) model.next }, sendLockFile { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (LockFileNext next) model.next }, sendLockFile { index = index, path = path } ) ( newRealWorld, UnlockFile next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (UnlockFileNext next) model.next }, sendUnlockFile { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (UnlockFileNext next) model.next }, sendUnlockFile { index = index, path = path } ) ( newRealWorld, DirGetModificationTime next filename ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirGetModificationTimeNext next) model.next }, sendDirGetModificationTime { index = index, filename = filename } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirGetModificationTimeNext next) model.next }, sendDirGetModificationTime { index = index, filename = filename } ) ( newRealWorld, DirDoesDirectoryExist next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirDoesDirectoryExistNext next) model.next }, sendDirDoesDirectoryExist { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirDoesDirectoryExistNext next) model.next }, sendDirDoesDirectoryExist { index = index, path = path } ) ( newRealWorld, DirCanonicalizePath next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirCanonicalizePathNext next) model.next }, sendDirCanonicalizePath { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirCanonicalizePathNext next) model.next }, sendDirCanonicalizePath { index = index, path = path } ) ( newRealWorld, BinaryDecodeFileOrFail next filename ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (BinaryDecodeFileOrFailNext next) model.next }, sendBinaryDecodeFileOrFail { index = index, filename = filename } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (BinaryDecodeFileOrFailNext next) model.next }, sendBinaryDecodeFileOrFail { index = index, filename = filename } ) ( newRealWorld, Write next fd content ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (WriteNext next) model.next }, sendWrite { index = index, fd = fd, content = content } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (WriteNext next) model.next }, sendWrite { index = index, fd = fd, content = content } ) ( newRealWorld, DirRemoveFile next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirRemoveFileNext next) model.next }, sendDirRemoveFile { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirRemoveFileNext next) model.next }, sendDirRemoveFile { index = index, path = path } ) ( newRealWorld, DirRemoveDirectoryRecursive next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirRemoveDirectoryRecursiveNext next) model.next }, sendDirRemoveDirectoryRecursive { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirRemoveDirectoryRecursiveNext next) model.next }, sendDirRemoveDirectoryRecursive { index = index, path = path } ) ( newRealWorld, DirWithCurrentDirectory next path ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (DirWithCurrentDirectoryNext next) model.next }, sendDirWithCurrentDirectory { index = index, path = path } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (DirWithCurrentDirectoryNext next) model.next }, sendDirWithCurrentDirectory { index = index, path = path } ) ( newRealWorld, ReplGetInputLineWithInitial next prompt left right ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ReplGetInputLineWithInitialNext next) model.next }, sendReplGetInputLineWithInitial { index = index, prompt = prompt, left = left, right = right } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ReplGetInputLineWithInitialNext next) model.next }, sendReplGetInputLineWithInitial { index = index, prompt = prompt, left = left, right = right } ) ( newRealWorld, NewEmptyMVar next ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (NewEmptyMVarNext next) model.next }, sendNewEmptyMVar index ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (NewEmptyMVarNext next) model.next }, sendNewEmptyMVar index ) ( newRealWorld, ReadMVar next id ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (ReadMVarNext next) model.next }, sendReadMVar { index = index, id = id } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (ReadMVarNext next) model.next }, sendReadMVar { index = index, id = id } ) ( newRealWorld, TakeMVar next id ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (TakeMVarNext next) model.next }, sendTakeMVar { index = index, id = id } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (TakeMVarNext next) model.next }, sendTakeMVar { index = index, id = id } ) ( newRealWorld, PutMVar next id value ) -> - ( { model | realWorld = newRealWorld, next = Dict.insert identity index (PutMVarNext next) model.next }, sendPutMVar { index = index, id = id, value = value } ) + ( { model | realWorld = newRealWorld, next = Dict.insert index (PutMVarNext next) model.next }, sendPutMVar { index = index, id = id, value = value } ) GetLineMsg index input -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (GetLineNext fn) -> update (PureMsg index (fn input)) model @@ -365,7 +365,7 @@ update msg model = crash "GetLineMsg" HPutLineMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (HPutLineNext fn) -> update (PureMsg index (fn ())) model @@ -373,7 +373,7 @@ update msg model = crash "HPutLineMsg" WriteStringMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (WriteStringNext fn) -> update (PureMsg index (fn ())) model @@ -381,7 +381,7 @@ update msg model = crash "WriteStringMsg" ReadMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (ReadNext fn) -> update (PureMsg index (fn value)) model @@ -389,7 +389,7 @@ update msg model = crash "ReadMsg" HttpFetchMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (HttpFetchNext fn) -> update (PureMsg index (fn value)) model @@ -397,7 +397,7 @@ update msg model = crash "HttpFetchMsg" GetArchiveMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (GetArchiveNext fn) -> update (PureMsg index (fn value)) model @@ -405,7 +405,7 @@ update msg model = crash "GetArchiveMsg" HttpUploadMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (HttpUploadNext fn) -> update (PureMsg index (fn ())) model @@ -413,7 +413,7 @@ update msg model = crash "HttpUploadMsg" HFlushMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (HFlushNext fn) -> update (PureMsg index (fn ())) model @@ -421,7 +421,7 @@ update msg model = crash "HFlushMsg" WithFileMsg index fd -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (WithFileNext fn) -> update (PureMsg index (fn fd)) model @@ -429,7 +429,7 @@ update msg model = crash "WithFileMsg" HFileSizeMsg index size -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (HFileSizeNext fn) -> update (PureMsg index (fn size)) model @@ -437,7 +437,7 @@ update msg model = crash "HFileSizeMsg" ProcWithCreateProcessMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (ProcWithCreateProcessNext fn) -> update (PureMsg index (fn value)) model @@ -445,7 +445,7 @@ update msg model = crash "ProcWithCreateProcessMsg" HCloseMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (HCloseNext fn) -> update (PureMsg index (fn ())) model @@ -453,7 +453,7 @@ update msg model = crash "HCloseMsg" ProcWaitForProcessMsg index code -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (ProcWaitForProcessNext fn) -> update (PureMsg index (fn code)) model @@ -461,7 +461,7 @@ update msg model = crash "ProcWaitForProcessMsg" NewEmptyMVarMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (NewEmptyMVarNext fn) -> update (PureMsg index (fn value)) model @@ -469,7 +469,7 @@ update msg model = crash "NewEmptyMVarMsg" DirFindExecutableMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (DirFindExecutableNext fn) -> update (PureMsg index (fn value)) model @@ -477,7 +477,7 @@ update msg model = crash "DirFindExecutableMsg" ReplGetInputLineMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (ReplGetInputLineNext fn) -> update (PureMsg index (fn value)) model @@ -485,7 +485,7 @@ update msg model = crash "ReplGetInputLineMsg" PutMVarMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (PutMVarNext fn) -> update (PureMsg index (fn ())) model @@ -493,7 +493,7 @@ update msg model = crash "PutMVarMsg" DirDoesFileExistMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (DirDoesFileExistNext fn) -> update (PureMsg index (fn value)) model @@ -501,7 +501,7 @@ update msg model = crash "DirDoesFileExistMsg" DirCreateDirectoryIfMissingMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (DirCreateDirectoryIfMissingNext fn) -> update (PureMsg index (fn ())) model @@ -509,7 +509,7 @@ update msg model = crash "DirCreateDirectoryIfMissingMsg" LockFileMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (LockFileNext fn) -> update (PureMsg index (fn ())) model @@ -517,7 +517,7 @@ update msg model = crash "LockFileMsg" UnlockFileMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (UnlockFileNext fn) -> update (PureMsg index (fn ())) model @@ -525,7 +525,7 @@ update msg model = crash "UnlockFileMsg" DirGetModificationTimeMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (DirGetModificationTimeNext fn) -> update (PureMsg index (fn value)) model @@ -533,7 +533,7 @@ update msg model = crash "DirGetModificationTimeMsg" DirDoesDirectoryExistMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (DirDoesDirectoryExistNext fn) -> update (PureMsg index (fn value)) model @@ -541,7 +541,7 @@ update msg model = crash "DirDoesDirectoryExistMsg" DirCanonicalizePathMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (DirCanonicalizePathNext fn) -> update (PureMsg index (fn value)) model @@ -549,7 +549,7 @@ update msg model = crash "DirCanonicalizePathMsg" ReadMVarMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (ReadMVarNext fn) -> update (PureMsg index (fn value)) model @@ -560,7 +560,7 @@ update msg model = crash "ReadMVarMsg" BinaryDecodeFileOrFailMsg index value -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (BinaryDecodeFileOrFailNext fn) -> update (PureMsg index (fn value)) model @@ -568,7 +568,7 @@ update msg model = crash "BinaryDecodeFileOrFailMsg" WriteMsg index -> - case Dict.get identity index model.next of + case Dict.get index model.next of Just (WriteNext fn) -> update (PureMsg index (fn ())) model @@ -821,7 +821,7 @@ type ION a type alias RealWorld = { args : List String , currentDirectory : String - , envVars : Dict String String String + , envVars : Dict String String , homedir : FilePath , progName : String , state : ReplState @@ -1077,7 +1077,7 @@ getLine = type ReplState - = ReplState (Dict String String String) (Dict String String String) (Dict String String String) + = ReplState (Dict String String) (Dict String String) (Dict String String) initialReplState : ReplState diff --git a/src/Terminal/Repl.elm b/src/Terminal/Repl.elm index 659d727b5..9c4eff8f3 100644 --- a/src/Terminal/Repl.elm +++ b/src/Terminal/Repl.elm @@ -37,7 +37,8 @@ import Compiler.Reporting.Error.Syntax as ES import Compiler.Reporting.Render.Code as Code import Compiler.Reporting.Report as Report import Control.Monad.State.Strict as State -import Data.Map as Dict exposing (Dict) +import Data.Map as Map exposing (Dict) +import Dict import List.Extra as List import Maybe.Extra as Maybe import Prelude @@ -544,7 +545,7 @@ eval env ((IO.ReplState imports types decls) as state) input = let newState : IO.ReplState newState = - IO.ReplState (Dict.insert identity name src imports) types decls + IO.ReplState (Dict.insert name src imports) types decls in IO.fmap Loop (attemptEval env state newState OutputNothing) @@ -552,7 +553,7 @@ eval env ((IO.ReplState imports types decls) as state) input = let newState : IO.ReplState newState = - IO.ReplState imports (Dict.insert identity name src types) decls + IO.ReplState imports (Dict.insert name src types) decls in IO.fmap Loop (attemptEval env state newState OutputNothing) @@ -564,7 +565,7 @@ eval env ((IO.ReplState imports types decls) as state) input = let newState : IO.ReplState newState = - IO.ReplState imports types (Dict.insert identity name src decls) + IO.ReplState imports types (Dict.insert name src decls) in IO.fmap Loop (attemptEval env state newState (OutputDecl name)) @@ -656,9 +657,9 @@ toByteString (IO.ReplState imports types decls) output = [ "module " , N.replModule , " exposing (..)\n" - , Dict.foldr compare (\_ -> (++)) "" imports - , Dict.foldr compare (\_ -> (++)) "" types - , Dict.foldr compare (\_ -> (++)) "" decls + , Dict.foldr (\_ -> (++)) "" imports + , Dict.foldr (\_ -> (++)) "" types + , Dict.foldr (\_ -> (++)) "" decls , outputToBuilder output ] @@ -749,7 +750,7 @@ getRoot = V.one (Outline.ExposedList []) defaultDeps - Dict.empty + Map.empty C.defaultElm ) |> IO.fmap (\_ -> root) @@ -759,7 +760,7 @@ getRoot = defaultDeps : Dict ( String, String ) Pkg.Name C.Constraint defaultDeps = - Dict.fromList identity + Map.fromList identity [ ( Pkg.core, C.anything ) , ( Pkg.json, C.anything ) , ( Pkg.html, C.anything ) @@ -841,9 +842,9 @@ lookupCompletions string = ) -commands : Dict String N.Name () +commands : Dict.Dict N.Name () commands = - Dict.fromList identity + Dict.fromList [ ( ":exit", () ) , ( ":quit", () ) , ( ":reset", () ) @@ -851,9 +852,9 @@ commands = ] -addMatches : String -> Bool -> Dict String N.Name v -> List Utils.ReplCompletion -> List Utils.ReplCompletion +addMatches : String -> Bool -> Dict.Dict N.Name v -> List Utils.ReplCompletion -> List Utils.ReplCompletion addMatches string isFinished dict completions = - Dict.foldr compare (addMatch string isFinished) completions dict + Dict.foldr (addMatch string isFinished) completions dict addMatch : String -> Bool -> N.Name -> v -> List Utils.ReplCompletion -> List Utils.ReplCompletion diff --git a/src/Utils/Main.elm b/src/Utils/Main.elm index ab9debb50..e52a41709 100644 --- a/src/Utils/Main.elm +++ b/src/Utils/Main.elm @@ -132,8 +132,9 @@ import Compiler.Json.Decode as D import Compiler.Json.Encode as E import Compiler.Reporting.Result as R import Control.Monad.State.Strict as State -import Data.Map as Dict exposing (Dict) +import Data.Map as Map exposing (Dict) import Data.Set as EverySet exposing (EverySet) +import Dict import Json.Decode as Decode import Json.Encode as Encode import Maybe.Extra as Maybe @@ -187,9 +188,9 @@ mapFromListWith : (k -> comparable) -> (a -> a -> a) -> List ( k, a ) -> Dict co mapFromListWith toComparable f = List.foldl (\( k, a ) -> - Dict.update toComparable k (Maybe.map (flip f a)) + Map.update toComparable k (Maybe.map (flip f a)) ) - Dict.empty + Map.empty maybeEncoder : (a -> Encode.Value) -> Maybe a -> Encode.Value @@ -218,7 +219,7 @@ eitherLefts = mapFromKeys : (k -> comparable) -> (k -> v) -> List k -> Dict comparable k v mapFromKeys toComparable f = List.map (\k -> ( k, f k )) - >> Dict.fromList toComparable + >> Map.fromList toComparable filterM : (a -> IO Bool) -> List a -> IO (List a) @@ -242,7 +243,7 @@ filterM p = find : (k -> comparable) -> k -> Dict comparable k a -> a find toComparable k items = - case Dict.get toComparable k items of + case Map.get toComparable k items of Just item -> item @@ -252,7 +253,7 @@ find toComparable k items = mapLookupMin : Dict comparable comparable a -> Maybe ( comparable, a ) mapLookupMin dict = - case List.sortBy Tuple.first (Dict.toList compare dict) of + case List.sortBy Tuple.first (Map.toList compare dict) of firstElem :: _ -> Just firstElem @@ -262,7 +263,7 @@ mapLookupMin dict = mapFindMin : Dict comparable comparable a -> ( comparable, a ) mapFindMin dict = - case List.sortBy Tuple.first (Dict.toList compare dict) of + case List.sortBy Tuple.first (Map.toList compare dict) of firstElem :: _ -> firstElem @@ -272,7 +273,7 @@ mapFindMin dict = mapInsertWith : (k -> comparable) -> (a -> a -> a) -> k -> a -> Dict comparable k a -> Dict comparable k a mapInsertWith toComparable f k a = - Dict.update toComparable k (Maybe.map (f a) >> Maybe.withDefault a >> Just) + Map.update toComparable k (Maybe.map (f a) >> Maybe.withDefault a >> Just) mapIntersectionWith : (k -> comparable) -> (k -> k -> Order) -> (a -> b -> c) -> Dict comparable k a -> Dict comparable k b -> Dict comparable k c @@ -282,22 +283,22 @@ mapIntersectionWith toComparable keyComparison func = mapIntersectionWithKey : (k -> comparable) -> (k -> k -> Order) -> (k -> a -> b -> c) -> Dict comparable k a -> Dict comparable k b -> Dict comparable k c mapIntersectionWithKey toComparable keyComparison func dict1 dict2 = - Dict.merge keyComparison (\_ _ -> identity) (\k v1 v2 -> Dict.insert toComparable k (func k v1 v2)) (\_ _ -> identity) dict1 dict2 Dict.empty + Map.merge keyComparison (\_ _ -> identity) (\k v1 v2 -> Map.insert toComparable k (func k v1 v2)) (\_ _ -> identity) dict1 dict2 Map.empty mapUnionWith : (k -> comparable) -> (k -> k -> Order) -> (a -> a -> a) -> Dict comparable k a -> Dict comparable k a -> Dict comparable k a mapUnionWith toComparable keyComparison f a b = - Dict.merge keyComparison (Dict.insert toComparable) (\k va vb -> Dict.insert toComparable k (f va vb)) (Dict.insert toComparable) a b Dict.empty + Map.merge keyComparison (Map.insert toComparable) (\k va vb -> Map.insert toComparable k (f va vb)) (Map.insert toComparable) a b Map.empty mapUnionsWith : (k -> comparable) -> (k -> k -> Order) -> (a -> a -> a) -> List (Dict comparable k a) -> Dict comparable k a mapUnionsWith toComparable keyComparison f = - List.foldl (mapUnionWith toComparable keyComparison f) Dict.empty + List.foldl (mapUnionWith toComparable keyComparison f) Map.empty mapUnions : List (Dict comparable k a) -> Dict comparable k a mapUnions = - List.foldr Dict.union Dict.empty + List.foldr Map.union Map.empty foldM : (b -> a -> R.RResult info warnings error b) -> b -> List a -> R.RResult info warnings error b @@ -318,7 +319,7 @@ indexedZipWithA func listX listY = sequenceADict : (k -> comparable) -> (k -> k -> Order) -> Dict comparable k (R.RResult i w e v) -> R.RResult i w e (Dict comparable k v) sequenceADict toComparable keyComparison = - Dict.foldr keyComparison (\k x acc -> R.apply acc (R.fmap (Dict.insert toComparable k) x)) (R.pure Dict.empty) + Map.foldr keyComparison (\k x acc -> R.apply acc (R.fmap (Map.insert toComparable k) x)) (R.pure Map.empty) sequenceAList : List (R.RResult i w e v) -> R.RResult i w e (List v) @@ -328,12 +329,12 @@ sequenceAList = sequenceDictMaybe : (k -> comparable) -> (k -> k -> Order) -> Dict comparable k (Maybe a) -> Maybe (Dict comparable k a) sequenceDictMaybe toComparable keyComparison = - Dict.foldr keyComparison (\k -> Maybe.map2 (Dict.insert toComparable k)) (Just Dict.empty) + Map.foldr keyComparison (\k -> Maybe.map2 (Map.insert toComparable k)) (Just Map.empty) sequenceDictResult : (k -> comparable) -> (k -> k -> Order) -> Dict comparable k (Result e v) -> Result e (Dict comparable k v) sequenceDictResult toComparable keyComparison = - Dict.foldr keyComparison (\k -> Result.map2 (Dict.insert toComparable k)) (Ok Dict.empty) + Map.foldr keyComparison (\k -> Result.map2 (Map.insert toComparable k)) (Ok Map.empty) sequenceDictResult_ : (k -> comparable) -> (k -> k -> Order) -> Dict comparable k (Result e a) -> Result e () @@ -353,7 +354,7 @@ sequenceNonemptyListResult (NE.Nonempty x xs) = keysSet : (k -> comparable) -> (k -> k -> Order) -> Dict comparable k a -> EverySet comparable k keysSet toComparable keyComparison = - Dict.keys keyComparison >> EverySet.fromList toComparable + Map.keys keyComparison >> EverySet.fromList toComparable unzip3 : List ( a, b, c ) -> ( List a, List b, List c ) @@ -383,7 +384,7 @@ dictMapM_ keyComparison f = c _ x k = IO.bind (\_ -> k) (f x) in - Dict.foldl keyComparison c (IO.pure ()) + Map.foldl keyComparison c (IO.pure ()) maybeMapM : (a -> Maybe b) -> List a -> Maybe (List b) @@ -393,9 +394,9 @@ maybeMapM = mapMinViewWithKey : (k -> comparable) -> (k -> k -> Order) -> (( k, a ) -> comparable) -> Dict comparable k a -> Maybe ( ( k, a ), Dict comparable k a ) mapMinViewWithKey toComparable keyComparison compare dict = - case List.sortBy compare (Dict.toList keyComparison dict) of + case List.sortBy compare (Map.toList keyComparison dict) of first :: tail -> - Just ( first, Dict.fromList toComparable tail ) + Just ( first, Map.fromList toComparable tail ) _ -> Nothing @@ -403,9 +404,9 @@ mapMinViewWithKey toComparable keyComparison compare dict = mapMapMaybe : (k -> comparable) -> (k -> k -> Order) -> (a -> Maybe b) -> Dict comparable k a -> Dict comparable k b mapMapMaybe toComparable keyComparison func = - Dict.toList keyComparison + Map.toList keyComparison >> List.filterMap (\( k, a ) -> Maybe.map (Tuple.pair k) (func a)) - >> Dict.fromList toComparable + >> Map.fromList toComparable mapTraverse : (k -> comparable) -> (k -> k -> Order) -> (a -> IO b) -> Dict comparable k a -> IO (Dict comparable k b) @@ -415,9 +416,9 @@ mapTraverse toComparable keyComparison f = mapTraverseWithKey : (k -> comparable) -> (k -> k -> Order) -> (k -> a -> IO b) -> Dict comparable k a -> IO (Dict comparable k b) mapTraverseWithKey toComparable keyComparison f = - Dict.foldl keyComparison - (\k a -> IO.bind (\c -> IO.fmap (\va -> Dict.insert toComparable k va c) (f k a))) - (IO.pure Dict.empty) + Map.foldl keyComparison + (\k a -> IO.bind (\c -> IO.fmap (\va -> Map.insert toComparable k va c) (f k a))) + (IO.pure Map.empty) mapTraverseResult : (k -> comparable) -> (k -> k -> Order) -> (a -> Result e b) -> Dict comparable k a -> Result e (Dict comparable k b) @@ -427,9 +428,9 @@ mapTraverseResult toComparable keyComparison f = mapTraverseWithKeyResult : (k -> comparable) -> (k -> k -> Order) -> (k -> a -> Result e b) -> Dict comparable k a -> Result e (Dict comparable k b) mapTraverseWithKeyResult toComparable keyComparison f = - Dict.foldl keyComparison - (\k a -> Result.map2 (Dict.insert toComparable k) (f k a)) - (Ok Dict.empty) + Map.foldl keyComparison + (\k a -> Result.map2 (Map.insert toComparable k) (f k a)) + (Ok Map.empty) listTraverse : (a -> IO b) -> List a -> IO (List b) @@ -804,7 +805,7 @@ dirWithCurrentDirectory dir action = envLookupEnv : String -> IO (Maybe String) envLookupEnv name = - IO (\s -> ( s, IO.Pure (Dict.get identity name s.envVars) )) + IO (\s -> ( s, IO.Pure (Dict.get name s.envVars) )) envGetProgName : IO String