ocamlpro / tryocaml Goto Github PK
View Code? Open in Web Editor NEWAn interactive tutorial to begin learning with OCaml
Home Page: try.ocamlpro.com
An interactive tutorial to begin learning with OCaml
Home Page: try.ocamlpro.com
What I type:
# module X = struct
let x = 1
end
What it gets parsed into:
# module X = struct
# let x = 1
# end;
File "", line 3, characters 0-3:
Error: Syntax error
# ;
File "", line 3, characters 3-5:
Error: Syntax error
The same works with Chromium.
result
in the following code is nan
in the tryocaml toplevel but 2.0
(as expected) in a standard OCaml installation:
type _ t =
Int : int -> int t
| Float : float -> float t
| AddIF : (int -> float -> float) t
| App : ('b -> 'a) t * 'b t -> 'a t
let rec eval : type a. a t -> a = function
| Int n -> n
| Float f -> f
| AddIF -> (fun i f -> float i +. f)
| App (f, x) -> (eval f) (eval x)
let result = eval (App (App (AddIF, Int 1), Float 1.0))
I came across this while experimenting with the GADT examples in the OCaml manual.
Whats up with this??
Thanks!!!!
File "", line 1, characters 9-12:
Error: This expression has type float but an expression was expected of type
int
val x : float = 1.
The evaluation of “exit 0” returns a value typed 'a, leading to weird behaviors.
This can be convenient for people interested in TryOCaml
We should save the current lesson and step in a cookie (and maybe also the language ?)
On http://try.ocamlpro.com/ , typing "aa" > "bb" ;; does not print anything
I use Chrome 16.0.912.63 m
Welcome to TryOCaml (v. 3.12.1)
# "aa" > "bb";;
#
Other operators and other input types seem to work fine.
#3 > 4;;
- : bool = false
# "a" < "4";;
- : bool = false
It would be nice to have Graphics working in the toplevel.
HTML canvas (http://en.wikipedia.org/wiki/Canvas_element) seems a good candidate.
for such input, for example
# let rec f: 'a. 'a -> 'a = fun x -> f (f x);;
val f : 'a -> 'a = <fun>
# f 1;;
# f "";;
#
When defining functions that span more than one line and manually hitting Enter on Try Ocaml website, the online toplevel will automatically add semicolon ending. In such situations this is undesirable behavior because my function definition is yet to be continued on the next line.
Example:
When you type the first line of Lesson 4 Step 1 into toplevel and hit Enter, the statement will be automatically ended (notice the undesirable semicolon below) and executed, and thus caused errors:
Characters 34-36:
Error: Syntax error
Here's Lesson 4 Step 1 function:
let string_of_int x = match x with
| 0 -> "zero"
| 1 -> "one"
| 2 -> "two"
| _ -> "many"
The URL should be used to pass different options:
Last js_of_ocaml update apparently forgot to "git add" the keycode files.
Do you really still need to bundle the js_of_ocaml sources?
On my Android phone, I cannot use the toplevel, because the return key does not have the correct behavior.
I think it would be worth having a "Execute" button, in such cases.
From time to time, it can be useful to have a console to interact with OCaml programs:
To reproduce:
Take clean http://try.ocamlpro.com/
Paste the following, line by line:
let f x = x x;;
let f x = (x, x);;
let c f = fun x -> f (f x);;
c f;;
let g x = f (f x);;
type r = {fu : 'a . 'a -> 'a};;
Then type the following line by hand, one by one character:
let c r = fun x -> r.fu (r.fu x);;
Press enter and we get errors from 3 separate chunks. Feels like extra ";;" are inserted randomly.
What we see at the end (see below) doesn't contain the last line as it was entered - it is changed in place.
.................
val g : 'a -> ('a * 'a) * ('a * 'a) = <fun>
# type r = {fu : 'a . 'a -> 'a};;
type r = { fu : 'a. 'a -> 'a; }
# let c r = fun x
File "", line 1, characters 13-14:
Error: Syntax error
# ->
File "", line 1, characters 16-18:
Error: Syntax error
# r.fu (r.fu x);;
File "", line 1, characters 19-20:
Error: Unbound value r
Tryocaml provides a read_string function
but there is no such function in Pervasives. I don't know if this is intentional.
There is instead a function read_line in Pervasives, and tryocaml knows about it,
but it fails:
Exception: ReferenceError: caml_ml_input_scan_line is not defined.
Note: the message "Enter your answer" when prompted for standard input is misleading. "Enter some integer" (for read_int), "Enter some string" (for read_line), etc. or simply "Standard input" would be more suited.
Jean-Christophe
Cannot build from source using OCaml 4.00, neither using opam: there are a lot of cmi libs that cannot be used.
I got this in the terminal of Try OCaml :
is_capital 'a' ==> Exception: Failure "Not a valid letter".
is_capital 't' ==> Exception: Failure "Not a valid letter".
Instead, I would expect :
is_capital 'a' ==> - : bool = false
is_capital 't' ==> - : bool = false
It seems that is_capital provides the wrong result only with 'a' .. 'z' characters.
I reseted the terminal and retried, I got the same problem.
Thank you for your website.
I am getting spurious syntax errors, because apparently the parsing sometimes only takes part of my input, sometimes cutting in the middle of a word. Maybe some flush is missing somewhere ? However, the history remembers the input correctly.
I am using firefox 10.0.3 and the online version of tryocaml.
Thanks for the nice work, still. My adaptation Try RTT is almost ready ! (but the lack of support for recursive modules in js_of_ocaml troubles me).
Github algorithm to detect generated javascript file is described here:
https://github.com/github/linguist/blob/master/lib/linguist/blob_helper.rb#L266
it is based on the average_line_lenght which should be greated than 100. In this case, it will not count the file when he does file statistics and it will not display it in commit messages. A good consequence is that the project will become listed in the OCaml projects instead of in the JavaScript ones.
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".
Trying the following on http://try.ocamlpro.com :
print_string = print_string;;
results in:
- : bool = true
but should result in:
Exception: Invalid_argument "equal: functional value".
It would be nice to be able to have the console in full-screen mode
This function in Lesson 4 Step 4:
let second_element = function
| [] -> failwith "the list is empty"
| [_] -> failwith "the list contains only one element"
| ::e:: -> e
throws a "the list contains only one element" exception for every list of size 1 or greater.
In 4.01, the Graphics' function is named "loop_at_exit"
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Graphics.html
The offending code is in ocaml-num/nat.ml
:
let num_leading_zero_bits_in_digit nat int =
let d = ref nat.(int) in
let n = ref length_of_digit in
if !d land 0xFFFF0000 <> 0 then (n := !n - 16; d := !d lsr 16);
if !d land 0xFF00 <> 0 then (n := !n - 8; d := !d lsr 8);
if !d land 0xF0 <> 0 then (n := !n - 4; d := !d lsr 4);
if !d land 0xC <> 0 then (n := !n - 2; d := !d lsr 2);
if !d land 0x2 <> 0 then (n := !n - 1; d := !d lsr 1);
!n - !d
The first literal, 0xFFFF0000
, provokes a compile-time failure on 32bits OCaml version.
The flags should change the URL (and thus, reset the terminal). Maybe add a cookie to save the language too.
It is different from set_lang "fr" that only changes the current language.
If one installed ocaml elsewhere than in /usr, then make fails with:
make[1]: Entering directory `/home/rixed/src/tryocaml/cmicomp'
cp -f ../js_of_ocaml/lib/*.cmi .
cp -f ../js_of_ocaml/lib/js_of_ocaml.cma .
./cmicomp -without-log CSS.cmi event_arrows.cmi js.cmi typed_array.cmi dom.cmi file.cmi json.cmi url.cmi dom_events.cmi firebug.cmi lwt_js.cmi webGL.cmi dom_html.cmi form.cmi regexp.cmi xmlHttpRequest.cmi
make[1]: ./cmicomp: Command not found
because cmicomp dashbang rely on /usr/bin/ocamlrun.
When building from sources, can't cmicomp be recompiled instead.?
It says:
# Dom_html.document##getElementById (Js.string "asdf");;
Exception: ReferenceError: caml_js_meth_call is not defined.
# Dom_html.window##alert (Js.string "");;
Exception: ReferenceError: caml_js_meth_call is not defined.
Do you have similar problems?
A very simple textarea where to write text, and a button to push the text into the terminal, and another button to download the text.
I was going through lesson 20, and I noticed this weird pattern. I'm clicking through the pieces of code on the left, which are sent to the toplevel on the right. Everything is fine until I reach to "type 'a t = Leaf of 'a | Node of ('a * 'a) t". I need to click three times before the toplevel accepts its. The first two times, it reports a syntax error, even though there is none. See excerpt from the session below. I can consistently reproduce the issue with firefox 9.0, but the issue doesn't show up on chromium.
# let f : 'a -> 'a = function x -> x + 1;;
val f : int -> int = <fun>
# let f : 'a.'a -> 'a = function x -> x + 1;;
Characters 22-41:
Error: This definition has type int -> int which is less general than
'a. 'a -> 'a
# type 'a t = Leaf of 'a | Node of ('a * 'a) t;;
Characters 11-12:
Error: Syntax error
# type 'a t = Leaf of 'a | Node of ('a * 'a) t;;
Characters 25-29:
Error: Syntax error
# type 'a t = Leaf of 'a | Node of ('a * 'a) t;;
type 'a t = Leaf of 'a | Node of ('a * 'a) t
The console doesn't work on safari 5.1.2, I'm using osx lion 10.7.2.
We need something like input_line for interactive examples, where some OCaml code needs to ask the user to enter a value.
The current size of the terminal fits well courses, but for longer sessions, it might be useful to have a bigger terminal (with more lines, maybe more columns too).
It would be nice to get the log of everything that was typed in the toplevel, maybe even get the session log too (i.e. only the input, and both the input and output).
There should be a ChangeLog on the start page to display some news:
When opening try.ocamlpro.com, a box opens and tells me "exception Not_found during init" (though everything seems to work).
The same happens for /js_of_ocaml/
I'm using Iceweasel 23.0.1 on a Debian sid system.
This function in Lesson 4, Step 4:
let second_element = function
| [] -> failwith "the list is empty"
| [_] -> failwith "the list contains only one element"
| ::e:: -> e
throws a "the list contains only one element" exception for every list of size 1 or greater.
It would be nice to have the possibility to increase the length of the lines in the toplevel. It would be even better if we could set the size with a command in the toplevel, and a button to increase/decrease it.
I'd like to build tryocaml for a custom version of OCaml. What's the procedure for generating the cmicomp binary?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.