Module Yocaml_unix

A runtime describes the set of "low-level" primitives to operate in a specific context. This separation allows to have a pure and platform agnostic kernel (the Yocaml module) and to define specific runtimes as needed. Here is the runtime for UNIXish (OSX/Linux).

API

val execute : 'a Yocaml.Effect.t -> 'a

Executes a YOCaml program using the UNIX Runtime.

val serve : filepath:string -> port:int -> unit Yocaml.t -> unit Lwt.t

serve ~filepath ~port engine will serve, a bit like the sad python server, a static directory ... in addition, the function takes an OCaml program and re-executes it on every HTTP request that does not point to a 404. Very handy for continuous content development!

Runtime

Inclusion of the runtime to be able to use Yocaml_unix as runtime directly.

include Yocaml.Runtime.RUNTIME with type 'a t = 'a
type 'a t = 'a
val bind : 'a t -> ('a -> 'b t) -> 'b t
val return : 'a -> 'a t
val get_time : unit -> float t

get_time () should returns a float like Unix.gettimeofday ().

val file_exists : Yocaml.Filepath.t -> bool t

file_exists path should returns true if path exists (as a file or a directory), false otherwise.

val target_exists : Yocaml.Filepath.t -> bool t

Same of file_exists but acting on the target.

val is_directory : Yocaml.Filepath.t -> bool t

is_directory path should returns true if path is an existing file and if the file is a directory, false otherwise.

val get_modification_time : Yocaml.Filepath.t -> int Yocaml.Try.t t

get_modification_time path should returns a Try.t containing the modification time (as an integer) of the given file. The function may fail.

val target_modification_time : Yocaml.Filepath.t -> int Yocaml.Try.t t

Same of get_modification_time but acting on the target.

val read_file : Yocaml.Filepath.t -> string Yocaml.Try.t t

read_file path should returns a Try.t containing the content (as a string) of the given file. The function may fail.

val content_changes : Yocaml.Filepath.t -> string -> bool Yocaml.Try.t t

content_changes filepath new_content check if the content of the file has been changed.

val write_file : Yocaml.Filepath.t -> string -> unit Yocaml.Try.t t

write_file path content should write (create or overwrite) content into the given path. The function may fail.

val read_dir : Yocaml.Filepath.t -> Yocaml.Filepath.t list t

read_dir path should returns a list of children. The function is pretty optimistic if the directory does not exist, or for any other possible reason the function should fail, it will return an empty list.

val create_dir : ?file_perm:int -> Yocaml.Filepath.t -> unit t

create_dir path is an optimistic version of mkdir -p, the function extract the directory of a file and create it if it does not exists without any failure.

val log : Yocaml.Log.level -> string -> unit t

log level message justs dump a message on stdout.

val command : string -> int t

command cmd performs a shell commands and returns the exit code.