diff --git a/bin/index.js b/bin/index.js index 0f84b6442..320b090c2 100755 --- a/bin/index.js +++ b/bin/index.js @@ -131,6 +131,9 @@ const io = { this.send({ index, value: ioRefs[id].value }); } }, + mVectorRead: function (index, i, array) { + this.send({ index, value: array[i] }); + }, dirCreateDirectoryIfMissing: function (index, createParents, filename) { fs.mkdir(filename, { recursive: createParents }, (err) => { this.send({ index, value: null }); diff --git a/src/Compiler/Type/Solve.elm b/src/Compiler/Type/Solve.elm index 1503b6b19..b36493706 100644 --- a/src/Compiler/Type/Solve.elm +++ b/src/Compiler/Type/Solve.elm @@ -406,7 +406,7 @@ This sorts variables into the young and old pools accordingly. -} generalize : Mark -> Mark -> Int -> Pools -> IO () generalize youngMark visitMark youngRank pools = - IO.mVectorRead (Decode.list UF.variableDecoder) pools youngRank + IO.mVectorRead (Decode.list UF.variableDecoder) (Encode.list UF.variableEncoder) pools youngRank |> IO.bind (\youngVars -> poolToRankTable youngMark youngRank youngVars diff --git a/src/Data/IO.elm b/src/Data/IO.elm index 240954d28..7f7a5a303 100644 --- a/src/Data/IO.elm +++ b/src/Data/IO.elm @@ -90,6 +90,7 @@ type Effect = Exit String Int | NewIORef Encode.Value | ReadIORef Int + | MVectorRead Int Encode.Value | WriteIORef Int Encode.Value | GetLine | HPutStr Handle String @@ -355,17 +356,25 @@ mVectorWrite decoder encoder ioRef i x = (Array.set i (Just x)) -mVectorRead : Decode.Decoder a -> IORef (Array (Maybe a)) -> Int -> IO a -mVectorRead decoder ioRef i = +mVectorRead : Decode.Decoder a -> (a -> Encode.Value) -> IORef (Array (Maybe a)) -> Int -> IO a +mVectorRead decoder encoder ioRef i = readIORef (Decode.array (Decode.maybe decoder)) ioRef - |> fmap + |> bind (\vector -> - case Maybe.join (Array.get i vector) of - Just a -> - a - - Nothing -> - todo "Failed to find index on vector" + make decoder + (MVectorRead i + (Encode.array + (\maybeValue -> + case maybeValue of + Just value -> + encoder value + + Nothing -> + Encode.null + ) + vector + ) + ) ) diff --git a/src/Terminal/Main.elm b/src/Terminal/Main.elm index cae862e74..a3ef35ef6 100644 --- a/src/Terminal/Main.elm +++ b/src/Terminal/Main.elm @@ -126,6 +126,16 @@ effectToCmd index portOut effect = ] } + IO.MVectorRead i array -> + portOut + { index = index + , value = + Encode.object + [ ( "fn", Encode.string "mVectorRead" ) + , ( "args", Encode.list identity [ Encode.int i, array ] ) + ] + } + IO.WriteIORef id value -> portOut { index = index diff --git a/src/Utils/Main.elm b/src/Utils/Main.elm index 0c4c74ca3..e2896afd2 100644 --- a/src/Utils/Main.elm +++ b/src/Utils/Main.elm @@ -752,8 +752,12 @@ fpMakeRelative root path = fpAddTrailingPathSeparator : FilePath -> FilePath -fpAddTrailingPathSeparator _ = - todo "fpAddTrailingPathSeparator" +fpAddTrailingPathSeparator path = + if String.endsWith "/" path then + path + + else + path ++ "/" fpPathSeparator : Char