functional programming - OCaml function syntax error -


the following code gives error:

let alpha = hashtbl.create 26 in let print_and_add =     print_char a;     hashtbl.add alpha true;; let str = read_line () in string.iter (fun x -> if hashtbl.mem alpha x=false print_and_add x) str 

what it's supposed do:each time function called (with char argument),it should print char,and add hash table (alpha). tried using other syntax functions:

let alpha = hashtbl.create 26 in let print_and_add = (fun ->     print_char a;     hashtbl.add alpha true) in let str = read_line () in string.iter (fun x -> if hashtbl.mem alpha x=false print_and_add x) str 

but still want know why first code fails. -thanks help.

the ;; symbol marks end of expression @ global level. after has part of different expression. hence alpha can't defined after that.

i never use ;; in source code, when typing toplevel. in opinion, that's it's for.

your code has let print_and_add ... without corresponding in. valid @ global level (not inside expression).

if change ;; in in original code, works. @ least works me.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -