jcreigh has quit ["Do androids dream of electric sheep?"]
ramkrsna has joined #ocaml
Smerdyakov has quit ["Leaving"]
ski_ has joined #ocaml
ski has quit [Nick collision from services.]
ski_ is now known as ski
Submarine has quit [Read error: 113 (No route to host)]
Skal has joined #ocaml
Submarine has joined #ocaml
pango is now known as pangoafk
zedrdave has joined #ocaml
<zedrdave>
good morning...
<zedrdave>
I have sort of a silly question, but no amount of googling managed to get me the answer...
<zedrdave>
I'm trying to have a simple ocaml script output shown in the terminal...
<zedrdave>
basically the way it would if I was to start interactive mode and #use "this_file.ml"...
<zedrdave>
is there an option to the 'ocaml' command that would do that?
<zedrdave>
(obviously I checked the doc and didn't see any)
pangoafk is now known as pango
<pango>
zedrdave: I'm not sure I understand the question...
<zedrdave>
pango: well... right now I have a small .ml script...
<zedrdave>
since I use my own editor, I'd like an easy way (preferably a single command line) to run the file and get its ocaml output to the terminal...
<zedrdave>
currently, if I do $ocaml my_file.ml
<zedrdave>
I only get syntax errors if any... no output...
<zedrdave>
of course, if I run the interactive shell then loads the file, it works... but this is a bit of a pain...
<pango>
and what did you expect to be displayed ?
<pango>
the expressions, before they're being evaluated ?
<zedrdave>
exactly the same as what the interactive shell does, line-by-line evaluation...
<zedrdave>
I don't really "expect" it to... I realize it's normal behaviour not to... just wondering if there was a verbose mode somewhere or a shortcut that would be equivalent to "open as interactive, then load file x"
<pango>
not afaik, but I didn't really feel the need to use the interpreter that way... When I do, I run it inside emacs...
<zedrdave>
I know... I usually use tuareg and it does it for me...
<zedrdave>
but right now I need to use BBedit on OS X... which is nice and works...
<zedrdave>
except for the part where I need to run the file.
<zedrdave>
but anyway, thanks for taking the time...
<zedrdave>
while I'm at it, I have another much more rtfm-like one: what's the list -> array conversion function (keep forgetting it, can't find it in the doc)...
<pango>
Array.of_list I suppose
<zedrdave>
damn. why was I trying of_List all along... :/
<zedrdave>
thnx
<pango>
for previous question, if you use a compiler (ocamlc or ocamlopt) instead of ocaml, you can try -i flag
<pango>
it will display inferred types, but not the expressions themselves (that will just get evaluated)
<zedrdave>
nah, it's really small scripts, I don't compile it, I merely want to check it produces the right function prototypes...
<zedrdave>
this is halfway there ;)
<zedrdave>
it would still help getting expressions
<pango>
well, if you look closely at ocaml toplevel, it's just a loop bolted on top of the bytecode compiler ;)
<zedrdave>
I see...
<zedrdave>
oh, I'm sure it wouldn't be that hard to put together a shel exec...
<zedrdave>
just being lazy and trying to figure out The Best Way(tm)
<zedrdave>
any way to load toplevel with a certain cmd by default (e.g. #use thisfile)
<pango>
I think it uses ~/.ocaml (or is it ~/.ocamlrc ?)
<zedrdave>
ok... g2g, but I'll check into that later... thanks for all the help
<pango>
~/.ocamlinit
<pango>
yes, that's it
love-pingoo has joined #ocaml
zedrdave has quit []
Tachyon76 has joined #ocaml
Revision17 has joined #ocaml
lchou1 has joined #ocaml
revision17_ has quit [Read error: 110 (Connection timed out)]
slipstream has joined #ocaml
slipstream-- has quit [Read error: 110 (Connection timed out)]
ski has quit [Connection timed out]
ski has joined #ocaml
finelemon has joined #ocaml
finelemo1 has quit [Read error: 110 (Connection timed out)]
mikeX has joined #ocaml
chessguy has joined #ocaml
zmdkrbou has quit [Read error: 104 (Connection reset by peer)]
zmdkrbou has joined #ocaml
Schmurtz has quit [Read error: 113 (No route to host)]
Purice has joined #ocaml
chessguy2 has joined #ocaml
<pango>
For what it's worth, just found Kaya... http://compsoc.dur.ac.uk/kaya/ ... A language for web development that seems to share a lot of properties with ocaml... The way it's used look more like a statically typed PHP, however, nothing fancy
chessguy has quit [Nick collision from services.]
chessguy2 has quit [Client Quit]
andreas_1 has joined #ocaml
<andreas_1>
hi all
<mikeX>
pango: it's syntax hearts my eyes though
love-pingoo has quit [Read error: 110 (Connection timed out)]
love-pingoo has joined #ocaml
<andreas_1>
is there something like enums in enums ocaml?
<mikeX>
andreas_1: can you give an example?
<andreas_1>
I would like to iterate over an array with arr.(STATE_X) where X can be 1 to 10
<mikeX>
hm, I still don't understand
<pango>
he's looking for ordered constructors, or something like that... I don't think there's an equivalent in ocaml
<andreas_1>
well I could use variable declarations such as "let state_1 = 1 and state_2 = 2 ..." and then use those variables to index the array, but...
<andreas_1>
it's not very nice since those variables are not really variable but constant throughout the program
<andreas_1>
any ideas?
<pango>
let states = [| STATE_1; STATE_2; STATE_3; STATE_4; STATE_5; ... |] ?
<pango>
then use Array.iter or Array.iteri over states ?
<andreas_1>
and STATE_1 etc. are constructors?
<pango>
yes
<andreas_1>
but what if I want to do arr.(STATE_3) <- somevalue?
<andreas_1>
that would force me to use a hashtbl, right?
<pango>
arrays indexes are ints, no matter what
<andreas_1>
that's the problem :)
<pango>
actually you could use Obj.magic to get constructors interval value, but I don't know if it's considered good practice ;)
<pango>
# type states = STATE_1 | STATE_2 | STATE_3 | STATE_4 | STATE_5 ;;
<pango>
# (Obj.magic (STATE_3):int ) ;;
<pango>
- : int = 2
<andreas_1>
looks scary
<pango>
the safest way is to write mapping functions
<pango>
let int_of_state = function
<pango>
| STATE_1 -> 1
<pango>
| STATE_2 -> 2
<pango>
...
<andreas_1>
but I want easy syntax, I will have to use those indices all over the place ;)
<ppsmimou>
why don't you define the type state = int
<ppsmimou>
and hide it in a module
<ppsmimou>
?
<andreas_1>
can you give an example, pls?
chessguy has joined #ocaml
<ppsmimou>
type state = int
<ppsmimou>
let int_of_state s = s
<ppsmimou>
etc.
<ppsmimou>
of course you say that int_of_state : state -> int
<andreas_1>
I don't get it
<ppsmimou>
here your state don't really need to be an inductive type
<ppsmimou>
just using an int would be better
<ppsmimou>
but if you want to have mor type-safety
<pango>
then you hide it with an abstract type ?
<ppsmimou>
yes
<ppsmimou>
that's I would do
<ppsmimou>
+what
<ppsmimou>
having numerous constructors for a type is often the sign of a design problem
<pango>
then they couldn't be used directly as array indexes, the only win is that mapping functions are straightforward ;)
<ppsmimou>
of course, hiding the array functions in the module too would be much nicer
<andreas_1>
couldn't I just create constants with ints as values?
<pango>
that's a possibility, if you give up some type safety
<pango>
STATE_2 + 2 will be correctly typed, for example ;)
<pango>
(or rather state_2 in that case; capital will no longer be usable)
<andreas_1>
ok, I think I could live with that, how can I create constants in ocaml?
<ppsmimou>
let state_2 = 2
<pango>
yes
<andreas_1>
hmm, ok so I will have to go with that I guess, thx for your help
<mikeX>
andreas_1: maybe you are thinking about your problem in the wrong way
<andreas_1>
how?
<mikeX>
I don't know really, I'm just speculating that there might be a way to express it more naturally in ocaml
<andreas_1>
I would like to use some kind of constant identifiers instead of integers as indices
<mikeX>
*fan*
<mikeX>
oops, wrong window yet again
<andreas_1>
sorry guys, I have to go, see you tomorrow