<IamUnix>
With Caml, is it possible to do C like pointers and pre-processing ?
<adrien>
pre-processing, not in the language (like in C's case actually): there's camlp4 and a number of existing syntax extensions for it
<adrien>
define "C-like pointers"
arquebus has joined #ocaml
<IamUnix>
adrien, OK - yes, I mean such: float *px; px = &x;
<adrien>
no
<adrien>
but if you tell us what you are trying to achieve (and not only "how"), we might help better
<IamUnix>
adrien, i am learning Caml, from my C, Java experience, just comparing what i can and what i cant. To quickly catch the basics.
<IamUnix>
Can i do something like this ? struct computer { float cost; int year; int cpu_speed; char cpu_type[16]; }; typedef struct computer SC;
vincenzoml has joined #ocaml
<vincenzoml>
Hi there, I'm trying to learn ocsigen. I can't start the web server for the first example in the tutorial: Fatal error: cannot load shared library dlllwt-unix - Reason: dlllwt-unix.so: cannot open shared object file: No such file or directory
<vincenzoml>
the dlllwt-unix.so library is in /usr/local/lib/ocaml/stublibs/dlllwt-unix.so
<djcoin>
vincenzoml: there is a specific #ocsigen channel by the way
<vincenzoml>
ah thanks, I did not know
Yoric has quit [Ping timeout: 245 seconds]
<vincenzoml>
I'll ask again there
<djcoin>
:)
<adrien>
it'll be interesting to say which OS you're running and how you're installing everything
<vincenzoml>
thanks adrien :)
<IamUnix>
Do i have possibility to do such `union` in Caml e.g: union automobile { int year; } sedan; union automobile *pointer; pointer->year = 1997;
<IamUnix>
or something: struct survey { int year; union { int year; } provider; }
<flux>
iamunix, hmm, your example doesn't really make sense even in C
<flux>
you need to have at least two elements you make a union out of for it to make sense..
<adrien>
unions, no, because they're unsafe
<flux>
but probably you want to use ocaml sum types
<adrien>
flux: never read the code of the linux kernel ;-)
<IamUnix>
OK
<adrien>
but as flux said, there is a different mechanism
<flux>
adrien, they have single-field unions?
<adrien>
flux: of course :-)
<adrien>
socket code
<IamUnix>
Can i do such: enum { success, fail, max_len = 81 } , the term `enum` or typedef int twobyte; twobyte i, j; ?
<flux>
iamunix, you have type aliases in ocaml. if you want to have constants, you just put a name to them; all variables in ocaml are const by default
<IamUnix>
OK
<mfp>
IamUnix: the idiomatic equivalent of both unions and enumerations in OCaml is sum types (= disjoint unions)
<flux>
probably you want to use sum types for those as well, though, and have a separate way to map them into numbers if you want
<IamUnix>
I am trying to language casting. To understand quickly. nvm.
<flux>
"success, fail, max_len" is an example of code ocaml probably wouldn't have
<IamUnix>
Can i do goto stuff such as in C: label-name: statement1; statement2; goto label-name;
<flux>
there is no goto in ocaml
<flux>
I think it's time for you to introduce to some ocaml tutorials and documentation ;)
<flux>
(s/introduce/introduce yourself/)
<IamUnix>
OK - Thank you.
<djcoin>
Goto statements
<djcoin>
lol
emmanuelux has joined #ocaml
arquebus has quit [Remote host closed the connection]
<IamUnix>
NVM, just casting language for better/quick catch. Can i do Java like mapping to any object? e.g: private static Map<String, JTextField> currentComponents = new HashMap<String, JTextField>();
<djcoin>
IamUnix: do you really think java is close to OCaml ?
<IamUnix>
Those type of terms: private static Map<String, JTextField> currentComponents = new HashMap<String, JTextField>(); OR private static List<JTextField> list = new ArrayList<JTextField>(); OR type cast JTextField goal = (JTextField) (JTextComponent) (Object) "serverTextField";
<IamUnix>
Map or List or multiple cast from right to left...
* ski
is not sure what IamUnix is asking about
<IamUnix>
OCaml cheat-sheet for background of C/Java users.
<ski>
i'm not sure sure a cheat-sheet would make much sense ..
<djcoin>
IamUnix: what don't you just send the whole program you are trying to convert line by line ? :)
<ski>
.. except to tell you to forget most of what you know from C or Java :)
<ski>
IamUnix : there are no casts in O'Caml
<IamUnix>
OK
<ski>
(you can convert from a subtype to a supertype (but not vice versa), though)
Tobu has quit [Quit: No Ping reply in 180 seconds.]
bitbckt has quit [Ping timeout: 260 seconds]
bitbckt_ is now known as bitbckt
bitbckt has quit [Changing host]
bitbckt has joined #ocaml
_andre has joined #ocaml
struktured has joined #ocaml
gnuvince has quit [Ping timeout: 245 seconds]
cdidd has quit [Ping timeout: 276 seconds]
djcoin has joined #ocaml
cdidd has joined #ocaml
ski has quit [Read error: Operation timed out]
kmicinski has joined #ocaml
lamawithonel has joined #ocaml
kmicinski has quit [Read error: Operation timed out]
gnuvince has joined #ocaml
Znudzon has joined #ocaml
zuymanto has quit [Quit: zuymanto]
yezariaely has quit [Ping timeout: 248 seconds]
kmicinski has joined #ocaml
lamawithonel has quit []
bjorkbsd has quit [Read error: Operation timed out]
<everyonemines>
IamUnix: your goto example would be: let rec loop() = statement1; statement2; loop()
<everyonemines>
or for a downward goto, an exception
<everyonemines>
ocaml exceptions are fast enough that you can use them like that
<djcoin>
goto are such an essential programming feature and best practice :>
ski has joined #ocaml
<IamUnix>
Thanks!
<everyonemines>
if you want to map, you do it like
<everyonemines>
Array.map [array]
<everyonemines>
er, Array.map [function] [array]
<everyonemines>
read the module reference for the standard library functions
smondet has joined #ocaml
<IamUnix>
OK
<everyonemines>
if you want to do lots of array stuff, you can "open array" then map function array
<everyonemines>
(but remember that modules must be capitalized)
<Ptival>
"open Array"
<everyonemines>
or, Array.(map function array) opens it locally
<everyonemines>
once you get to know ocaml I think you'll like it better than java :-)
<IamUnix>
I hope so :)
<everyonemines>
what kind of thing are you working on?
<everyonemines>
or is it class stuff?
<IamUnix>
Text translations
<Ptival>
(Java is always "class" stuff :p)
<IamUnix>
Chinese to Bengali or reverse etc...
<djcoin>
class stuff, rofl :)
<everyonemines>
That's a pretty tough problem.
<f[x]>
classy!
<everyonemines>
but I like algorithmic stuff :-)
<everyonemines>
IamUnix: Have you done natural language processing stuff before?
<IamUnix>
everyonemines, Not yet. Textual translations right now for one project
<everyonemines>
well, you can learn a lot from working on that, and ocaml is useful, but if you need something now, you might be better off using the google translate api :-/
Sanders_NL has joined #ocaml
<mfp>
according the the gc.mli, let v = ... in Gc.finalise (fun x -> ...) v "will not work as expected" because "anything reachable from the closure of finalisation functions is considered reachable"
ftrvxmtrx has quit [Quit: Leaving]
<mfp>
does that only apply to the case where ... captures v, or is it general? (and if so, why does the closure enclose the whole environment?)
<thelema>
mfp: it only makes sense to me that it's when ... captures v
bjorkintosh has joined #ocaml
<mfp>
hmm maybe there could be "surprise captures" in cases like (fun () -> .... a .... b .... Gc.finalise (fun _ -> ... a .... b ...) c)
<mfp>
in some hypothetical OCaml implementation (AFAIK not the current one) that reused the environment for the outer closure in the inner one
Znudzon_ has joined #ocaml
<thelema>
probably just an over-warning; if people always define their finalization function before declaring their value...
Znudzon has quit [Ping timeout: 240 seconds]
<mfp>
guess so
thelema_ has joined #ocaml
thelema has quit [Ping timeout: 244 seconds]
ocp has quit [Read error: Operation timed out]
cago has quit [Quit: Leaving.]
mika1 has quit [Quit: Leaving.]
avsm has joined #ocaml
kmicinski has quit [Ping timeout: 265 seconds]
kmicinski has joined #ocaml
jamii has joined #ocaml
edwin has joined #ocaml
<hcarty>
orbitz: The upstream PCRE file is missing. I sent the author an email asking about it.
kmicinski has quit [Ping timeout: 244 seconds]
avsm has quit [Quit: Leaving.]
err404 has quit [Quit: Ex-Chat]
avsm has joined #ocaml
everyonemines has quit [Quit: Leaving.]
<ssbr_>
Which of these is generally considered more idiomatic? "let x y z = match z with ..." or "let x y = function ..." ?
<hcarty>
ssbr_: I'm not sure which is generally considered more idiomatic, but I use the first when there are multiple arguments and the second when there is only one.
<ssbr_>
Yeah. I just don't know if this currying stuff is _actually_ confusing, or if it's just something I'm not used to yet, you know?
<ssbr_>
It's difficult to edit this codebase because it was written by two people: one who was really good at ocaml, and one who was really bad.
<ssbr_>
(worse than me, and I just started, really.)
<ssbr_>
This is not confusing though, so it's not like that this time. I'll leave it as is.
<hcarty>
ssbr_: That's why I have that split - I find it a bit easier to read the resulting code as a human.
<hcarty>
When there are multiple arguments I have found that throwing "= function" on the end makes it more difficult to parse the function at a glance.
<ssbr_>
Yeah, that's what I figured.
<ssbr_>
Hm. Reading the body of this function, it might have been written by the bad programmer. But the good programmer is the one that loves currying everything...
<ssbr_>
Aieie
<ssbr_>
By the way, what is "||" in ocaml?
<ssbr_>
errr, wait, I think that's [||]
<ssbr_>
is that an empty array?
<Qrntz>
ssbr_, yes, [| |] is an empty array
<Qrntz>
the amount of whitespace between the braces is arbitrary
<Qrntz>
«||» is a logical OR
<ssbr_>
Right, I realized my question was ambiguous slightly too late. :(
<ssbr_>
(and that the braces were probably part of the syntax -- the return type was array)
<Qrntz>
[ || ] wouldn't make sense
<Qrntz>
so, perhaps
<ssbr_>
Thanks :)
<Qrntz>
you're welcome
<f[x]>
[(||)]
Znudzon_ has quit [Remote host closed the connection]
eni has joined #ocaml
Submarine_ has joined #ocaml
Submarine_ has quit [Changing host]
Submarine_ has joined #ocaml
edwin has quit [Quit: Leaving.]
avsm has quit [Quit: Leaving.]
eikke has quit [Read error: Operation timed out]
Sablier has joined #ocaml
eni has quit [Ping timeout: 250 seconds]
Yoric has quit [Ping timeout: 245 seconds]
IamUnix has quit [Quit: Nothing]
djcoin has quit [Quit: WeeChat 0.3.2]
kmicinski has joined #ocaml
antegallya has joined #ocaml
kmicinski has quit [Ping timeout: 248 seconds]
ftrvxmtrx has joined #ocaml
kmicinski has joined #ocaml
eikke has joined #ocaml
kmicinski has quit [Ping timeout: 250 seconds]
gnuvince has quit [Ping timeout: 240 seconds]
Reventlov has quit [Ping timeout: 248 seconds]
Reventlov has joined #ocaml
eikke has quit [Ping timeout: 248 seconds]
Yoric has joined #ocaml
avsm has joined #ocaml
pangoafk is now known as pango
snearch has joined #ocaml
gnuvince has joined #ocaml
snearch has quit [Quit: Verlassend]
eni has joined #ocaml
pango has quit [Ping timeout: 265 seconds]
snearch has joined #ocaml
Sanders_NL has quit [Remote host closed the connection]
pango has joined #ocaml
eni has quit [Ping timeout: 252 seconds]
zuymanto has joined #ocaml
avsm has quit [Quit: Leaving.]
fooc has quit [Quit: leaving]
Snark has quit [Quit: Quitte]
Sablier_ has joined #ocaml
Sablier has quit [Ping timeout: 244 seconds]
itewsh has joined #ocaml
osa1 has joined #ocaml
<osa1>
can anyone recommend me an introduction text for ocaml? I have functional programming(haskell, scheme) experience but I'm not an expert in types and advanced functional programming techniques
<bitbckt>
that's probably the most approachable intro.
<osa1>
bitbckt: thanks
<bitbckt>
np
<bitbckt>
the official manual is thorough, if a bit dry.
<bitbckt>
best used as a reference.
<osa1>
bitbckt: oh, it's from author of real world ocaml ..
<bitbckt>
one of them, yes.
Sablier_ is now known as Sablier
Submarine_ has quit [Quit: Leaving]
<orbitz>
hcarty: thanks
eni has joined #ocaml
gnuvince has quit [Ping timeout: 245 seconds]
tomprince has quit [Ping timeout: 244 seconds]
zuymanto has quit [Quit: zuymanto]
eni has quit [Quit: Leaving]
tomprince has joined #ocaml
thomasga has quit [Ping timeout: 244 seconds]
thomasga has joined #ocaml
thomasga has quit [Client Quit]
osa1 has quit [Ping timeout: 248 seconds]
zuymanto has joined #ocaml
osa1 has joined #ocaml
<wmeyer``>
ssbr: Abuse currying that's what it was designed for. Beware combinators like "flip" and point free coding however. In terms of let foo a b c = ... then 1) Usually my functions are single argument and the rest is the environment outside a closure - but I'm doing a lot of AST transformations - if they have second argument - then it's accumlator or environment - in case of API situations might be very different! 2) If they acc
<wmeyer``>
than one and you need to pattern match for the last argument - I usually use "function", that's for me more idiomatic. In general what type checks and is readable in 80% is enough.
<wmeyer``>
thelema_: I rebased my branch - now you can pull
<ski>
(possible cut off "... 2) If they acc")
gnuvince has joined #ocaml
cdidd has quit [Remote host closed the connection]
Yoric has quit [Ping timeout: 250 seconds]
Se7en has joined #ocaml
zuymanto has quit [Quit: zuymanto]
tomprince has quit [Ping timeout: 245 seconds]
tomprince has joined #ocaml
<osa1>
is there a way to load a source into ocaml repl? like :load in haskell's ghci
<gildor_>
#load ?
<Qrntz>
#use "file.ml" ;;
<osa1>
thanks
<Se7en>
yes, use that
eikke has joined #ocaml
BiDOrD_ has joined #ocaml
BiDOrD has quit [Ping timeout: 252 seconds]
itewsh has quit [Quit: o/]
smondet has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
<orbitz>
Does the run time gurantee the order modules are executed in, fo rexample can I have a module register itself with a plugin registry like let () = Registry.register yadda;; or could it be possible Registry has not ben initialized yet?
osa1 has quit [Quit: Konversation terminated!]
<_habnabit>
orbitz, if you're referencing Registry, then it's been initialized
<_habnabit>
orbitz, initialization order is based on which modules depend on each other
<orbitz>
Excellent
<orbitz>
Is what I am trying to do a good idea?
<_habnabit>
it doesn't seem like a bad idea. the ocaml stdlib already does this.
<orbitz>
Basically I want a factory I guess
<_habnabit>
this doesn't seem like a factory
<Qrntz>
I would be very interested in something like that
<orbitz>
Being able to handle multiple database types at runtime, for example
<Qrntz>
(a plugin factory)
<_habnabit>
it's a registry
<orbitz>
_habnabit: Well, I'd register with it, then when I want a new db connection i'd say Registery.get db_type
<orbitz>
and then I'd have a record (or something?) that has functiosn to play with a db
<_habnabit>
if you're using 3.12, you could use modules-as-values
<orbitz>
Yeah, I don't think that necessarily changes much though
<orbitz>
I'd still eb doing a .get somewhere, right?
<_habnabit>
well, yeah
<_habnabit>
I just mean instead of a record
<orbitz>
Yeah
<orbitz>
I'd probably have get really be .connect or soemthign and give me back something I can use a Connection module on
<wmeyer``>
orbitz: with first class values you can package them and assign to mutable variable during load
<wmeyer``>
orbitz: s/values/modules/
snearch has quit [Quit: Verlassend]
pango has quit [Remote host closed the connection]
mal`` has quit [Ping timeout: 244 seconds]
noamsml[kersh] has quit [Ping timeout: 276 seconds]