From 2ae7dc30bf91d709a6038871e9c967dafb15cf49 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 24 Feb 2019 21:30:10 -0400 Subject: Improved the names of monad transformers. --- new-luxc/source/luxc/lang/translation/jvm.lux | 4 ++-- new-luxc/source/program.lux | 6 +++--- stdlib/source/lux/control/reader.lux | 2 +- stdlib/source/lux/control/state.lux | 10 +++++----- stdlib/source/lux/control/writer.lux | 2 +- stdlib/source/lux/data/error.lux | 2 +- stdlib/source/lux/data/maybe.lux | 2 +- stdlib/source/lux/tool/compiler/default/platform.lux | 2 +- stdlib/source/lux/tool/compiler/meta/io/context.lux | 2 +- stdlib/source/lux/tool/compiler/phase.lux | 2 +- stdlib/source/lux/world/console.lux | 2 +- stdlib/source/lux/world/db/jdbc.jvm.lux | 14 +++++++------- stdlib/source/lux/world/file.lux | 10 +++++----- stdlib/source/lux/world/net/http/client.lux | 3 ++- stdlib/source/lux/world/net/tcp.jvm.lux | 12 ++++++------ stdlib/source/lux/world/net/udp.jvm.lux | 10 +++++----- stdlib/source/lux/world/shell.lux | 6 +++--- stdlib/source/program/licentia.lux | 2 +- stdlib/source/program/scriptum.lux | 2 +- stdlib/source/test/lux/control/reader.lux | 2 +- stdlib/source/test/lux/control/state.lux | 2 +- stdlib/source/test/lux/control/writer.lux | 2 +- stdlib/source/test/lux/host/jvm.jvm.lux | 2 +- 23 files changed, 52 insertions(+), 51 deletions(-) diff --git a/new-luxc/source/luxc/lang/translation/jvm.lux b/new-luxc/source/luxc/lang/translation/jvm.lux index 88e607217..5ffb60482 100644 --- a/new-luxc/source/luxc/lang/translation/jvm.lux +++ b/new-luxc/source/luxc/lang/translation/jvm.lux @@ -100,14 +100,14 @@ (|>> valueI (inst.PUTSTATIC bytecode-name ..value-field ..$Object) inst.RETURN))))] - (io.run (do (error.with-error io.monad) + (io.run (do (error.with io.monad) [_ (loader.store eval-class bytecode library) class (loader.load eval-class loader)] (:: io.monad wrap (class-value eval-class class)))))) (def: (execute! library loader temp-label [class-name class-bytecode]) (-> Library ClassLoader Text Definition (Error Any)) - (io.run (do (error.with-error io.monad) + (io.run (do (error.with io.monad) [_ (loader.store class-name class-bytecode library)] (loader.load class-name loader)))) diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux index cee627708..0f761d70d 100644 --- a/new-luxc/source/program.lux +++ b/new-luxc/source/program.lux @@ -57,7 +57,7 @@ (def: (timed action) (All [a] (-> (-> Any (IO (Error a))) (IO (Error a)))) - (do (error.with-error io.monad) + (do (error.with io.monad) [start (: (IO (Error Instant)) (error.lift io.monad instant.now)) result (action []) @@ -88,7 +88,7 @@ (<| (or-crash! "Compilation failed:") ..timed (function (_ _) - (do (error.with-error io.monad) + (do (error.with io.monad) [state (: (IO (Error (statement.State+ host/jvm.Anchor host/jvm.Inst host/jvm.Definition))) (platform.initialize platform common.bundle)) ## _ (platform.compile platform (set@ #cli.module syntax.prelude configuration) state) @@ -102,5 +102,5 @@ ## TODO: Fix the interpreter... (undefined) ## (<| (or-crash! "Interpretation failed:") - ## (interpreter.run (error.with-error io.monad) console platform configuration common.bundle)) + ## (interpreter.run (error.with io.monad) console platform configuration common.bundle)) ))) diff --git a/stdlib/source/lux/control/reader.lux b/stdlib/source/lux/control/reader.lux index dc18cb43e..01b139b82 100644 --- a/stdlib/source/lux/control/reader.lux +++ b/stdlib/source/lux/control/reader.lux @@ -51,7 +51,7 @@ (function (_ env) (mma env env)))) -(structure: #export (with-reader monad) +(structure: #export (with monad) {#.doc "Monad transformer for Reader."} (All [M] (-> (Monad M) (All [e] (Monad (All [a] (Reader e (M a))))))) diff --git a/stdlib/source/lux/control/state.lux b/stdlib/source/lux/control/state.lux index afbf28ad1..fc017f177 100644 --- a/stdlib/source/lux/control/state.lux +++ b/stdlib/source/lux/control/state.lux @@ -94,7 +94,7 @@ [_ body] (while condition body))) -(structure: (with-state//functor functor) +(structure: (with//functor functor) (All [M s] (-> (Functor M) (Functor (All [a] (-> s (M [s a])))))) (def: (map f sfa) @@ -102,10 +102,10 @@ (:: functor map (function (_ [s a]) [s (f a)]) (sfa state))))) -(structure: (with-state//apply monad) +(structure: (with//apply monad) (All [M s] (-> (Monad M) (Apply (All [a] (-> s (M [s a])))))) - (def: &functor (with-state//functor (:: monad &functor))) + (def: &functor (with//functor (:: monad &functor))) (def: (apply sFf sFa) (function (_ state) @@ -123,11 +123,11 @@ (All [M s a] (-> s (State' M s a) (M [s a]))) (action state)) -(structure: #export (with-state monad) +(structure: #export (with monad) {#.doc "A monad transformer to create composite stateful computations."} (All [M s] (-> (Monad M) (Monad (State' M s)))) - (def: &functor (with-state//functor (:: monad &functor))) + (def: &functor (with//functor (:: monad &functor))) (def: (wrap a) (function (_ state) diff --git a/stdlib/source/lux/control/writer.lux b/stdlib/source/lux/control/writer.lux index 8b8d7e38f..278fc9236 100644 --- a/stdlib/source/lux/control/writer.lux +++ b/stdlib/source/lux/control/writer.lux @@ -48,7 +48,7 @@ (let [[log1 [log2 a]] mma] [(:: monoid compose log1 log2) a]))) -(structure: #export (with-writer monoid monad) +(structure: #export (with monoid monad) (All [l M] (-> (Monoid l) (Monad M) (Monad (All [a] (M (Writer l a)))))) (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) diff --git a/stdlib/source/lux/data/error.lux b/stdlib/source/lux/data/error.lux index 98f05869f..938fca3b9 100644 --- a/stdlib/source/lux/data/error.lux +++ b/stdlib/source/lux/data/error.lux @@ -49,7 +49,7 @@ (#Success ma) ma))) -(structure: #export (with-error monad) +(structure: #export (with monad) ## TODO: Replace (All [a] (M (Error a))) with (functor.Then M Error) (All [M] (-> (Monad M) (Monad (All [a] (M (Error a)))))) diff --git a/stdlib/source/lux/data/maybe.lux b/stdlib/source/lux/data/maybe.lux index 5b780e999..e00b89234 100644 --- a/stdlib/source/lux/data/maybe.lux +++ b/stdlib/source/lux/data/maybe.lux @@ -65,7 +65,7 @@ _ #0))) -(structure: #export (with-maybe monad) +(structure: #export (with monad) (All [M] (-> (Monad M) (Monad (All [a] (M (Maybe a)))))) (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) diff --git a/stdlib/source/lux/tool/compiler/default/platform.lux b/stdlib/source/lux/tool/compiler/default/platform.lux index 8711d20ec..22c50ddec 100644 --- a/stdlib/source/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/lux/tool/compiler/default/platform.lux @@ -29,7 +29,7 @@ ## (def: (write-module target-dir file-name module-name module outputs) ## (-> File Text Text Module Outputs (Process Any)) -## (do (error.with-error io.monad) +## (do (error.with io.monad) ## [_ (monad.map @ (product.uncurry (&io.write target-dir)) ## (dictionary.entries outputs))] ## (&io.write target-dir diff --git a/stdlib/source/lux/tool/compiler/meta/io/context.lux b/stdlib/source/lux/tool/compiler/meta/io/context.lux index f526a3738..6b9ce9ba4 100644 --- a/stdlib/source/lux/tool/compiler/meta/io/context.lux +++ b/stdlib/source/lux/tool/compiler/meta/io/context.lux @@ -93,7 +93,7 @@ (All [!] (-> (Monad !) (file.System !) (List Context) Module (! (Error Input)))) - (do (error.with-error monad) + (do (error.with monad) [## TODO: Get rid of both ":share"s ASAP path,file (:share [!] {(Monad !) diff --git a/stdlib/source/lux/tool/compiler/phase.lux b/stdlib/source/lux/tool/compiler/phase.lux index 909b7e9e9..8c4bbd615 100644 --- a/stdlib/source/lux/tool/compiler/phase.lux +++ b/stdlib/source/lux/tool/compiler/phase.lux @@ -20,7 +20,7 @@ (state.State' Error s o)) (def: #export monad - (state.with-state error.monad)) + (state.with error.monad)) (type: #export (Phase s i o) (-> i (Operation s o))) diff --git a/stdlib/source/lux/world/console.lux b/stdlib/source/lux/world/console.lux index 0d84ae993..88ddf8a8d 100644 --- a/stdlib/source/lux/world/console.lux +++ b/stdlib/source/lux/world/console.lux @@ -93,7 +93,7 @@ (function (_ _) (|> jvm-input InputStream::read - (:: (error.with-error io.monad) map .nat))))) + (:: (error.with io.monad) map .nat))))) (def: can-read-line (..can-read diff --git a/stdlib/source/lux/world/db/jdbc.jvm.lux b/stdlib/source/lux/world/db/jdbc.jvm.lux index cc6dd79c1..d66918206 100644 --- a/stdlib/source/lux/world/db/jdbc.jvm.lux +++ b/stdlib/source/lux/world/db/jdbc.jvm.lux @@ -90,7 +90,7 @@ (-> (Statement i) java/sql/Connection (-> java/sql/PreparedStatement (IO (Error a))) (IO (Error a)))) - (do (error.with-error io.monad) + (do (error.with io.monad) [prepared (io.io (java/sql/Connection::prepareStatement (sql.sql (get@ #sql statement)) (java/sql/Statement::RETURN_GENERATED_KEYS) conn)) @@ -112,7 +112,7 @@ (def: #export (connect creds) (-> Credentials (IO (Error (DB IO)))) - (do (error.with-error io.monad) + (do (error.with io.monad) [connection (java/sql/DriverManager::getConnection (get@ #url creds) (get@ #user creds) (get@ #password creds))] @@ -123,7 +123,7 @@ (function (execute statement) (with-statement statement connection (function (_ prepared) - (do (error.with-error io.monad) + (do (error.with io.monad) [row-count (java/sql/PreparedStatement::executeUpdate prepared)] (wrap (.nat row-count)))))))) @@ -132,7 +132,7 @@ (function (insert statement) (with-statement statement connection (function (_ prepared) - (do (error.with-error io.monad) + (do (error.with io.monad) [_ (java/sql/PreparedStatement::executeUpdate prepared) result-set (io.io (java/sql/Statement::getGeneratedKeys prepared))] (/output.rows /output.long result-set))))))) @@ -147,7 +147,7 @@ (function (query [statement output]) (with-statement statement connection (function (_ prepared) - (do (error.with-error io.monad) + (do (error.with io.monad) [result-set (java/sql/PreparedStatement::executeQuery prepared)] (/output.rows output result-set))))))) ))))) @@ -157,7 +157,7 @@ (-> Credentials (-> (DB IO) (IO (Error a))) (IO (Error a)))) - (do (error.with-error io.monad) + (do (error.with io.monad) [db (..connect creds) result (action db) _ (!.use (:: db close) [])] @@ -168,7 +168,7 @@ (-> Credentials (-> (DB Promise) (Promise (Error a))) (Promise (Error a)))) - (do (error.with-error promise.monad) + (do (error.with promise.monad) [db (promise.future (..connect creds)) result (action (..async db)) _ (promise/wrap (io.run (!.use (:: db close) [])))] diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 55c8a4f8d..b12b2afe6 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -235,7 +235,7 @@ [(def: (..can-modify (function ( data) - (do (error.with-error io.monad) + (do (error.with io.monad) [stream (FileOutputStream::new (java/io/File::new path) ) _ (OutputStream::write data stream) _ (OutputStream::flush stream)] @@ -248,7 +248,7 @@ (def: content (..can-query (function (content _) - (do (error.with-error io.monad) + (do (error.with io.monad) [#let [file (java/io/File::new path)] size (java/io/File::length file) #let [data (binary.create (.nat size))] @@ -265,7 +265,7 @@ (|> path java/io/File::new java/io/File::length - (:: (error.with-error io.monad) map .nat))))) + (:: (error.with io.monad) map .nat))))) (def: last-modified (..can-query @@ -273,7 +273,7 @@ (|> path java/io/File::new (java/io/File::lastModified) - (:: (error.with-error io.monad) map (|>> duration.from-millis instant.absolute)))))) + (:: (error.with io.monad) map (|>> duration.from-millis instant.absolute)))))) (def: can-execute? (..can-query @@ -320,7 +320,7 @@ [(def: (..can-query (function ( _) - (do (error.with-error io.monad) + (do (error.with io.monad) [?children (java/io/File::listFiles (java/io/File::new path))] (case ?children (#.Some children) diff --git a/stdlib/source/lux/world/net/http/client.lux b/stdlib/source/lux/world/net/http/client.lux index af48d8a23..f2cafb0e3 100644 --- a/stdlib/source/lux/world/net/http/client.lux +++ b/stdlib/source/lux/world/net/http/client.lux @@ -19,6 +19,7 @@ ["." // (#+ Data Client) [// (#+ URL)]]) +## TODO: This is unfinished work. Things like headers and cookies are missing. (`` (for {(~~ (static host.jvm)) (as-is (import: #long java/lang/String) @@ -51,7 +52,7 @@ Client (`` (for {(~~ (static host.jvm)) (promise.future - (do (error.with-error io.monad) + (do (error.with io.monad) [conn (java/net/URL::openConnection (java/net/URL::new url)) #let [conn (:coerce java/net/HttpURLConnection conn)] _ (java/net/HttpURLConnection::setRequestMethod (case method diff --git a/stdlib/source/lux/world/net/tcp.jvm.lux b/stdlib/source/lux/world/net/tcp.jvm.lux index 3b664d9d8..fbdf47720 100644 --- a/stdlib/source/lux/world/net/tcp.jvm.lux +++ b/stdlib/source/lux/world/net/tcp.jvm.lux @@ -67,34 +67,34 @@ output (Socket::getOutputStream socket)] (wrap (: (TCP IO) (structure (def: (read size) - (do (error.with-error io.monad) + (do (error.with io.monad) [#let [data (binary.create size)] bytes-read (InputStream::read data +0 (.int size) input)] (wrap [(.nat bytes-read) data]))) (def: (write data) - (do (error.with-error io.monad) + (do (error.with io.monad) [_ (OutputStream::write data +0 (.int (binary.size data)) output)] (Flushable::flush output))) (def: (close _) - (do (error.with-error io.monad) + (do (error.with io.monad) [_ (AutoCloseable::close input) _ (AutoCloseable::close output)] (AutoCloseable::close socket)))))))) (def: #export (client address port) (-> //.Address //.Port (IO (Error (TCP IO)))) - (do (error.with-error io.monad) + (do (error.with io.monad) [socket (Socket::new address (.int port))] (io.io (tcp socket)))) (def: #export (server port) (-> //.Port (IO (Error [(Promise Any) (frp.Channel (TCP IO))]))) - (do (error.with-error io.monad) + (do (error.with io.monad) [server (ServerSocket::new (.int port)) #let [close-signal (: (Promise Any) (promise #.None)) @@ -107,7 +107,7 @@ (promise.future (loop [_ []] (do io.monad - [?client (do (error.with-error io.monad) + [?client (do (error.with io.monad) [socket (ServerSocket::accept server)] (io.io (tcp socket)))] (case ?client diff --git a/stdlib/source/lux/world/net/udp.jvm.lux b/stdlib/source/lux/world/net/udp.jvm.lux index 27363956d..09726c5ae 100644 --- a/stdlib/source/lux/world/net/udp.jvm.lux +++ b/stdlib/source/lux/world/net/udp.jvm.lux @@ -73,7 +73,7 @@ (`` (for {(~~ (static host.jvm)) (as-is (def: (resolve address) (-> //.Address (IO (Error InetAddress))) - (do (error.with-error io.monad) + (do (error.with io.monad) [addresses (InetAddress::getAllByName address)] (: (IO (Error InetAddress)) (case (array.size addresses) @@ -86,7 +86,7 @@ (structure (def: (read size) (let [data (binary.create size) packet (DatagramPacket::new|receive data +0 (.int size))] - (do (error.with-error io.monad) + (do (error.with io.monad) [_ (DatagramSocket::receive packet socket) #let [bytes-read (.nat (DatagramPacket::getLength packet))]] (wrap [bytes-read @@ -95,7 +95,7 @@ data])))) (def: (write [location data]) - (do (error.with-error io.monad) + (do (error.with io.monad) [address (resolve (get@ #//.address location))] (DatagramSocket::send (DatagramPacket::new|send data +0 (.int (binary.size data)) address (.int (get@ #//.port location))) socket))) @@ -106,11 +106,11 @@ (def: #export client (IO (Error (UDP IO))) (|> (DatagramSocket::new|client) - (:: (error.with-error io.monad) map udp))) + (:: (error.with io.monad) map udp))) (def: #export server (-> //.Port (IO (Error (UDP IO)))) (|>> .int DatagramSocket::new|server - (:: (error.with-error io.monad) map udp))) + (:: (error.with io.monad) map udp))) )})) diff --git a/stdlib/source/lux/world/shell.lux b/stdlib/source/lux/world/shell.lux index aefdf2b3c..a26d63259 100644 --- a/stdlib/source/lux/world/shell.lux +++ b/stdlib/source/lux/world/shell.lux @@ -105,7 +105,7 @@ (def: (process-console process) (-> java/lang/Process (IO (Error (Console IO)))) - (do (error.with-error io.monad) + (do (error.with io.monad) [jvm-input (java/lang/Process::getInputStream process) #let [jvm-input (|> jvm-input java/io/InputStreamReader::new @@ -118,7 +118,7 @@ (function (_ _) (|> jvm-input java/io/Reader::read - (:: (error.with-error io.monad) map .nat))))) + (:: (error.with io.monad) map .nat))))) (def: can-read-line (console.can-read @@ -150,7 +150,7 @@ (def: #export (execute environment command arguments) (-> Context Text (List Text) (IO (Error (Console IO)))) (`` (for {(~~ (static host.jvm)) - (do (error.with-error io.monad) + (do (error.with io.monad) [windows? (:: @ map (|>> java/lang/String::toLowerCase ..windows?) (java/lang/System::getProperty "os.name")) #let [builder (java/lang/ProcessBuilder::new (arguments-array (list& (sanitize-command windows? command) diff --git a/stdlib/source/program/licentia.lux b/stdlib/source/program/licentia.lux index 3300c380d..46fa8345f 100644 --- a/stdlib/source/program/licentia.lux +++ b/stdlib/source/program/licentia.lux @@ -55,7 +55,7 @@ (cli.named "--output" cli.any))}] (do io.monad [?done (: (IO (Error Any)) - (do (error.with-error io.monad) + (do (error.with io.monad) [file (!.use (:: file.system file) input) blob (!.use (:: file content) []) document (io/wrap (do error.monad diff --git a/stdlib/source/program/scriptum.lux b/stdlib/source/program/scriptum.lux index 04570a9bb..a51a1765b 100644 --- a/stdlib/source/program/scriptum.lux +++ b/stdlib/source/program/scriptum.lux @@ -483,7 +483,7 @@ (-> [Text (Markdown Block)] (IO Any)) (let [path (format (text.replace-all "/" "_" module-name) ".md")] (do io.monad - [outcome (do (error.with-error io.monad) + [outcome (do (error.with io.monad) [target (: (IO (Error (File IO))) (file.get-file io.monad file.system path))] (!.use (:: target over-write) (encoding.to-utf8 (md.markdown documentation))))] diff --git a/stdlib/source/test/lux/control/reader.lux b/stdlib/source/test/lux/control/reader.lux index f1d80f703..2d83244d6 100644 --- a/stdlib/source/test/lux/control/reader.lux +++ b/stdlib/source/test/lux/control/reader.lux @@ -47,7 +47,7 @@ (let [(^open "io/.") io.monad] (_.test "Can add reader functionality to any monad." (|> (: (/.Reader Any (IO Nat)) - (do (/.with-reader io.monad) + (do (/.with io.monad) [a (/.lift (io/wrap sample)) b (wrap factor)] (wrap (n/* b a)))) diff --git a/stdlib/source/test/lux/control/state.lux b/stdlib/source/test/lux/control/state.lux index 044ff11ff..49cbbcb15 100644 --- a/stdlib/source/test/lux/control/state.lux +++ b/stdlib/source/test/lux/control/state.lux @@ -108,7 +108,7 @@ (let [(^open "io/.") io.monad] (_.test "Can add state functionality to any monad." (|> (: (/.State' io.IO Nat Nat) - (do (/.with-state io.monad) + (do (/.with io.monad) [a (/.lift io.monad (io/wrap left)) b (wrap right)] (wrap (n/+ a b)))) diff --git a/stdlib/source/test/lux/control/writer.lux b/stdlib/source/test/lux/control/writer.lux index 87d2de77a..bed2d68d1 100644 --- a/stdlib/source/test/lux/control/writer.lux +++ b/stdlib/source/test/lux/control/writer.lux @@ -48,7 +48,7 @@ (let [lift (/.lift text.monoid io.monad) (^open "io/.") io.monad] (_.test "Can add writer functionality to any monad." - (|> (io.run (do (/.with-writer text.monoid io.monad) + (|> (io.run (do (/.with text.monoid io.monad) [a (lift (io/wrap left)) b (wrap right)] (wrap (n/+ a b)))) diff --git a/stdlib/source/test/lux/host/jvm.jvm.lux b/stdlib/source/test/lux/host/jvm.jvm.lux index d8224d214..73cf967f9 100644 --- a/stdlib/source/test/lux/host/jvm.jvm.lux +++ b/stdlib/source/test/lux/host/jvm.jvm.lux @@ -37,7 +37,7 @@ (-> Text Binary (IO Text)) (let [file-path (format name ".class")] (do io.monad - [outcome (do (error.with-error @) + [outcome (do (error.with @) [file (: (IO (Error (File IO))) (file.get-file io.monad file.system file-path))] (!.use (:: file over-write) bytecode))] -- cgit v1.2.3