## Copyright (c) Eduardo Julian. All rights reserved. ## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ## If a copy of the MPL was not distributed with this file, ## You can obtain one at http://mozilla.org/MPL/2.0/. (;import lux (lux (meta macro ast) (control (functor #as F) (monad #as M))) (.. list (text #as T #open ("text:" Text/Monoid)))) ## [Types] (deftype #export (IO a) (-> (,) a)) ## [Syntax] (defmacro #export (io tokens state) (case tokens (\ (list value)) (let [blank (symbol$ ["" ""])] (#;Right [state (list (` (_lux_lambda (~ blank) (~ blank) (~ value))))])) _ (#;Left "Wrong syntax for io"))) ## [Structures] (defstruct #export IO/Functor (F;Functor IO) (def (F;map f ma) (io (f (ma []))))) (defstruct #export IO/Monad (M;Monad IO) (def M;_functor IO/Functor) (def (M;wrap x) (io x)) (def (M;join mma) (mma []))) ## [Functions] (def #export (print x) (-> Text (IO (,))) (io (_jvm_invokevirtual "java.io.PrintStream" "print" ["java.lang.Object"] (_jvm_getstatic "java.lang.System" "out") [x]))) (def #export (println x) (-> Text (IO (,))) (io (_jvm_invokevirtual "java.io.PrintStream" "println" ["java.lang.Object"] (_jvm_getstatic "java.lang.System" "out") [x])))