datkin has quit [Remote host closed the connection]
larhat has quit [Quit: Leaving.]
datkin has joined #ocaml
ulfdoz_ has joined #ocaml
ulfdoz has quit [Read error: Operation timed out]
ulfdoz_ is now known as ulfdoz
letrec has quit [Ping timeout: 245 seconds]
Tobu has quit [Ping timeout: 260 seconds]
Tobu has joined #ocaml
Tobu has quit [Ping timeout: 272 seconds]
Tobu has joined #ocaml
jathd has quit [Remote host closed the connection]
thelema_ has joined #ocaml
thelema has quit [Read error: Connection reset by peer]
lamawithonel has quit []
lihaitao has joined #ocaml
lewis1711 has joined #ocaml
<lewis1711>
how do you guys call C libs from ocaml, generally? SWIG, ocaml FFI generator, by hand?
<_habnabit>
by hand
oriba has quit [Remote host closed the connection]
smerz has quit [Remote host closed the connection]
andreypopp has joined #ocaml
<thelema_>
flux: open Batteries Enum.combine((1.0,10.0) --. y_dim, (1.0,10.0) --. x_dim) |> iter (fun (x,y) -> ...) ... err, you want to iterate through all combinations... BatList has cartesian_product... I thought we had another cartesian product, but I can't find it now.
thelema_ has quit [Remote host closed the connection]
thelema has joined #ocaml
ViciousPlant has quit [Ping timeout: 272 seconds]
alvis has quit [Ping timeout: 272 seconds]
sivoais has quit [Quit: Lost terminal]
ankit9 has joined #ocaml
sivoais has joined #ocaml
ankit9 has quit [Read error: Connection reset by peer]
Xizor has joined #ocaml
Fabio has joined #ocaml
lewis1711 has left #ocaml []
pango is now known as pangoafk
ftrvxmtrx has quit [Quit: Leaving]
<flux>
thelema, btw, I'm not 100% confident (1,0, 10.0) --. x_dim is the best notation for float ranges. how about frange 1.0 10.0 x_dim?-)
<flux>
but your suggestion was nice, although it relies on the combine-function for 2-tuples, so it doesn't really generalize for third dimension..
<flux>
actually, I suppose yuo can run multiple combines one inside another, but it becomes quite syntax heavy
Cyanure has joined #ocaml
andreypopp has quit [Quit: Quit]
thomasga has joined #ocaml
thomasga has quit [Ping timeout: 250 seconds]
ankit9 has joined #ocaml
ftrvxmtrx has joined #ocaml
emmanuelux has quit [Remote host closed the connection]
mika1 has joined #ocaml
cago has joined #ocaml
Fabio has quit [Quit: Leaving]
ankit9 has quit [Ping timeout: 260 seconds]
ankit9 has joined #ocaml
cdidd has quit [Remote host closed the connection]
djcoin has joined #ocaml
<Drakken>
Is there a way to use camlp4 quotations outside of EXTEND forms?
avsm has quit [Quit: Leaving.]
<f[x]>
yes
<Drakken>
What do you do with the _loc variable?
<f[x]>
simplest - use sentinel value
<f[x]>
e.g. let _log = Loc.ghost
<Drakken>
It seems like quotations are intended to be wrapped in functions that are produced by EXTEND.
<f[x]>
Loc is from Camlp4.PreCast
<f[x]>
no, but they do expect some environment
<f[x]>
i.e. modules opened providing Ast constructors generated by given quotation
<f[x]>
third-party quotations can have any other requirements
<Drakken>
Do quotations work properly with Loc.ghost?
<f[x]>
think of quotations as macros
<f[x]>
they splice code
<f[x]>
why not? you will get less precise error locations but theat's the price for not bothering
avsm has joined #ocaml
Anarchos has joined #ocaml
Anarchos has quit [Ping timeout: 245 seconds]
eni has joined #ocaml
avsm has quit [Quit: Leaving.]
alvis has joined #ocaml
Kakadu has joined #ocaml
tufisi has joined #ocaml
avsm has joined #ocaml
gildor has quit [Quit: leaving]
gildor has joined #ocaml
avsm has quit [Quit: Leaving.]
avsm has joined #ocaml
<adrien>
I'm starting to think of lazyness in GUIs as a very dirty hack
<adrien>
the typical case of not using "ref (Obj.magic 0)" for state that will be initialized, but I'm not sure lazyness actually helps
<mrvn>
what happens if 2 lazy values need the other to compute?
<adrien>
if they rely on effects, I'd expect the result to be the same as (or at least, not better than) "let rec f = ... and g = ...", which is not defined iirc
<mrvn>
but evaluating the first evaluates the second evaluates the first evaluates the second ...
<adrien>
and the thing with lazyness instead of "ref (Obj.magic 0)" can be nice but is only fine when there will be only the initialization and no change of the data afterwards
<adrien>
hah
<mrvn>
adrien: it avoids the extra indirection of a useless ref
<adrien>
Note: if the program is compiled with the -rectypes option, ill-founded
<adrien>
recursive definitions of the form let rec x = lazy x or let rec x =
<adrien>
lazy(lazy(...(lazy x))) are accepted by the type-checker and lead, when
<adrien>
forced, to ill-formed values that trigger infinite loops in the garbage
<adrien>
collector and other parts of the run-time system.
<mrvn>
adrien: :)
<adrien>
mrvn: in a GUI, when relying on something like GTK+, one indirection is not going to be the performance issue ;-)
<mrvn>
adrien: still, its better to have immutables immutable.
<mrvn>
and having to type !foo all the time sucks
<adrien>
I'm moving yypkg's GUI to FRP-style
<adrien>
currently, I have that in the code (in several places):
<adrien>
let pkglist = !(Lazy.force pkglist) in
_andre has joined #ocaml
<mrvn>
adrien: can't you compute all the values before creating the actual object?
<adrien>
making yypkg's GUI in an FRP-style would probably be a pretty good introduction/example for FRP because it's pretty simple and the backend is functional
<adrien>
mrvn: pkglist is fetched over http
<adrien>
plus it can change
<mrvn>
class foo bar buzz = let pkglist = fetch_list bar in object(self) ... end
<adrien>
I'll have to update the listview of packages sometimes
<mrvn>
if it can change then initialize it with some dummy value. For lists [] usualy works.
<adrien>
so I can either update an existing one or create a new one
<adrien>
if I create a new one (which is most probably what I'm going to do), then I can do it that way
<adrien>
if I update, well, it's going to be buggy =)
<mrvn>
adrien: pass the old (dummy) list as argument
<adrien>
well, I have a package list and display it; it's possible that during the execution of the program, the package list will change (add or remove some items)
<adrien>
if I update instead of destroying+creating, I'd have to handle inserting new elements
<adrien>
and that would be O(n^2) and it'll probably end up worse than destroying+creating
<mrvn>
destroying+creating sucks because then the GUI will flicker.
<adrien>
it might
<adrien>
I'll check how it behave before doing anything :-)
<mrvn>
and I assume the list is sorted in some way. Then updating is O(n)
<adrien>
it's sorted but it's in GTK+-land
<adrien>
plus, with the default model of the listviews
<adrien>
that model asserts that the underlying data structure is a list, with only a "next" operation; it's not possible to give it a "previous" operation
<mrvn>
so your authorative data is in GTK land? Then why not just create the list every time it is needed?
<adrien>
so when it needs to do "previous" (and it definitely needs to), it relies on an rb-tree
hefner has joined #ocaml
<adrien>
I wanted to use a zipper, with O(1) previous, and a low factor
<adrien>
I think I can keep the graphical widget of the listview and swap the models; that should be flicker-free (well, I hope)
<mrvn>
makes sense
<adrien>
but for models, it's possible to provide what you want, and lablgtk2 lets you do it!
<adrien>
except that it's crashy I think and I have no idea what's wrong
<adrien>
(and I'm not sure it's my fault that it's crashing; the whole stuff works with a lot of callbacks from C to OCaml, and with allocation-heavy data structures)
<mrvn>
That's why I want an ocaml GUI and not just some glue to C or C++ code.
<adrien>
I'm not sure OCaml is really good at drawing
<adrien>
currently I'm interested in the EFLs; and some people there are interested in ocaml; there could be some fun things to do with typing
<adrien>
and I want the runtime type-info!
<adrien>
I _need_ that
larhat has joined #ocaml
<mrvn>
runtime type-info as in objects with inheritance and virtual functions?
<adrien>
(yypkg's GUI is a program that deserializes data from json and displays it in a GUI; both serialization and GUI would be better with rtti; the combination of the two would be much better)
<adrien>
mrvn: no, the work from Alain Frisch that has been presented a few months ago
<mrvn>
or GADTs?
<adrien>
which relies on GADTs
<adrien>
it's optional stuff: you add a special parameter to a function and ocaml will add type info if you don't do it when calling the function (optional argument)
<NougatRillettes>
it was a simple parenthesis error.
<thelema>
maybe use npeek and list matching?
<thelema>
oh, ok
<thelema>
need more () around the argument to lexer?
<Ptival>
because application binds tighter than (::) ?
<thelema>
f x::y is (f x)::y, not f (x::y)
<Ptival>
e = lexer ((Var v)::dic) (* should be okay *)
<Ptival>
no need to parethesize lexer
<NougatRillettes>
ok, thanks.
<pippijn>
what about lexer (Var v :: dic)
<Ptival>
you could also remove the parentheses around (Var v) but it's easier to read that way :)
<pippijn>
ok
<Ptival>
but it depends on people
<Ptival>
pippijn: with the additional spaces it's better indeed
<Ptival>
idk what people prefer
NaCl has quit [Ping timeout: 260 seconds]
<NougatRillettes>
hm, the pattern [< e1 = lexer dic; e2 = lexer dic >] gives me a looping recursion. I guess it's because it's too greedy any idea how to help that ?
<flux>
by using an actual parser generator
<flux>
stream parsing is veeery simple
<flux>
the upside is that ocamllex & ocamlyacc are quite easy tools to use, and definitely worth the trouble
<Ptival>
(menhir)
<flux>
and when ocamlyacc's limitations/annoyances hit you, there's always menhir that's 100% (?) backwards compatible
<flux>
I think there was some 'competing' lexer generator there as well, was there?
<flux>
I just used ocamllex the other day after pondering for a while how to mutilate Pcre to parse a g-code file for me
<flux>
(didn't use yacc, though)
<NougatRillettes>
well the goal here is too implement lamda-calculus, so if I use ocamllex and ocamlyacc, it would be quite uninteresting, wouldn't it ?
<flux>
would it? is there anything other than a parser to implement for it?
<thelema>
not really
<flux>
if your task is to create a lexer, a parser and lambda-calculus, then I would agree :)
<NougatRillettes>
well i've got no «task», i'm just trying to learn and learning «how to compile» seemed interessant, so i began with lambda-calculus.
<NougatRillettes>
but, maybe it's just a bad idea to begin there.
<flux>
nougatrillettes, well, have you used lex and yacc earlier?
<NougatRillettes>
nop
<flux>
it is definitely worth your while to learn them
<thelema>
if you're learning how to compile, you shoudl definitely use lex and yacc for parsing your input into a parse tree
<NougatRillettes>
ok, thank you guys. Streams are not used nowadays with yacc and lex ?
<flux>
I don't think they were ever really used..
<flux>
although I must admit I played with them at a time
<thelema>
streams look nice, but don't get you very far
<flux>
spot on
<thelema>
that said, I am using a stream based (well, really just an exploded list) parser for regular expressions
<NougatRillettes>
Hm, ok.
<thelema>
the tokenizer and parser are both stream based
cago has quit [Quit: Leaving.]
<thelema>
but it's just a way of writing a recursive descent parser.
<thelema>
but better is to use a parser generator.
<thelema>
if you're just doing lambda-calculus, you may be able to get away with recursive descent if you keep the syntax simple.
mika1 has quit [Quit: Leaving.]
<NougatRillettes>
what do you call «recursive descent» ?
<Ptival>
NougatRillettes: you don't consume input and recur immediately?
<NougatRillettes>
And i'm trying not to use yacc and lex of course.
<NougatRillettes>
Well Ptival I guess that with the actual code, e1 = lexer... gets the whole stream and here is the loop.
<NougatRillettes>
But i don't know how to prevent it.
<NougatRillettes>
as application are wriiten "TermeTerme"
emmanuelux has joined #ocaml
ulfdoz has joined #ocaml
alxbl has quit [Changing host]
alxbl has joined #ocaml
<NougatRillettes>
Wow, another question what does type xxx/nnn mean ?
<NougatRillettes>
with nnn a number ?
<NougatRillettes>
I got a type error : This expression has type terme/1197
<NougatRillettes>
but an expression was expected of type terme/1298
Tobu has quit [Ping timeout: 272 seconds]
Tobu has joined #ocaml
Guest26920 has joined #ocaml
Guest26920 has left #ocaml []
Hussaind has joined #ocaml
ulfdoz_ has joined #ocaml
ulfdoz has quit [Ping timeout: 248 seconds]
ulfdoz_ is now known as ulfdoz
ulfdoz has quit [Ping timeout: 250 seconds]
ulfdoz has joined #ocaml
ftrvxmtrx_ has joined #ocaml
hto has quit [Read error: Connection reset by peer]
thelema has quit [Remote host closed the connection]
thelema_ has joined #ocaml
<thelema_>
NougatRillettes: you're not prevented from declaring a type multiple times with different definitions
ulfdoz has quit [Client Quit]
<thelema_>
NougatRillettes: the numbers are indications of when the type was declared
<NougatRillettes>
in fact i got it, it was because i loaded multiple times in toplevel
<thelema_>
yes, that's usually the cause.
<thelema_>
as for your infinite recursion, you need to consume some input on each case.
<thelema_>
what you're writing is similar to: let rec f x = f x + f x
ulfdoz has joined #ocaml
letrec has quit [Ping timeout: 248 seconds]
<vext01>
what was the name of the magical module that lets you print things from the toplevel?
<vext01>
ie. StringMaps
<thelema_>
vext01: umm, Std.dump from extlib?
<thelema_>
or #install_printer?
<thelema_>
dump works in compiled code
<thelema_>
#install_printer requires you to write the function to do the printing, and it just hooks it into the toplevel so that the toplevel knows to use it
<NougatRillettes>
Did anyone here code some compiler as could give me the code ?
<NougatRillettes>
With streams of course and not ocamlyacc or lex.
<_habnabit>
16:29:52 < NougatRillettes> Did anyone here code some compiler as could give me the code ?
<thelema_>
the compiler I wrote used ocamlyacc/lex
<_habnabit>
er, whoops
<NougatRillettes>
:/
<NougatRillettes>
I don't understand a piece of what i found about recursive descent parsing.
jamii has quit [Ping timeout: 276 seconds]
<vext01>
wait, you cant have two records with the same field name?
<_habnabit>
vext01, field names are per-module, not per-record
<hcarty>
vext01: Not in the same module or you run into trouble
<vext01>
heh, the plot thickens
<vext01>
thanks
larhat has quit [Quit: Leaving.]
NihilistDandy has joined #ocaml
NihilistDandy has quit [Client Quit]
NihilistDandy has joined #ocaml
<mrvn>
vext01: To be specific you can have the same label but as soon as you declare the second the first one gets shadowed. Makes accessing the first one impossible unless you already have some functions to access it.
Tobu has quit [Remote host closed the connection]
Tobu has joined #ocaml
Tobu has quit [Remote host closed the connection]
pangoafk is now known as pango
Zedrikov has joined #ocaml
Tobu has joined #ocaml
skchrko has joined #ocaml
lihaitao has joined #ocaml
NihilistDandy has quit [Ping timeout: 246 seconds]
yroeht has quit [Ping timeout: 260 seconds]
Hussaind has quit [Remote host closed the connection]
yroeht has joined #ocaml
iago has joined #ocaml
NihilistDandy has joined #ocaml
j2d2j2d2 has joined #ocaml
<NihilistDandy>
Anyone able to help me out with this homework? I have most of it done, but there are some points where I'm stuck. Code: http://hpaste.org/67167
<NihilistDandy>
And yes, the style is absurdly contrived
<_habnabit>
and you're stuck with ...?
<NihilistDandy>
In particular, the correct implementation of closedp WRT Fix, firstly
<NihilistDandy>
And then a few of the cases in subst and eval
<NihilistDandy>
I don't quite grok substitution, yet :D
<mrvn>
What is a Fix?
<NihilistDandy>
Essentially ocaml's `fix`
<NihilistDandy>
The D language we're implementing uses Ocaml as an oracle
<mrvn>
# fix;;
<mrvn>
Error: Unbound value fix
<j2d2j2d2>
NihilistDandy: "D language" confused me. there already is a d language
<NihilistDandy>
j2d2j2d2: Haha, yeah, me, too
<NihilistDandy>
mrvn: My understanding is that it's meant to be the fixed point combinator
<NihilistDandy>
Or operator, perhaps more appropriately
* Ptival
is sad when people don't put a pipe before the first pattern
<Ptival>
NihilistDandy: Fix is there to encode recursive things
<NihilistDandy>
Right
<mrvn>
Ptival: how is that supposed to look like? Fix ("x", "y", Plus (Var "x", Var "y")) ?
<Ptival>
I guess you can just think of it as a let rec
<mrvn>
Fix ("factorial_0", "factorial_n", Equal (Var "n", Int 0)))?
<Ptival>
oh wait no
<Ptival>
it has two idents
<j2d2j2d2>
so i have heard that ocaml is not turing complete because it wishes to halt. could someone help me undersatnd that better?
<mrvn>
Ptival: yeah. What are the idents and expression supposed to be?
<mrvn>
j2d2j2d2: you can implement a turing machine in ocaml so clearly it is turing complete.
<Ptival>
mrvn: I don't know, we need context from NihilistDandy :)
<mrvn>
NihilistDandy: anyway, in Fix if e is already closed over ident_list then adding x or y will never change that.
<mrvn>
NihilistDandy: why do you think your implementation is wrong?
<NihilistDandy>
mrvn: The professor said that I should watch out for problematic cases in the x closedness check, but I wasn't really sure what he meant.
<NihilistDandy>
Iidents, to my understanding, are just stand-ins for variables in whatever arbitrary expressions we encode in the abstract syntax. Expressions are a series of terms in that syntax, each term being described in the AST
<Ptival>
NihilistDandy: can you explain what is Fix(x, y, e)?
<NihilistDandy>
*Idents
<mrvn>
NihilistDandy: standin for values
<j2d2j2d2>
mrvn: It appears the type system itself is not turing complete.
<mrvn>
j2d2j2d2: why should it be?
<thelema_>
j2d2j2d2: it's good that the type system is not turing complete, otherwise it may not complete.
<j2d2j2d2>
mrvn: I don't know. That's why I'm here.
<Ptival>
j2d2j2d2: hopefully, you want the type-checker to terminate even if the program doesn't :)
<j2d2j2d2>
What would be an example of a type that might not terminate?
<mrvn>
Having code that is correct but never finishes to compile would be bad.
Zedrikov is now known as camembert8
<mrvn>
j2d2j2d2: there isn
<mrvn>
't one since in ocaml they always terminate
<j2d2j2d2>
mrvn: Oh. So there isn't actually anything neat about that idea then huh. Seems like it's just how types probably should work.
<NihilistDandy>
j2d2j2d2: In Haskell you could get an infinitely recursive datatype, but the typechecker generally prevents it
<mrvn>
j2d2j2d2: there are languages out there with higher level type systems.
<j2d2j2d2>
interesting
<thelema_>
j2d2j2d2: there's some people who've wrote languages with turing complete type systems, but the programs one can express in them are no more powerful than what you can express in ocaml (or any other language)
<mrvn>
NihilistDandy: ask your prof for some examples of Fix that are closed and not closed.
<j2d2j2d2>
is the lack of turing completeness on type checking what makes ocaml useful for proving math formulas?
<mrvn>
NihilistDandy: And your forgot the Function case.
<j2d2j2d2>
it was described to me as a choice specifically to make math more easy, but the person couldn't go past that statement
<NihilistDandy>
mrvn: Oh, I know. I just haven't done that one, yet :D
<mrvn>
j2d2j2d2: not realy
<NihilistDandy>
I'll ask him and see if I can get more directed information
<Ptival>
NihilistDandy: if you don't know what the x and y represent in Fix(x, y, e), I don't see how you're going to understand what you're doing
<mrvn>
NihilistDandy: what is your problem with subst?
camembert8 is now known as Zedrikov
hexreel has quit [Quit: leaving]
<j2d2j2d2>
stoked for the oreilly ocaml book by minsky
Kakadu has joined #ocaml
<mrvn>
NihilistDandy: and in eval your Let is incomplete
<NihilistDandy>
Yes, indeed. Again, hadn't worked much on that part, yet
<NihilistDandy>
Sorry, going over notes to be more useful
* mrvn
likes the _ -> raise AssignmentIncomplete
<Ptival>
:)
<Ptival>
raise CanIHazGoodMark
<NihilistDandy>
So, I understand that Fix is used to encode recursion in our system, but I don't really follow its definition: (Fix z.x → e)
<NihilistDandy>
s.t. z ≠ x
<mrvn>
would be better with raise (Grade "A"), raise (Grade "B"), ...
<NihilistDandy>
er, "where" rather than "s.t."
<NougatRillettes>
Is there a way to filter a stream containing only one char ?
<NihilistDandy>
So, in the abstract syntax, we would have Fix(Ident("z"), Ident("x"), e)
<Ptival>
NihilistDandy: maybe it means μ z . λ x . e
<Ptival>
for let rec f x = e
<mrvn>
NihilistDandy: -Ident
<Ptival>
but it's weird to put one ident here :\
<NihilistDandy>
I thought that, but I wasn't sure.
<mrvn>
NihilistDandy: the question isn't the type, the question is what does it mean?
<Ptival>
yes, we know what your idents and expressions mean :)
<mrvn>
NihilistDandy: How does 'let rec f x = if x = 0 then 0 else f (x - 1)' translate into a Fix for example?
Snark has quit [Quit: Quitte]
<NougatRillettes>
NihilistDandy: your nick owns my respect.
<mrvn>
or let f x = f x
<NihilistDandy>
Fix(f, x, (If x = 0 Then 0 Else f (x-1))
<NihilistDandy>
)
<NihilistDandy>
Or something to that effect. I think.
<NihilistDandy>
Or rather (If(x=0, 0, f (x-1)))
<Ptival>
how would you translate let rec f a b = f b a ? :)
<mrvn>
NihilistDandy: so "f" and "x" are idents the fixpoint binds when evaluating e.
<Ptival>
oh I think I see why the x is included in the Fix...
<NihilistDandy>
Hmm
<mrvn>
Basically Function ("x", Let ("f", e, e))
<Ptival>
so closedp for Fix(f, x, e) should just be (closedp e (f :: x :: ident_list))
<mrvn>
+1
<mrvn>
But as I said get some examples.
<Ptival>
because you're going to construct (fix (λfλx→e)) really, where fix will be a fixpoint combinator
<NihilistDandy>
Right
<NihilistDandy>
I guess that makes sense. I need to think about it for a bit, though. I'll go over the notes where we talked about Fix. He seems to have been dodging around it a bit.
<NihilistDandy>
Thanks for the help. I'm sure I'll be back later. It's not due for quite a while :D
<NihilistDandy>
You've really been helpful :)
<Ptival>
np
NihilistDandy has quit []
hexreel has joined #ocaml
JoeyA has joined #ocaml
JoeyA has quit [Quit: Leaving]
larhat has joined #ocaml
err404 has joined #ocaml
JoeyA has joined #ocaml
<JoeyA>
How do I install the Core.Std module on Ubuntu?
<JoeyA>
When I run `ocaml` from the command line and type open Core.Std;; , it says: Error: Unbound module Core
<thelema_>
JoeyA: download tarball (or checkout repo), make && make install
<NougatRillettes>
while i precised to run application l. 22
<thelema_>
because application only runs once?
<NougatRillettes>
(no need to understand the whole code)
<NougatRillettes>
well thelema_ it should be called recursively, shouldn't it ?
<NougatRillettes>
l. 22, i precised to run it «again» but it doesn't seem to do anything.
<NougatRillettes>
ok, i found it
Kakadu has quit [Quit: Konversation terminated!]
oriba has joined #ocaml
<NougatRillettes>
Did anyone ver used js_of_ocaml ?
<NougatRillettes>
From the ocsigen project ?
smerz has joined #ocaml
Cyanure has quit [Remote host closed the connection]
dsheets has joined #ocaml
<vext01>
hrm
Zedrikov has quit [Quit: Bye all, see you next time!]
<oriba>
NougatRillettes, did you used it? I thought about it but never used it... maybe you have and can share some experiences?
<NougatRillettes>
well, not at all, i was trying to get online a little caml programm i did.
<NougatRillettes>
There is no simple way to do it in fact.
<NougatRillettes>
but maybe pou could help you, i think he knows ocsigen quite well.
<NougatRillettes>
(sorry for the highlight)
<oriba>
at the moement it's not a topic I'm working on, so I would not ask actively for it, maybe later, when it might become a topic for me again.
<oriba>
I just thought you maybe can tell something about it
<vext01>
ok more dumb questions for you guys
<vext01>
let prompt () = let line = "" in
<vext01>
while true do (
<vext01>
line = input_line stdin; ()
<vext01>
) done;;
<oriba>
Setup is too much trouble for just playing around with it, if it's not clear that it makes sense for me, or if I better do things as I did before.... but if everyone would say: use it, then next time I would give it a try
<vext01>
this expression should have type unit.
<vext01>
why so?
<oriba>
because it "gives back" unit
<vext01>
ah, i was not supposed to paste the ()
<vext01>
i removed that
iago has quit [Ping timeout: 265 seconds]
<vext01>
oriba: i dont follow
<oriba>
what exactly is your question? maybe I can't follow your question
<vext01>
the compiler tells me that the line with the "while" keyword should have type unit
<oriba>
you compare "line" with the result of read_line stdin
<oriba>
either line should be a ref and you need := then to set the value of it
<oriba>
or you need to rewrite something else of your code
<vext01>
oh, it's not supposed to be a comparison
<vext01>
assignment
<oriba>
vext01, maybe this qway:
<oriba>
let prompt () =
<oriba>
let line = ref "" in
<oriba>
while true do
<oriba>
(
<oriba>
line := input_line stdin
<oriba>
) done
<vext01>
so there are two assignment operators in ocaml?
<oriba>
no
<vext01>
let line =
<oriba>
let is not an assignment
<oriba>
it binds a value to a name
<oriba>
it's a functional concept
<vext01>
eesh
<vext01>
let me try
iago has joined #ocaml
<vext01>
hm
<vext01>
i think this ref thing is a symptom of my minsunderstanding
cdidd has quit [Ping timeout: 246 seconds]
<vext01>
im not sure i want a let
<oriba>
maybe you have not much experience in functional progranmming and the theory behind it, and that is the reason for misunderstanding
<vext01>
the "" is irrelevant, i just added it so as to define a local variable i can store the line in
<oriba>
why is it irrelevant?
<vext01>
oriba: yes, this is my first functional language
<oriba>
aha :)
<vext01>
oriba: i never want an empty string
<oriba>
Ocaml does not allow undefined values
<vext01>
i just want storage space to put the result of read_line
<vext01>
er
<oriba>
so if you use the ref than "" is a good point to start with
<vext01>
input_line
<oriba>
if you want to do it functional, then it could ebe done differently
<vext01>
enlighten me :)
<oriba>
what will happen with the value?
<vext01>
its going to be parsed eventually
<oriba>
hmhh
<oriba>
OCaml is not purely functional. It also allows non-functional ways of solving problems
<oriba>
Each concept has it's advantages and disadvantages
<vext01>
you may have noticed a nice non-functional while loop
<oriba>
yes
<vext01>
i dont know another way to indefinitely (or until eof) read stdin
<oriba>
is this by asccident or by will?
<vext01>
^
<vext01>
how would you have done it?
<oriba>
if you want to do it with that loop, then ref "" is a way to go
<oriba>
What I would have done depends on what I want to achieve
<oriba>
If you reach End-of-File, an exception is thrown
<oriba>
You need to cath this exception
<oriba>
catch
cdidd has joined #ocaml
<oriba>
vext01, and exceptions are caught with try ... with
<oriba>
vext01, maybe reading some texts about OCaml would help you to explore some base knowledge
<oriba>
vext01, why did you started using OCaml?
<vext01>
yep, i was going to allow the exception to propogate up
<vext01>
oriba: i started because i work in an area of computer scienc where it is widely used
<oriba>
aha
<vext01>
until now I have mostly written in C and python
<oriba>
what area?
<oriba>
aha
<vext01>
static analysis
<oriba>
Python also allows functional programming (lambda terms)
<vext01>
I just needed to bite the bullet and give it a shit
<vext01>
shot
<vext01>
heh
<vext01>
(typo)
<_habnabit>
you don't need lambdas for functional programming
<vext01>
ok, so suppose we want to just print the line we recieved and use a functional paradigm
<vext01>
how would you, oriba, approach this
<oriba>
Either you never get it (functional programming), or you might become addcited to it ;)
<vext01>
as it stands im confused, but i remember this stage when I was learning C also
<oriba>
_habnabit, AFAIK thats Pythons FP way... maybe it offers other FP-features also.
<vext01>
i can bang out C code like no-ones business by now
<oriba>
vext01, reading file with a loop is ok, and using ref "" as a starting point also
<vext01>
btw, just because I used python, does not mean i liked it ;)
<_habnabit>
python has plenty of FP features which don't use or necessitate lambdas
<oriba>
vext01, aha :)
<vext01>
i didnt like python's type system
<oriba>
it does not really have one ;-)
<vext01>
a friend of mine has long running experiments written in python, which often crash due to an error in printing the result :P
<_habnabit>
unit tests
<vext01>
hehe quite
<vext01>
ok, well next im googling about "ref"
<oriba>
vext01, regarding your input_line program: you may want to save all lines inside a list (line by line), or make one big string out of it.... depending on that, you need to write the code....
<vext01>
oriba: the thing about user input... is it is unbounded
<oriba>
_habnabit, a lot of unit tests are necessary because there is not a good type system
<oriba>
vext01, ??
lorilan has quit [Quit: Quitte]
<vext01>
i dont need to store previous user input
<vext01>
and to do so would be silly
<oriba>
vext01, read something about OCaml. There is already a lot of material available
<vext01>
yeh, i have the "Practical Ocaml" book, but really disliked it
<oriba>
if you just need one line to read, "let" is ok. Someting like read the line and check if it is "Y" or "N"
<vext01>
great
<oriba>
vext01, did you looked at the Oreilly Book?
<oriba>
Or jason Hickey's book on Ocaml?
<vext01>
i have used bits of the oreilly book it seems
<_habnabit>
oriba, conversely, type inference is not a replacement for unit tests
<_habnabit>
(often I've had the *exact same thing* happen in ocaml)
<vext01>
ok, so ref makes line mutable
<oriba>
The Oreilly book is good explaining the background, but iuf you are unpatient and want to do some I/O Jason Hickeys book is more pratcical and comes faster to results... without too much elaborating
<vext01>
ok thanks
<oriba>
_habnabit, it is not a replacement for any test, but a lot of tests can be thrown away - all those, where type problems would result in bugs.
<_habnabit>
okay, except people don't typically make their unit tests check types in python. it's sufficient to check behavior
<_habnabit>
so... you write the exact same tests, because you're checking behavior in ocaml too
<oriba>
type sysetem and compile time checks check a lot of issues... o tests necessary for THESE TYPES of problems. of course testing is necessary in general. But less testing
tmaedaZ has joined #ocaml
tmaedaZ is now known as tmaeda
tufisi has quit [Ping timeout: 265 seconds]
bitbckt has quit [Quit: out]
JoeyA has joined #ocaml
<JoeyA>
What is the syntax for applying two arguments to a data constructor? Say I have: type 'a bar = A of 'a * int ;;
<JoeyA>
A 2 4;; gives me a syntax error.
<_habnabit>
A (2, 4)
bitbckt has joined #ocaml
<JoeyA>
So data constructors can only have one argument, and this case the argument is a tuple?
<JoeyA>
and in*
djcoin has quit [Quit: WeeChat 0.3.2]
<_habnabit>
kind of. it's only superficially a tuple
<_habnabit>
you can't pass a tuple
<JoeyA>
If I wanted it to be a real tuple, what would the syntax be?
<JoeyA>
What flags should I get into the habit of passing to ocamlopt? I usually run ghc with -Wall -O2 and gcc with -Wall -W -O3 because I want full warnings, and full optimization (in case optimization breaks my code).
<vext01>
_habnabit: it would appear that i is unbound in the fixed version
<_habnabit>
'unbound' ?
<vext01>
so let binds value for the following block, right?
<_habnabit>
yes.
<vext01>
you refer to i outside the block
<_habnabit>
nope.
<_habnabit>
the block starts on line 2 and goes through line 8
tmaeda is now known as tmaedaZ
<vext01>
i also notice that an exception does not cause the function to return immediately
<_habnabit>
you're catching the exception
<_habnabit>
if the exception isn't caught, the function exits immediately. it doesn't return, though
<vext01>
ok i see
<vext01>
sorry, all the questions
<vext01>
what is the begin...end scoping here?
<_habnabit>
it's fine
<_habnabit>
begin and end are isomorphic to ( and )
<_habnabit>
I just like using them better for cases like that
<vext01>
we dont need them atall in this case, right?
<_habnabit>
you need them because otherwise the `with` in your try-with will contain the printf
<JoeyA>
Two questions about syntax: 1) Is OCaml indentation-sensitive? 2) In type definitions and cases, does it allow an optional leading | for better appearance alone?
<_habnabit>
so you need to wrap the try-with in parentheses
<_habnabit>
JoeyA, no, yes
<JoeyA>
Thanks
<_habnabit>
vext01, you could also use a let instead of parentheses there