OCamlPro / tryocaml

An interactive tutorial to begin learning with OCaml
try.ocamlpro.com
91 stars 39 forks source link

support `open_in` with an URL argument #112

Open gasche opened 11 years ago

gasche commented 11 years ago

The (very real) use case is a desperate university student with no computer at home, and only access to a public computer in his or her school's library, severely restricted (basic Caml installation, no right to install additional libraries or basically write any file on the computer), willing to work on image manipulation in OCaml.

The following could work in TryOCaml:

let image = open_in_bin "http://orion.math.iastate.edu/burkardt/data/bmp/snail.bmp";;
(* then use parsing code from http://pauillac.inria.fr/~cheno/lettre/lettre1.html *)

Current (incorrect) output:

Exception:
Sys_error
 "http://orion.math.iastate.edu/burkardt/data/bmp/snail.bmp: no such file or directory".
hhugo commented 10 years ago

Sys_js.register_autoload allows to do that (with CORS restriction https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) see https://github.com/ocsigen/js_of_ocaml/blob/master/toplevel/toplevel.ml#L146

In the js_of_ocaml toplevel, the following will load http://ocsigen.org/resources/logos/text_js_of_ocaml_with_shadow.png let image = open_in_bin "/http/ocsigen.org/resources/logos/text_js_of_ocaml_with_shadow.png"

cpitclaudel commented 7 years ago

@hhugo Is this documented somewhere? Thanks!