<thEnigma>
Is there a way I can execute multiple commands in one statement in OCaml?
<thEnigma>
for example I am trying to print something and then execute a function.
<aantron>
how about "print_endline "foo"; f x" ?
<Algebr>
let _ = print_endline "hello"; f ();
<Algebr>
yea
<foolishmonkey>
let () = print_endline "hello"; f ();
<foolishmonkey>
it's more strict
<aantron>
foolishmonkey: how so? ; is a binary operator in ocaml
<aantron>
if you have let () = print_endline "hello"; f (); and then on the next line "let something_else = blah"
<foolishmonkey>
if f doesn't return unit a value will be ignored with _ but with () the compiler will complain
<aantron>
ah yes, but you dont want the ; on the end
<foolishmonkey>
sorry let () = pri... in
<aantron>
or without the in if its a declaration (structure item, top-level let, whatever you want to call it)
<foolishmonkey>
Yes, I was thinking toplevel at first
<thEnigma>
so I am using utop. Whenever I try doing something like let () = print_string "hello" ; (1 + 2); I get an error.
<foolishmonkey>
yes, 1 + 2 is not unit
<thEnigma>
I am fairly new to OCaml, so I do not know what I am doing wrong.
<thEnigma>
what is unit?
<aantron>
ok, not sure if we are agreeing, i just wanted to say that two lets in a row with a ; on the end like that will parse as "let () = (print_endline "foo"; f (); let () = more", which is probably not what you want
<foolishmonkey>
let x = print_string "hello"; 1 + 2;;
<aantron>
or "let _ = ..." or "let x = print_string "hello"; ignore (1 + 2);;"
<aantron>
unit is a type with one value, unit, which in OCaml is used a bit like "void" is used in C/Java/etc
<aantron>
err the value is spelled "()" but pronounced unit
<aantron>
when you write "let () = ..." you are telling OCaml that you expect the expression "..." to have type unit
<foolishmonkey>
it's similar to void of C but not the same thing
<aantron>
so OCaml will check that the expression produces "no useful value"
<aantron>
right
damason has joined #ocaml
<thEnigma>
so if I have a function like : let add x y = (let z = print_string "hello"; x + y;), will it be a valid statement?
<aantron>
dang i need to be quiet. my example above should have been "let () = print_string "hello"; ignore (1 + 2);;"
<aantron>
thEnigma: try it in the top level :)
<foolishmonkey>
thEnigma, except at top level, when you introduce a variable (like z in your case) it must be "let z = <Value> in <somethingelse>"
<foolishmonkey>
in your case you don't say in what z is used
<aantron>
you probably want "let add x y = print_string "hello"; x + y;;"
<foolishmonkey>
let add x y = print_string "hello"; x + y;;
<foolishmonkey>
:)
<aantron>
:)
<thEnigma>
so what kind of construct is this? I have used a bit of scheme which used "begin end" construct to accomplish this. Why does this work?
<aantron>
which construct exactly?
<foolishmonkey>
it's the same thing. but with ocaml you can concatenate values/instructions using ;
<aantron>
the ";" is the sequence expression
<aantron>
note not statement
<aantron>
it means execute the first one, then execute the second
<aantron>
or rather e1; e2 is the sequence expression, ; is the sequence operator
madroach has quit [Ping timeout: 248 seconds]
<aantron>
and the result of e1; e2 is the result of e2
<thEnigma>
so how does the type checker know the type of such a sequence?
<aantron>
the type is the type of e2
<aantron>
the type checker also will warn you if e1 doesnt have type unit, because you are implicitly ignoring a value resulting from e1 if thats the case
<thEnigma>
Can you elaborate a bit?
<aantron>
yes, but can you be more specific on what? :)
madroach has joined #ocaml
manizzle has quit [Ping timeout: 264 seconds]
<thEnigma>
Oh, I re-read it. It makes sense now. Thank you so much.
jtmcf_ is now known as jtmcf
<aantron>
i need to be more precise in my vocabulary... e1; e2 joins two expressions e1 and e2, and *evaluating* e1; e2 means evaluating e1, then evaluating e2 :)
sepp2k has quit [Quit: Leaving.]
manizzle has joined #ocaml
<thEnigma>
What does it mean for a language to be type complete?
<thEnigma>
and is OCaml type complete? Is type completeness the same as type correct?
<aantron>
i havent heard either term applied to languages. ive heard of expressions (or other language constructs) being type correct - relative to a language
<aantron>
perhaps someone else can comment, or do you have a reference?
<aantron>
type correctness however is a property of expressions. given a language, an expression might not be type correct, e.g. in OCaml 1 + "foo" is not
<aantron>
i use the word expression loosely here, could apply to declarations, statements, or whatever a language's sentences are called that are subject to type checking
<foolishmonkey>
caml gives garanty that there will be no type error (except if using the devil function)
<thEnigma>
But python won't object to 1 + "foo" or even 1 * "abc"
<foolishmonkey>
many languages don't give such garantee
<aantron>
foolishmonkey: thats soundness though ("type safety")
<aantron>
well python assigns a meaning to 1 + "foo"
<aantron>
OCaml could assign a meaning to 1 + "foo" and still be type safe, and then this expression would be type correct in this new OCaml'
<aantron>
however python expressions dont have the property of type correctness (or type incorrectness) - python doesnt check types
<thEnigma>
Even though I have never used it, I have heard that in C, you can cast between pointers to objects. Doesn't that mess with the type soundness for it?
<foolishmonkey>
there is no objects in C
<aantron>
C is a notorious example of a type-unsound language :)
<thEnigma>
wait, doesn't C have the struct {} construct?
<foolishmonkey>
yes, but it's not objects, it's structs
<aantron>
its close enough
<aantron>
an object is largely a product (a tuple), some pieces of which may be mutable (state) and some may be functions
<thEnigma>
Isn't type soundness a desirable quality in a language? Why wouldn't C have it?
<aantron>
you can have all of that in a struct, the language just doesnt give you special support
<thEnigma>
Oh, I see.
ely-se has quit [Quit: Leaving...]
<aantron>
because type soundness without a garbage collector requires a type system which, despite rust, is still an open research problem
struk|desk|away is now known as struk|desk2
<aantron>
part of type soundness is the idea that if you have an expression "e", the result of which will be, for example, a pointer into the heap, and you evaluate it a little bit, the result would still be a pointer into the heap
<thEnigma>
Why is that? Can't the ideas behind the garbage collectors in, say Java, be used in such a language?
<aantron>
this is difficult to guarantee with manual memory management
<thEnigma>
What is that?
<aantron>
well C doesnt "want" a garbage collector
<aantron>
manual memory management? when you want to get some memory during run time, you have to call "malloc" in C
<aantron>
and when you are done, you have to call "free" yourself
<thEnigma>
So why doesn't C "want" a garbage collector? Something to do with speed?
<aantron>
yes, something to do with implementing unix in the late 60s on ancient hardware, which also makes C great for similar tasks today :)
<Drup>
aantron: you are mixing type soudness and memory soudness
<Drup>
both are desirable, but distinct
<aantron>
Drup: i am being imprecise
<Drup>
you can use types to solve the memory soudness problem (cf Rust) but that's not the only solution
<Drup>
and you can have type soudness without memory soudness (Pascal)
octachron has joined #ocaml
<def`>
Drup: types assert some properties which won't be verified with improper memory management, hence the type system is unsound
<thEnigma>
So can C be type sound or not?
<def`>
(well typed programnwill go wrong)
<Drup>
C is completely type unsound
ygrek_ has joined #ocaml
<Drup>
def`: just with exceptions, depends on "go wrong" ;)
<def`>
no
esad has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<def`>
pascal in practice (freepascal) is equivalent to X
<def`>
C*
<def`>
dereferencing a wrong pointer isn't going to raise an exception, just mess with memory and eventually segfault
<aantron>
Drup: in particular types assert statements about the how a value can be eliminated (used) without causing classes of errors, and with manual memory management as in C it becomes impossible to guarantee these
<foolishmonkey>
segfault can be blocked
<foolishmonkey>
like that the program is not killed
manizzle has quit [Ping timeout: 260 seconds]
<aantron>
thEnigma: no :)
Stalkr has joined #ocaml
<thEnigma>
\help
<Drup>
def`: fair enough, I don't know the semantic of pascal enough :p
Stalkr has quit [Read error: Connection reset by peer]
<aantron>
however, OCaml minus such things as Obj.magic sound, and these things are not typically used, whereas in C, manual memory management is used pervasively
<aantron>
is sound*
<lewis1711>
it's always good to have a backdoor
<def`>
aantron: put another way, OCaml is sound in that it is not going to derive wrong things
<thEnigma>
Wait, I don't understand how OCaml is unsound. I looked at the link you sent me, but it has a bunch of functions.
<aantron>
it has a function 'a -> 'b
<def`>
but you can tell lies if you want.
<foolishmonkey>
the devil function
<lewis1711>
Obj.magic is less elegant than doing the equivalent in C< but at least it's there
<foolishmonkey>
flee mortals
<aantron>
so you can say.. "1 + (Obj.magic "foo")"
<aantron>
lol
<Drup>
lewis1711: "less elegant" ? :D
Stalkr has joined #ocaml
<lewis1711>
Drup, yes less elegant than a void*
<aantron>
lewis1711: im not sure, but you may have signed off for a discussion about type annotations that we had
<lewis1711>
I started it then the connection dropped
<thEnigma>
So how does that make it type unsound? Can't the type checker infer the type of function by it's application?
<aantron>
np, you may want to check the log. talked about the different meanings of 'a in annotations and signatures
manizzle has joined #ocaml
Stalkr_ has joined #ocaml
<def`>
thEnigma: the type checker will always infer correct things, as it is sound. but your program might be unsound if you lied avout external things (which can't be checked)
<lewis1711>
I'm not a big fan of safety weenyism. safe by default is nice, but sometimes hairy things just have to be done.
<thEnigma>
Can you give an example?
<octachron>
Drup, would you mind some comments on the manual part of your PR#342?
Stalkr^ has joined #ocaml
Stalkr_ has quit [Read error: Connection reset by peer]
<thEnigma>
I don't quite understand what you mean by external stuff.
<Drup>
octachron: go on :)
<def`>
(Obj.magic 1 : string) (* 1 is not a string but that's what we are asserting *)
<def`>
thEnigma: Obj.magic is one, but bindings to C functions is the general case
Stalkr has quit [Ping timeout: 250 seconds]
<lewis1711>
thEnigma, sure. mutable data structures, interfacing to C, Obj.magic
<lewis1711>
mutable vars in general
<thEnigma>
When I tried doing that in utop, it threw a parse error saying Error: Parse error: [str_item] or ";;" expected (in [top_phrase])
<def`>
lewis1711: no?! mutable vars and structures are safe
<Drup>
mutable structure are safe
Stalkr^ has quit [Read error: Connection reset by peer]
Stalkr has joined #ocaml
<def`>
thEnigma: you shouldn't bother about such questions as this point :)
<aantron>
(Obj.magic 1 : string);; works for me
<aantron>
produces the expected result :p
<lewis1711>
sorry maybe I missed the discussion. 'safe' in terms of?
<octachron>
Drup, on the attribute section, two typos: "every constructs" → "every construct" and "Those constructs supports" → "... support"
<Drup>
:D
<Drup>
thEnigma: that's the expected behavior
<lewis1711>
yeah but there are some weenies who would consider ocaml 'unsafe' because it doesn't track sideffects
<thEnigma>
Oh, Okay.
Stalkr has quit [Read error: Connection reset by peer]
<aantron>
Drup: it should be a runtime error if entered correctly, not a parse error
<Drup>
Really, the summary is the following: OCaml is both type and memory safe, except when you are trying very hard.
<lewis1711>
"it could launch the nukes!!" is I believe the phrase they use
<aantron>
in particular i got a segfault on my system
<lewis1711>
yeah I got a segfault as well
<aantron>
probably when the top-level tried to print the "string"
<lewis1711>
aantron, utop told me out of memory, so likely
<aantron>
thEnigma: for type safety, first we need to say what a type is.. one way to think of a type is as a set of operations that can be performed on it (correctly)
<def`>
lewis1711: except there is an objective notion of type safety, that's worth discussing about, the rest are opinions
<aantron>
on values of that type*
<lewis1711>
Fair enough. I wouldn't want to use a typesafe language
<aantron>
dang
<aantron>
i need to take a step back
<aantron>
im trying to phrase this without verbiage but everything i come up with that has less than two "such that" is wrong :p
<def`>
:)) irc might not be the most effective medium for such discussions
<aantron>
i just want to get to the point of why Obj.magic 1 : string is not typesafe. in super imprecise terms, its because "being of type" string promises that "String.length" will work among other things
<Drup>
aantron: much simpler: it's accessing pointer 1, since a string is an array
superboum_ has joined #ocaml
<thEnigma>
So do languages like Java check for type safety too? I tried doing something like int x=1; String y = "abc"; System.out.println(x + y); but it didn't fail. It simply cast x into String and showed me the answer.
<aantron>
sure, thats the operation explanation for the error you get, but it doesnt explain why Obj.magic is unsafe in the language
<Drup>
thEnigma: conversions can fail at runtime in Java
<aantron>
thEngima: conversions dont inherently have anything to do with safety
struk|desk2 has quit [Remote host closed the connection]
<foolishmonkey>
thEnigma, you know ASM?
<foolishmonkey>
or C?
<thEnigma>
No
<aantron>
s/operation/operational/
<foolishmonkey>
what languages do you know?
<Drup>
octachron: please post the comment on the PR, I'll fix tomorrow
<thEnigma>
So does Java not check for type soundness at compile time?
<foolishmonkey>
java checks a lot of things
struk|desk has joined #ocaml
<pierpa>
why: Obj.magic 1 : string;; (with no parens) is a syntax error?
<lewis1711>
Println just takes an Object doesn't it/
<aantron>
pierpa: the parens are part of the ascription syntax
badon has quit [Quit: Leaving]
<pierpa>
hmmm
<aantron>
pierpa: these are not optional parens for precedence like most others
<mspo>
you can often get a classcastexception with java doing that stuff
<aantron>
i think Java is largely type sound
<aantron>
not sure what happened with the problem of variance of arrays (and collections?)
<pierpa>
they insert run-time checks
<thEnigma>
Why does't OCaml do things like this? It makes a very clear distinction between its types and even stuff like + and +.
<aantron>
the + and +. thing is ultimately an arbitrary choice, informed by considerations of how to deal with overloading and whether to special-case it for the operators, given that a general system was not avaialble
<aantron>
but see the work on implicits
<aantron>
SML for example overloads +
groovy2shoes has joined #ocaml
<pierpa>
this is a pita in SML. and the not overloading one of the things I like of Ocaml
<thEnigma>
So was it a design decision of the people who build OCaml, or was it because of some specific reason?
<aantron>
it was a design decision for specific reasons that are not strong enough to make it "obviously the right decision", but exist nonetheless
<thEnigma>
What kind of reasons?
<aantron>
pierpa: ocaml inserts some runtime checks too, for example array access is checked
<foolishmonkey>
it can be disabled
<aantron>
which then makes ocaml quite unsound
<aantron>
thEnigma: as i understand it, there was no good approach to function overloading available at the time that OCaml was designed, so they chose to overload no functions at all
<aantron>
overloading in ML-like languages is complicated somewhat by the need to still support type inference
<mspo>
you might be interested to know that perl6 does a lot of compile time checking
<mspo>
for example this does not run: perl6 -e 'my Str $s = "hi"; say $s + 1;'
antkong_ has joined #ocaml
<def`>
overloading is ad hoc polymorphism (function change depending on its type)
<pierpa>
aantron: I mean, Java inserts run-time type casts to overcome the array variance problem
<aantron>
ah, thank you
<thEnigma>
I am trying to make an OCaml program that has external dependencies, but whenever I try to load the main file in utop, it fails and says unbound module <name of dependency>. For example, in a program in which I am implementing a pseudo language, I have a file named "Syntax.ml", now in the main file, I wrote Open Syntax.ml, but it fails.
<def`>
ocaml has a strong emphasis on parametric polymorphism (function is generic for parts which don't affect its behavior)
<foolishmonkey>
overloadin is not polymorphism
<foolishmonkey>
it's jus a way to allow many functions to have the same name
<aantron>
thats polymorphism
<foolishmonkey>
not for me
<foolishmonkey>
but ok
<aantron>
ad-hoc and parametric polymorphism differ only by whether you "analyze" the type of arguments
<fds>
foolishmonkey: You're very confident for someone who's so frequently wrong. :-)
<foolishmonkey>
fds, i will stay polite
<aantron>
in parametric polymorphism analysis is forbidden, in ad-hoc polymorphism the "implementation" depends on the arguments
<octachron>
Drup, done. Don't hesitate to ignore my babbling if you disagree with it.
<aantron>
type of* the arguments
<lewis1711>
thEnigma, ocaml doesn't support doing that. which is a pain
<lewis1711>
or the top level doesn't
<lewis1711>
you have to load all the modules manualy, and in-order, using #mod_use
<lewis1711>
it's not like lisp or ruby
<thEnigma>
So, any ideas how I can test such a program in an interactive environment?
<lewis1711>
no. if you hear of one let me know, I'd be keen
mac10688 has joined #ocaml
<lewis1711>
but I don't know ocaml that way. there might be a way
<lewis1711>
*that well
<thEnigma>
Would something like a REPL work? using ocamlbuid and stuff
<Enjolras>
you can create a .ocamlinit file with all the module loading directive
<aantron>
foolishmonkey: a function foo : 'a -> 'a is a bunch of functions with the name foo, one for each possible type :) of course in some languages it is possible to use one implementation for all the foos, but that is an implementation detail relative to the language
<foolishmonkey>
aantron, it's one function
<foolishmonkey>
there is one binary code for that
<foolishmonkey>
one symbol
<aantron>
foolishmonkey: how about template <typename T> T foo(T &foo) ?
<foolishmonkey>
template are not the same thing
<foolishmonkey>
because they're templates
<aantron>
no, but this function might be completely parametrically polymorphic
<foolishmonkey>
aantron, template are template, they are repeated with variation
<foolishmonkey>
ocaml doesn't repeat a parametric function
<aantron>
i know it doesnt. i am saying this is an implementation detail due to how ocaml is implemented
<foolishmonkey>
it's not a template, it just check that nothing stupid will be done
<aantron>
not an inherent feature of parametric polymorphism
<foolishmonkey>
aantron, no because in that case I can say that two unrelated functions are polymorphic, that;s what overlaod are
<foolishmonkey>
two overloaded functions can have only the name in common
<Enjolras>
thEnigma: you can replace core by your libraries
<foolishmonkey>
and templates are not overload
<aantron>
they are related, by name. a "set" of ad-hoc polymorphic functions can be thought as a "type switch" typically evaluated at compile time, followed by dispatch to the right case
shinnya has quit [Ping timeout: 256 seconds]
<aantron>
which is also an implementation detail
<def`>
foolishmonkey: system F can be implemented with uniform representation of function, where type application is explicit but there is still one synbol. which polymorphism is this? :)
<thEnigma>
I have already done that. Also how do I message pointing to a specific person without making it private?
octachron has quit [Quit: Leaving]
<foolishmonkey>
aantron, what is polymorphism in that case?
<Enjolras>
thEnigma: just mention the name
<thEnigma>
I am using sublime text 2 to edit my OCaml files but it is really annoying how it doesn't ident the things properly. Is there something like DrRacket for OCaml?
<aantron>
not sure what you are asking. what is polymorphism in general?
<foolishmonkey>
def`, i expect from polymorphism to have one code that can accord to many types, templates do it but badly
<aantron>
foolishmonkey: correct, except the issue is not with the definition of the code, but with the usage. if i can vary the types at the use site and the code still makes sense, what i am using is polymorphic
<Enjolras>
thEnigma: merlin. I think it works with sublime text
<foolishmonkey>
aantron, no you're just using two different but realted functions with the same name
<foolishmonkey>
but everything is said, we don't agree
<def`>
foolishmonkey: focusing on generated code is an implementation detail
<foolishmonkey>
def`, I focus more on written code
<def`>
ok
<foolishmonkey>
sorry, I shouldn't have argu with you
<lewis1711>
is there a naming convention for optional values? like if I am searching for an address, "maybe_address" or something?
<aantron>
and the ability to choose that automatically, for one name, is polymorphism
<wolfcore>
thEnigma: I think most of us that write ocaml use emacs, but that's a whole other thing to learn :p
<Enjolras>
lewis1711: i tend to think the type is enough. But if it is confusing, i use maybe_foo
exm has joined #ocaml
<Enjolras>
wolfcore: or vim. Don't be a jerk :>
<wolfcore>
Enjolras: vim doesn't have the same level of integration with REPLs
<wolfcore>
Enjolras: to someone new to both and learning a lisp or an ml-based lang I would recommend emacs first
<thEnigma>
<wolfcore> Would you recommend learning Emacs. I tried using it for scheme, but looked too daunting.
<Enjolras>
whatever. This troll is outdated. But there is vim-slime for integrating with ocaml toplevel and it's not bad
FreeBirdLjj has joined #ocaml
<aantron>
foolishmonkey: a small thought experiment. lets say i had a library with a polymorphic function "val foo : 'a -> 'a bar" that did some crazy stuff. this is nice and parametrically polymorphic in OCaml
<foolishmonkey>
aantron, I say I was sorry to argue with you about that
<wolfcore>
thEnigma: once you get past the initial learning curve it's not too bad. I kept coming back to it every few months and finally stuck with it on the 3rd or 4th try :p
<jtmcf>
I ran into an interesting problem, i'm using utop, emacs 24.5.1, just now learning ocaml, but i was playing around and was just experimenting with parenthesizing an infix operator, such as: (+) 3 5;; ... It did as i expect, but (*) 3 5;; hangs utop. Is something going on here that indicates a bug in some software i'm using or is this not supported in ocaml?
<aantron>
lets say OCaml 5.00 allows specialization of functions at certain types for the purposes of optimization (not saying its a good idea)
<jtmcf>
(using utop in emacs, launched M-x utop --emacs)
<aantron>
if i provide a secondary "foo : char -> char bar" hidden in my library, does foo stop being polymorphic?
<mspo>
what does repl integration mean?
<wolfcore>
Enjolras: not trolling. I switched to Emacs after using Vim for years, it's 100x better for interactive development
<wolfcore>
mspo: you can evaluate expressions in your buffer and send them to Utop
thEnigma has quit [Quit: "Thanks for all the help"]
<wolfcore>
mspo: this is possible in vim as well, though imo in emacs it's more well integrated since emacs is essentially a lisp interpreter with an editor frontend
<mspo>
yeah I've never been able to commit to a switch either
<mspo>
maybe evil mode
<mspo>
wolfcore: I don't quite see what lisp has to do with it :)
seangrove has quit [Ping timeout: 264 seconds]
<wolfcore>
mspo: emacs is written in elisp, hence repls, or at least the ability to develop interactively, is given more forethout as opposed to vim where they're tacked on
<wolfcore>
I'll stop there, since this is discussion is sorta off topic for the channel :^)
<aantron>
nano is the best.. jk :)
<pierpa>
jtmcf: (* starts a comment... :)
struk|desk has quit [Quit: Konversation terminated!]
<jtmcf>
Ah duh!
<jtmcf>
Haha, thanks :P
<jtmcf>
I wont forget my spaces
<pierpa>
it's a common gotcha
<jtmcf>
so in the code that defines it it would be written as let ( * ) = ...
<jtmcf>
(with the two args, oops)
<pierpa>
yes
<jtmcf>
cool, thanks a lot
<mspo>
wolfcore: maybe one day I'll have time to get enlightened
<mspo>
wolfcore: erlang is also highly integrated into emacs
<wolfcore>
mspo: yeah it is
badon has joined #ocaml
<jtmcf>
mspo: it's an interesting and overall positive switch, i used vim for 10 years, pre college, through college and up until about a year ago
<jtmcf>
emacs has its issues but what doesnt.
<mspo>
I actually use normal vi mostly (nvi)
<lewis1711>
I spent two days hammering emacs into an editor I wanted to use once. then I tried a language mode and my keybindings didn't mesh
<mspo>
heh
<mspo>
maybe spacemacs is the way to go
seangrove has joined #ocaml
NingaLeaf has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
govg has quit [Ping timeout: 250 seconds]
FreeBirdLjj has joined #ocaml
virtualeyes has quit [Ping timeout: 250 seconds]
foolishmonkey has quit [Quit: Leaving]
<jtmcf>
mspo: i actually liked building up my own config with evil-mode better, learned more about emacs along the way and i found spacemacs has some weird issues
<jtmcf>
i still use evil
<mspo>
yeah I'll give it another shot if I get some time
<mspo>
falling back on old habits is sometimes too easy, though :)
kolko has quit [Ping timeout: 250 seconds]
<jtmcf>
hah yeah, the only reason i stuck to it was my coworkers gave me shit every time they saw me with vim back.. i'm definitely glad i stayed though heh
ygrek_ has quit [Ping timeout: 260 seconds]
teknozulu has joined #ocaml
damason has quit [Ping timeout: 260 seconds]
copy` has quit [Quit: Connection closed for inactivity]
damason has joined #ocaml
pierpa has quit [Ping timeout: 240 seconds]
Algebr`` has quit [Ping timeout: 250 seconds]
yegods has quit [Remote host closed the connection]
yegods has joined #ocaml
yegods has quit [Remote host closed the connection]
yegods has joined #ocaml
seangrove has quit [Ping timeout: 245 seconds]
seliopou has quit [Ping timeout: 240 seconds]
johnelse has quit [Ping timeout: 250 seconds]
johnelse has joined #ocaml
johnelse is now known as Guest91207
Guest91207 has quit [Ping timeout: 272 seconds]
johnelse_ has joined #ocaml
seliopou has joined #ocaml
ygrek_ has joined #ocaml
mac10688 has quit [Ping timeout: 248 seconds]
damason has quit [Read error: No route to host]
damason has joined #ocaml
esad has joined #ocaml
esad has quit [Ping timeout: 260 seconds]
antkong_ has quit [Ping timeout: 240 seconds]
antkong_ has joined #ocaml
lewis1711 has quit [Ping timeout: 250 seconds]
Algebr has quit [Ping timeout: 252 seconds]
JacobEdelman has quit [Quit: Connection closed for inactivity]
<edwin>
ok, is opam-doc better? I tried it a while ago but some opam packages require >4.01
<edwin>
I'm just looking for an alternative of manually reading .mli files of packages
<rks`_>
opam-doc is dead.
<rks`_>
edwin: you should complain to package authors, so *they* set a doc for their package somewhere
<edwin>
yeah most packages that I use have that (lwt, ocsigen, stuff from dbuenzli, ...) but not everything
zpe has quit [Remote host closed the connection]
lokien_ has quit [Quit: Connection closed for inactivity]
jeffmo has joined #ocaml
MercurialAlchemi has quit [Ping timeout: 245 seconds]
MercurialAlchemi has joined #ocaml
srcerer has quit [Ping timeout: 276 seconds]
sgnb has quit [Ping timeout: 276 seconds]
srcerer has joined #ocaml
Haudegen has quit [Ping timeout: 240 seconds]
kansi has quit [Read error: Connection reset by peer]
slash^ has joined #ocaml
superboum_ has quit [Ping timeout: 256 seconds]
<apache2_>
can someone explain the documentation for output_binary_int in Pervasives? how can there be doubt about how to parse a 4byte bigendian int?
<orbitz>
dsheets: Is there a standard way to deal with this issue of ctypes + closures? Wondering how to design my API in the sanest way possible, it will be closure-callback heavy.
<apache2_>
(looking for a function to serialize network-order (big-endian) 16bit and 32bit ints)
<dsheets>
orbitz: I think creating the closure to pass into C and then retaining that in an abstract type is the cleanest method. Hopefully you can figure out a way to convince the user to keep a reference to the variable which encapsulates your closure.
<orbitz>
apache2_: Are you asking about the bit in the defintion about how the only reliable way to read it in is the input_binary_int function?
<apache2_>
yes
<dsheets>
This frees the user from retaining the closures themselves, instead giving them the model of "this object is my API accessor"
<apache2_>
and "the format is compatible across all machines for a given version of OCaml"
<orbitz>
apache2_: My guess, having no knowledge otherwise, is that there are no gurantess it's a naked int? Possibly some header info could be put in there at some point.
<apache2_>
ok, nothing too important, just made me wonder
Haudegen has joined #ocaml
<orbitz>
dsheets: Hrm, I'm doing an I/O event loop basically where all of the eventy stuff is C code (playing with something for fun), Right now the API is like: val do_thing : event_loop -> callback -> unit
<dsheets>
orbitz: yeah, I have some in-progress bindings to OS X CoreFoundation's event loop. I think the right thing to do here is return an object representing "thing" to the user and mutate the event_loop to keep a reference to it. If they lose the reference and the callback reference, that's fine because you kept it.
yegods has quit [Remote host closed the connection]
<orbitz>
dsheets: And then the callback removes itself from the loop?
<orbitz>
dsheets: What's the least over-head way to do that?
<dsheets>
it depends on if you want it recurring or one-shot, I suppose
<apache2_>
different question: Unix.ADDR_INET, is the only way to extract the IP seriously to do string parsing of the result of string_of_inet_addr ?
<orbitz>
dsheets: In my case all callbacks are one-shot
<dsheets>
apache2_: specifically, there is an Ipaddr_unix module with conversions. I don't recall at the moment but it is probably horrible inside.
<orbitz>
dsheets: In my case I'm trying to be as overhead free as possible. One thing I'm considering is keeping this API liek it is, and providing a 'safe' API on top that returns soemthing like Deferreds.
<orbitz>
and the Deferred would retain a reference
<orbitz>
But I guess if toss out the Deferred I'm kind of screwed...
<dsheets>
orbitz: hmm... sure. It's a trade-off between safety and performance at all costs
<orbitz>
I'd like to be able to handle hundreds of thousands of these callbacks existing at once, which makes me alitlte cautious about storing it in the event loop somewhere.
lokien_ has joined #ocaml
<orbitz>
dsheets: is this a ctypes-specific issue? As in, could I hand construct bindings that don't have this property?
ontologiae has quit [Ping timeout: 250 seconds]
<dsheets>
orbitz: you also have to consider that the event loop may be busy
<dsheets>
orbitz: this is C memory management leaking into OCaml :-) Closures are not simple and require GC
<orbitz>
Ok, I saw some discussion about liek adding roots in the C code, but maybe I'm missunderstanding
<dsheets>
orbitz: if you know something about the event loop behavior, that would be good. if it runs your callbacks FIFO or LIFO then you can be pretty fast
jwatzman|work has quit [Quit: jwatzman|work]
<orbitz>
Hrm no they will be in any order that the event happens, unfortuntely.
<apache2_>
dsheets: hmm thanks
<dsheets>
orbitz: do you ever collect them? you need to decide when to clean up. you may be able to bind to the OCaml run-time itself... i haven't looked into that
<orbitz>
dsheets: ideally, I knwo I can collect them after they fire, and I could just add that code to the closure. Manually memory management, yay :)
<dsheets>
orbitz: i think you are right and this can be done more efficiently because you know that they only fire once
Guest38 has quit [Read error: Connection reset by peer]
<orbitz>
dsheets: Is there any way for me to tell the runtime "trust me, don't collect this yet, I'll tell you when" without storing them in some kind of container?
<dsheets>
orbitz: i would be interested in what you find here. I've been considering mostly the recurring case.
<orbitz>
I might have to send an email out to list for some tips, this is outside my knowledge sphere!
<dsheets>
orbitz: I think the recent thread where diml suggested registering global roots is the right approach
<orbitz>
dsheets: That was in the C code, though, right?
<dsheets>
orbitz: yes, we would need to add support to ctypes or do some hacking to support that
<orbitz>
dsheets: that coudl be nice.
<orbitz>
How hard woudl that be?
<dsheets>
orbitz: I suggest filing an issue on the ctypes issue tracker and yallop will follow up with more detail. I don't know all the intricacy of interfacing with the GC...
<orbitz>
dsheets: great thanks. I have to go cook dinner, thank you for the info.
Guest38 has joined #ocaml
seangrove has joined #ocaml
<flux>
cool how things have moved from camlp4 to ppx quite fast
<flux>
pgocaml might be the only thing I still miss :/
<seangrove>
flux: Interesting, had never seen that before. Seems a bit like type-providers in f#, the way they use describe to get types from the db.
<seangrove>
Is that same thing possible with ppx?
superboum_ has joined #ocaml
ggole has quit [Ping timeout: 250 seconds]
<seangrove>
I'm not sure on what ppx is able to do, only that it's fundamentally more limited than camlp4 (which is better for lots of tooling)
larhat has joined #ocaml
sgnb has joined #ocaml
sgnb is now known as Guest88126
_andre has quit [Quit: leaving]
<flux>
I think it would be straight-forward to do in ppx, the type information in PGOCaml is flowing from the database to the program
<flux>
I'm guessing the code generation part would change. But I know zero ppx :)
aantron has quit [Remote host closed the connection]
<seangrove>
Curious to hear from someone who might know.
<seangrove>
flux: In the case of the current PGOCaml, does it allow for interop with e.g. merlin, or only compile time warnings/errors?
<flux>
I'm not sure if it interops with merlin, but if it does, it would be because the support would be hardcoded into merlin
<flux>
I'm guessing it doesn't.
aantron has joined #ocaml
<nicoo>
AFAIK, there is no support for PGOCaml's syntax extension in Merlin
<seangrove>
Bummer - makes sense though. Not on quite the same level as type providers, perhaps
<flux>
do type providers also work from feeding compiler more information about types, or does it work the other way around as well?
<flux>
ie. if I do foo 42, can F# instruct the type provider to create a foo that accepts 42?
<seangrove>
flux: Not sure, only saw a demo someone showed me, but they were able to use it for autocompletion, type checking in the editor, etc.
<flux>
if not, then I think it would be possible to implement that in ppx (without doing type inference withni ppx)
larhat has quit [Quit: Leaving.]
<seangrove>
Hrm, so I think there's no syntax-quote in OCaml, since OCaml code isn't homoiconic
dsheets has quit [Remote host closed the connection]
<seangrove>
What's the limitation with ppx wrt merlin, syntax highlighting, etc.?
<seangrove>
I'd like to be able to write something like `[:find ?e ?x :where [?e :age 42] [?e :likes ?x]] (* which 42-year-olds like what? *)` inline in my code
<seangrove>
I could make it more OCaml-y: `[:find; ?e; ?x; :where; [?e; :age; 42]; [?e; :likes; ?x]] (* which 42-year-olds like what? *)`
<seangrove>
But the first representation is ideal. Is this something I can pull off with ppx?
<flux>
yes, but the syntax for quoting anything is slightly heavy: {delim|I'm quoting, I'm quoting|delim}
<flux>
you would of course need to parse everything being quoted yourself
<seangrove>
flux: That seems reasonable - it all happens at compile time, so there's no run time penalty, right/
<flux>
yes, and you can just copy paste that to your ocaml toplevel and you get out the string
<flux>
so you could use that to put fragments from other languages as runtime strings (ie. sql)
<seangrove>
That's great, I want to use Clojure's datalog syntax - and how does that then work with merlin/syntax highlighting? I assume it just doesn't
<flux>
well, I think it's possible to provide location information from the ppx extension
<flux>
but I think the syntax coloring is more primitive in emacs
<flux>
I probably don't have the latest merlin, but what does it do constantly?
<flux>
I think for me it checks stuff only on save
govg_ has quit [Ping timeout: 264 seconds]
<_berke__>
well I save constantly... it's a habit
<flux>
:)
<_berke__>
I would like it to check only on C-c C-r or something
<flux>
maybe it's hackable. did you look at merlin.el?
<flux>
but for me it's reboot time, no guarantees I'll get back :)
<_berke__>
nah... later maybe. I'm too busy for that right now :( disabling merlin for now
<flux>
ah ten more minutes still, I need to rebuild my boot raid first :) (that loose cable..)
<flux>
so I guess I'll have time to check edwin's links then
<flux>
to me it seems that should be possible "if" only someone writes the code..
<flux>
the syntax could go like this: module M = {%psql dbname=foo} and what it would do, would be it would connect the database 'foo' and download all type-related data from it
<flux>
and then it would expand to module M = struct type client = .. type product = .. let clients = .. let products = .. end
<flux>
and as far as I see, it should then just work out of the box. I think even merlin's symbol expansion should then work.
<flux>
the difficult trick is then having a nice syntax that constructs ocaml expressions using those types
<flux>
so if pgocaml used to be able to just send the string in, with this kind of approach it would need to parse and reconstruct the query and express it as an ocaml expression that would result in the desired types..
<flux>
that I think would be the difficult part and I think something like that has been tried before, but never actually finished properly.. not the sql parsing part, but just the "express this query as an ocaml expression" part
kakadu_ has joined #ocaml
BitPuffin has quit [Ping timeout: 272 seconds]
<Drup>
flux: macaque
<flux>
right
<Drup>
it's a bad idea
<Drup>
just use the sql syntax, please
<flux>
:)
<flux>
but it has its downsides as well. in particular, inability to compose, except in stringful fashion.
<Drup>
No, there is not reason not to be able to compose
<flux>
though I wish pgocaml actually had macros, that would probably be sufficient most of the time
<Drup>
you just need splicing
<Drup>
I never said to use strings, I said the sql syntax
<flux>
but reboot time for me, raid sync went alright
<Drup>
it's very different
lokien_ has quit [Quit: Connection closed for inactivity]
<flux>
ooh, reboot went better than expected
<flux>
and probably the cable reseating as well, at least raid builds at 5-10x speed :)
seangrove has joined #ocaml
<flux>
drup, what do you mean by splicing?
<Drup>
[%sql {|select foo = 3 from %thing |}]
<flux>
and %thing can be what?
<Drup>
a table or another query
<flux>
and is there compile time checking?
JacobEdelman has quit [Quit: Connection closed for inactivity]
<flux>
or, in particular, does it give back typed rows?
<Drup>
It should, at least, it's complicated
<Drup>
look at macaque
<Drup>
macaque does the typing
<flux>
well I'm certainly in favor of just writing plain sql
<Drup>
I'm going to eat now, we'll finish the discussion later :)