dark_light changed the topic of #ocaml to: OCaml 3.09.2 available! Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
<dbueno_> Has anyone in here used Elkhound? Is the OCaml support good?
<dan2> what's elkhound?
<dbueno_> A GLR parser generator.
<dan2> give it a shot
<dan2> if anything targets only 3 languages, C,C++, and Ocaml, I suspect the ocaml is good
<dan2> it's probably written in Ocaml for that matter
<dbueno_> dan2, It's not.
<dan2> dbueno_: what's the risk in trying it out?
<dbueno_> In fact, the author is part of a group which has written much OCaml software, but he decided to write his in C++ because he likes it.
<dbueno_> dan2, the amount of time it takes to figure out how it works.
<dbueno_> All the examples I can find use lexers and semantic actions written in C.
<dbueno_> C++
<dan2> dbueno_: they all work pretty similarly. They all want a grammar in BNF format...
<dbueno_> dan2: Right, but, I can't find anything on how it integrates with OCaml, or how to build ASTs with ocaml
<dan2> that whole directory is a list of examples
<dan2> By default, Elkhound generates a parser in C++. By specifying "-ocaml" on the command line, the user can request that instead the parser generate OCaml code. Please see ocaml/, probably starting with the example driver ocaml/main.ml.
<dan2> The lexer interface for OCaml is given in ocaml/lexerint.ml. It is similar to the C++ interface except I have not yet (2005-06-13) implemented support for source location propagation, so there is no loc field. Also, since OCaml does not have function pointers, it uses an ordinary virtual dispatch to get the next token.
* dbueno_ looks....
shawn has quit [Connection timed out]
duncanm has quit [Read error: 110 (Connection timed out)]
chessguy has joined #ocaml
<dan2> dbueno_: how is it?
TSC has quit [Connection timed out]
bzzbzz has joined #ocaml
shawn has joined #ocaml
pango_ has joined #ocaml
shawn has quit [Connection timed out]
pango has quit [Remote closed the connection]
dark_ has joined #ocaml
dark_ has quit [Read error: 104 (Connection reset by peer)]
TSC has joined #ocaml
TSC has quit [Remote closed the connection]
TSC has joined #ocaml
chessguy has quit [" Try HydraIRC -> http://www.hydrairc.com <-"]
khaladan_ has joined #ocaml
dechunker has joined #ocaml
khaladan- has joined #ocaml
shawn has joined #ocaml
shawn has quit [Remote closed the connection]
Selva_ has quit [Read error: 113 (No route to host)]
khally has joined #ocaml
shawn has joined #ocaml
khaladan has quit [Success]
khaladan_ has quit [Connection timed out]
khaladan- has quit [Connection timed out]
khaladan has joined #ocaml
khally has quit [Connection timed out]
ZeeGeek has quit ["leaving"]
khaladan_ has joined #ocaml
khaladan- has joined #ocaml
khally has joined #ocaml
khaladan has quit [Connection timed out]
khally is now known as khaladan
duncanm has joined #ocaml
khaladan_ has quit [Connection timed out]
<flux__> dbueno_, if you're not determined to use elkhound, maybe menhir would be a nice parser generator to try - I like it
khaladan- has quit [Connection timed out]
<flux__> it's only an LR generator, though, not a GLR
<flux__> I'm not sure what's the difference though
<flux__> maybe they are the same :)
<flux__> oh ok, they're not
<flux__> GLR allows multiple state transitions per state and input token, while LR allows only one
<flux__> I can see why a program parsing c++ would like to have a GLR parser..
Smerdyakov has quit ["Leaving"]
david_koontz has joined #ocaml
dark_light has quit [Read error: 113 (No route to host)]
_velco has joined #ocaml
Ballin_05 has quit [Remote closed the connection]
dark_light has joined #ocaml
ZaZa91 has joined #ocaml
ZaZa91 has quit [Client Quit]
pango_ has quit [Remote closed the connection]
pango has joined #ocaml
rickdangerous has joined #ocaml
dark_light has quit ["Ex-Chat"]
love-pingoo has joined #ocaml
_fab has joined #ocaml
rickdangerous has quit [Read error: 110 (Connection timed out)]
jajs has joined #ocaml
Snark has joined #ocaml
m3ga has joined #ocaml
rickdangerous has joined #ocaml
velco has joined #ocaml
TheArthur has quit [Remote closed the connection]
lde has quit [Connection timed out]
ramki has quit [Read error: 104 (Connection reset by peer)]
_fab has quit [Remote closed the connection]
nodie has joined #ocaml
ramki has joined #ocaml
ramkrsna has quit [Read error: 110 (Connection timed out)]
<dbueno_> flux__: I want to try out a GLR parser because I don't care about the time it takes to parse.
<dbueno_> O(n^3) works for me.
nodie has left #ocaml []
mikeX has joined #ocaml
khaladan has quit [niven.freenode.net irc.freenode.net]
Demitar_ has quit [niven.freenode.net irc.freenode.net]
dbueno_ has quit [niven.freenode.net irc.freenode.net]
flux__ has quit [niven.freenode.net irc.freenode.net]
Nutssh has quit [niven.freenode.net irc.freenode.net]
TaXules has quit [niven.freenode.net irc.freenode.net]
ozzloy has quit [niven.freenode.net irc.freenode.net]
zmdkrbou has quit [niven.freenode.net irc.freenode.net]
buggs has quit [niven.freenode.net irc.freenode.net]
khaladan has joined #ocaml
Demitar_ has joined #ocaml
ozzloy has joined #ocaml
dbueno_ has joined #ocaml
flux__ has joined #ocaml
Nutssh has joined #ocaml
TaXules has joined #ocaml
zmdkrbou has joined #ocaml
buggs has joined #ocaml
chessguy has joined #ocaml
jajs has quit ["Leaving"]
mikeX has quit ["leaving"]
mikeX has joined #ocaml
Skal has joined #ocaml
m3ga has quit ["disappearing into the sunset"]
chessguy has quit [" HydraIRC -> http://www.hydrairc.com <- 100,000+ downloads can't be wrong"]
Amorphous has quit [Read error: 104 (Connection reset by peer)]
slipstream-- has joined #ocaml
Amorphous has joined #ocaml
romildo has joined #ocaml
dbueno_ has quit [niven.freenode.net irc.freenode.net]
khaladan has quit [niven.freenode.net irc.freenode.net]
flux__ has quit [niven.freenode.net irc.freenode.net]
ozzloy has quit [niven.freenode.net irc.freenode.net]
buggs has quit [niven.freenode.net irc.freenode.net]
Nutssh has quit [niven.freenode.net irc.freenode.net]
TaXules has quit [niven.freenode.net irc.freenode.net]
zmdkrbou has quit [niven.freenode.net irc.freenode.net]
Demitar_ has quit [niven.freenode.net irc.freenode.net]
slipstream-- has quit [niven.freenode.net irc.freenode.net]
mikeX has quit [niven.freenode.net irc.freenode.net]
rickdangerous has quit [niven.freenode.net irc.freenode.net]
Snark has quit [niven.freenode.net irc.freenode.net]
duncanm has quit [niven.freenode.net irc.freenode.net]
slipstream has quit [niven.freenode.net irc.freenode.net]
seafood_ has quit [niven.freenode.net irc.freenode.net]
datrus has quit [niven.freenode.net irc.freenode.net]
bohanlon has quit [niven.freenode.net irc.freenode.net]
julien has quit [niven.freenode.net irc.freenode.net]
romildo has quit [niven.freenode.net irc.freenode.net]
Amorphous has quit [niven.freenode.net irc.freenode.net]
_velco has quit [niven.freenode.net irc.freenode.net]
david_koontz has quit [niven.freenode.net irc.freenode.net]
pattern has quit [niven.freenode.net irc.freenode.net]
gim has quit [niven.freenode.net irc.freenode.net]
abez has quit [niven.freenode.net irc.freenode.net]
levi_home has quit [niven.freenode.net irc.freenode.net]
Wazm_ has quit [niven.freenode.net irc.freenode.net]
cmeme has quit [niven.freenode.net irc.freenode.net]
love-pingoo has quit [niven.freenode.net irc.freenode.net]
shawn has quit [niven.freenode.net irc.freenode.net]
bzzbzz has quit [niven.freenode.net irc.freenode.net]
Ugarte has quit [niven.freenode.net irc.freenode.net]
dbueno has quit [niven.freenode.net irc.freenode.net]
Eelis has quit [niven.freenode.net irc.freenode.net]
Hadaka has quit [niven.freenode.net irc.freenode.net]
pingu has quit [niven.freenode.net irc.freenode.net]
crack_head has quit [niven.freenode.net irc.freenode.net]
ulfdoz has quit [niven.freenode.net irc.freenode.net]
dechunker has quit [niven.freenode.net irc.freenode.net]
knobo has quit [niven.freenode.net irc.freenode.net]
haelix_ has quit [niven.freenode.net irc.freenode.net]
descender has quit [niven.freenode.net irc.freenode.net]
gonnet has quit [niven.freenode.net irc.freenode.net]
mellum has quit [niven.freenode.net irc.freenode.net]
slipstream-- has joined #ocaml
mikeX has joined #ocaml
rickdangerous has joined #ocaml
Snark has joined #ocaml
duncanm has joined #ocaml
datrus has joined #ocaml
bohanlon has joined #ocaml
julien has joined #ocaml
seafood_ has joined #ocaml
khaladan has joined #ocaml
Demitar_ has joined #ocaml
ozzloy has joined #ocaml
dbueno_ has joined #ocaml
flux__ has joined #ocaml
Nutssh has joined #ocaml
TaXules has joined #ocaml
zmdkrbou has joined #ocaml
buggs has joined #ocaml
love-pingoo has joined #ocaml
shawn has joined #ocaml
bzzbzz has joined #ocaml
Ugarte has joined #ocaml
dbueno has joined #ocaml
Eelis has joined #ocaml
Hadaka has joined #ocaml
crack_head has joined #ocaml
pingu has joined #ocaml
dechunker has joined #ocaml
knobo has joined #ocaml
haelix_ has joined #ocaml
ulfdoz has joined #ocaml
descender has joined #ocaml
gonnet has joined #ocaml
mellum has joined #ocaml
malc_ has joined #ocaml
romildo has joined #ocaml
Amorphous has joined #ocaml
_velco has joined #ocaml
david_koontz has joined #ocaml
pattern has joined #ocaml
gim has joined #ocaml
abez has joined #ocaml
levi_home has joined #ocaml
Wazm_ has joined #ocaml
cmeme has joined #ocaml
romildo has quit ["Leaving"]
love-pingoo has quit ["Leaving"]
mikeX has quit ["reboot"]
<datrus> anyone knows if it's possible to do pattern matching over constructors like:
<datrus> match f with _(f1,f2) -> ...;;
<datrus> in order to match all binary operators
<datrus> and _(f1,f2,f3) to match all ternary operators for example
<datrus> or do i have to list explicitely all binary/ternary/... operators
<datrus> i mean constructors
<malc_> i don't see how this can work.. consider type moo = A of (int * int) | B of (float * float) or some such
<datrus> i have: type prop_formula = False | True | Prop of string | Not of prop_formula | And of prop_formula * prop_formula | Or of prop_formula * prop_formula | ...
<datrus> i would like to match unary constructors (like Not)
<datrus> binary constructors (like And,Or)
<datrus> using a single pattern for each arity
<malc_> i think the best you can do is | And (p1, p2) | Or (p1, p2) -> ... i.e. multiple patterns one block of code
<datrus> yes ok, so i have to list the constructors explicitely
rickdangerous has quit ["leaving"]
ramki has quit [Remote closed the connection]
dylan has joined #ocaml
dylan has left #ocaml []
danly_ is now known as danly
Smerdyakov has joined #ocaml
velco has quit ["Ex-Chat"]
Mr_Awesome has joined #ocaml
_fab has joined #ocaml
<Mr_Awesome> hmm, what would be a good name for a type that holds either a literal value or a symbolic identifer in a parsing program?
mikeX has joined #ocaml
<mikeX> there's no way for a function to have a variable argument list, right? (besides printf etc)
<pango> depends what you call a "variable argument list"
<Mr_Awesome> yeah, lists can kind of simulate that
<Mr_Awesome> assuming you mean variable-length arg lists
<pango> you can get some amount of flexibility with labels are optional arguments
<mikeX> hmm : S, I'm wondering how to make an assert_raises function
<mikeX> (takes an exception and a function and makes sure the exception is raised)
<Mr_Awesome> where would you need variable arg lists?
<pango> mikeX: not sure what you mean exactly with that description
<mikeX> well the function arguments would have to be passed as well
<Mr_Awesome> oh ok
Ugarte has quit ["leaving"]
<pango> assert_raises (fun () -> f a b c) ?
<pango> just delay evaluation ?
<Mr_Awesome> that delays evalutation?
<Mr_Awesome> that would work then
<mikeX> no, call the function, and assert the given exception is raised by the function
<mikeX> although I'm not quite sure what you meant
Ugarte has joined #ocaml
smimou has joined #ocaml
<Mr_Awesome> if you can delay the evaluation of the function your passing, you can simply bind all the args right before you call it
<mikeX> then how would I delay the evaluation?
<Mr_Awesome> let assert_raises e f = try f () with e -> () | _ -> failwith "assert_traises"
<mikeX> oh, add an extra () arg I see
descender has quit [Remote closed the connection]
<Mr_Awesome> then assert_raises MyExn (func a b c)
<Mr_Awesome> i mean (fun () -> func a b c)
<pango> Mr_Awesome: will need something like try with exc when exc = e, otherwise e will be just redefined
<mikeX> still the function needs to be modified :/
<Mr_Awesome> yeah youre right
<mikeX> actually, what it should do is: let assert_raises e f = try f (); assert false with e -> () | _ -> assert false
_velco is now known as velco
<Mr_Awesome> yeah good point
<mikeX> i'm just trying to make some unit tests, and I'm immitating the python unittest module : \
<mikeX> i guess there should be a way better fitted to ocaml, maybe i'll try the oUnit module
descender has joined #ocaml
<pango> you may also need ignore, as in ignore(f ()), otherwise your assert_raises will be picky about f return type
<mikeX> good point
<mikeX> hmm, assert_raises e f last_arg should work for any function right?
<pango> that's also another way to delay evaluation
<mikeX> : ), thanks pango Mr_Awesome
<pango> used by Printexc.print, Printexc.catch, Unix.handle_unix_error, etc.
<Mr_Awesome> there is a Lazy module, but ive never used it
<pango> lazy does more than you need, it also caches result
postalchris has joined #ocaml
<mikeX> weren't there plans for exception tracing at some point?
<mikeX> (which function raised the exception and where etc)
<pango> you already have that for bytecode executables
<pango> for native there's a compiler patch in the bug tracker
<mikeX> ah yes, that's what I was talking about
<mikeX> so I guess it will be accepted at some point right?
<pango> OCAMLRUNPARAM="b"
<pango> (traces uncaught exceptions only)
<mikeX> val assert_raises : ?msg:string -> exn -> (unit -> 'a) -> unit, hmm that's what oUnit uses
Skal has quit [Remote closed the connection]
<pango> no idea
Smirnov has joined #ocaml
<Smirnov> Are you allowed to define several functions inside another function without using the "in" keyword
<pango> no
<Smirnov> damn
<Smirnov> how come you can do it at the outmost level?
<pango> lets without in are global declarations
<pango> that's precisely their semantic
<Smirnov> should I do (let x = foo) in
<pango> what's your problem exactly ?
<Smirnov> or (let x = foo in) ?
<Smirnov> it just says syntax error, I was trying to define several functions inside another one
<pango> neither
<pango> you don't need ()s
<Smirnov> hmm
<pango> you probably already used let in for non functional values; that's exactly the same thing
<Smirnov> well i'm doing a match in my functoin im defining
<Smirnov> so maybe the "in" is getting confused because of the match
<pango> put ()s around the match then, if you're unsure
<Smirnov> I'm trying to use pastebin to show you.. damn this site is slow
<Smirnov> i'm getting an error on line 2
<Smirnov> This '(' might be unmatched
<Smirnov> I can paste whatever is on top of that as well if you want
<pango> (I often use http://nopaste.tshw.de/, at least it's less overloaded)
<pango> the error is not in what you pasted
<Smirnov> grr
<Smirnov> ok i'll go back and look over it
<pango> find an editor that does indentation for you ;) it helps
<Smirnov> my editor does indentation but somehow i cant paste out of it
mikeX has quit [Read error: 110 (Connection timed out)]
<Smirnov> my editor also does ) matching and its saying all my ()s are closed properly
<pango> and indentation doesn't give you any clue about unclosed/superfluous/... parenthesis ?
<Smirnov> wow this paste site rocks
<pango> where does the compiler complain ?
<Smirnov> the beginning of line 21
<pango> I guess there's the main body of unif definition just below ?
<Smirnov> yes
<Smirnov> ugh
<pango> I still can't find anything wrong
<Smirnov> my error was on the function below that
<Smirnov> is "and" a keyword?
<pango> yes
<pango> for simultaneous declarations
<Smirnov> is that the same as &&
<Smirnov> damn it
<Smirnov> ok
<Smirnov> i had
<Smirnov> (isVariable t and not (isVariable s)) on the next function
<pango> would adding ;; between toplevel declarations have helped ?
<Smirnov> doubt it, i should have been using && not and
<pango> I mean, helped the compiler complaining at the right place
<Smirnov> "in" only works with a let right?
<Smirnov> cause i'm having some other weird syntax errors now
<pango> mmmh I'd say yes... I can't think of another construct using 'in'...
<Smirnov> having a syntax error on http://nopaste.tshw.de/11601558237772d/ line 13 now
<pango> btw, raise (Failure "msg") <=> failwith "msg"
<Smirnov> ah cool
<pango> forgot the = at the end of previous line
<Smirnov> damn
<Smirnov> I wish the errors were better :P
<pango> you don't need the parenthesis around the tuples you create just for matches: match s, t with TpVar x, _ -> ...
<pango> (a matter of taste, however)
<Smirnov> ah
<Smirnov> ok
<Smirnov> these constructors are giving me a lot of grief
<pango> and you can regroup some cases ... | Bool, Bool | String, String | Nat, Nat -> false ...
<Smirnov> oh i can chain cases like that?
<pango> yes
<Smirnov> cool
<pango> first code you pasted had more useless parenthesis, but I guess it was attempts at narrowing problems ;)
<Smirnov> yep
<Smirnov> is there any suggetsions you can give me for when I can omit parentheses around constructors?
<Smirnov> those were giving me some grief
<pango> depends on cases, I guess sometimes they're unavoidable
<Smirnov> yeah those were giving me lots of grief so I started putting extra parentheses around them just in case
<Smirnov> I only started doing ocaml recently so I'm still confused about when I can omit ()s
<Smirnov> so I can omit external ()s around a constructor if I have internal ()s?
<Smirnov> Foo(x,y) instead of (Foo(x,y))
chessguy has joined #ocaml
<pango> you may have a problem with the priority of function application, that you don't have with :: constructor
<pango> f Constructor arg1 arg2 being interpreted as f (Constructor) (arg1) (arg2)
<Smirnov> is there a shortcut for the identity function (fun x ->x) ?
<Smirnov> ah, function application is always interpreted as having () around each argument?
<Smirnov> f x y z === f (x) (y) (z) ?
<pango> id is not predefined, but it's not difficult either
<Smirnov> ok
<malc_> # external id : 'a -> 'a = "%identity";;
<malc_> external id : 'a -> 'a = "%identity"
<malc_> # id 1;;
<malc_> - : int = 1
<malc_> yep.. dead simple
<Smirnov> yeah but its not part of the library so i cant use it on a test :P
<pango> malc_: or just let id x = x (but your solution may be more efficient ;) )
<mellum> malc_: is there any advantage of that over let id x = x?
<malc_> pango: it has a nice "guru" touch to it ;)
<malc_> mellum: doubtful.. "%identity" is used by Inria for dirty things mainly
<malc_> magic like things i'd say
<pango> it's probably converted to a no-op whenever possible
<malc_> i think it's always a no-op
<malc_> it's there to fool the type checker
<malc_> at least that's my theory
<pango> (Char.code, etc.)
<malc_> yeah yeah
<malc_> anyhow
malc_ has quit ["leaving"]
dbueno_ has quit [Read error: 110 (Connection timed out)]
Foxyloxy has joined #ocaml
chessguy has quit [" Like VS.net's GUI? Then try HydraIRC -> http://www.hydrairc.com <-"]
<Smirnov> I'm matching for a (_,_) that should match any 2-tuple right?
<Smirnov> not just a tuple with the same value?
<pango> OCaml's pattern matching is linear, so you can't do the latter anyway (short of writing (x, y) when x = y)
<Smirnov> ok
<Smirnov> there is a "when" keyword?
<pango> yes, see guards
<Smirnov> whats a guard
<pango> arbitrary predicate added to a matching case, and that must also be verified for the case to match
<Smirnov> how do I find the list of them?
<Smirnov> There is no "Guard" on the manual page
<pango> mmmh ? any predicate will do
<Smirnov> Can't find what a predicate is either
<Smirnov> :(
<pango> a predicate is a function that returns a boolean value
<Smirnov> so
<Smirnov> how do I use functions with |
<Smirnov> fun Int x -> x + 1 | Float x -> x +. 1 ?
<Smirnov> speaking of which, how do I access the Int, Float, etc constructors?
<pango> function is equivalent to fun x -> match x with
<pango> so let f = function false -> 0 | true -> 1 is the same as let f x = match x with false -> 0 | true -> 1
<pango> and there's no Int, or Float predefined constructors
<Smirnov> hmm
<Smirnov> syntax error?!
<Smirnov> i typed in "let f = function false -> 0 | true -> 1;;"
<pango> None, Some, false, true, are predefined constructors ([], ::, and maybe others can be seen as predefined constructors too)
<pango> # let f = function false -> 0 | true -> 1 ;;
<pango> val f : bool -> int = <fun>
<pango> "works for me"
<Smirnov> oh crap
<Smirnov> you cant do that with fun?
<pango> you'd have to name the argument that's left anonymous by function
<Smirnov> what do you mean
<Smirnov> isnt function x the same as fun x?
<pango> let f = fun x -> match x with false -> 0 | true -> 1
<pango> no
<Smirnov> whats the difference
<pango> as I said function is equivalent to fun x -> match x with, so function x is the same as fun x' -> match x' with x -> ...
<pango> since matching with x will always succeed, you get the same as fun x, but that's a special case
<Smirnov> interesting
<Smirnov> so fun is essentially function but without being able to put in patterns where the arguments would go?
<Smirnov> match-like patterns*
<pango> on the other hand fun accepts several arguments, whereas function only accepts its anonymous one
<Smirnov> hm
<Smirnov> so you cannot do function x y -> ...?
<pango> personally I seldom use the 'function' keyword... only in very specific cases it doesn't get in the way of readability, imho
<pango> # function x y -> 0 ;;
<pango> Syntax error
<Smirnov> I see
<Smirnov> although I suppose fun x -> match x with p1 -> e1 | p2 -> e2 ... is more typing than fun p1 -> e1 | pt2 -> e2
<Smirnov> s/fun p1/function p1
bluestorm has joined #ocaml
<pango> not much more, function is longer than fun :)
<Smirnov> oh well, most of the time i need to make functions on the spot I'm using a fold
<pango> and then you need at least two arguments, so 'function' is not an option... unless you write List.fold (fun acc -> function ... ) not excessively exciting syntax
<Smirnov> exactly
<Smirnov> one more thing
<Smirnov> how do I know when function types take a 'a, and when they take a _'a
<pango> you mean '_a
<Smirnov> yes, '_a
<pango> those are weak types... they appear in type system because of imperative constructs
<pango> there's a good chapter on the topic in "Developing applications with objective caml"
<pango> 's the right link)
<pango> however that chapter shows its age; Many (all ?) of the examples do not work with recent ocaml compilers because the type system has been improved
<pango> (yet weak types haven't disappeared; only in some cases)
<Smirnov> hm
<Smirnov> so I only have to worry about weak types when I'm dealing with mutables/
<pango> seems not...
<pango> # let idid = let id x = x in id id ;;
<pango> val idid : '_a -> '_a = <fun>
<pango> (so thinking of it, maybe they're other reasons for weak types than imperative constructs)
<Smirnov> :-|
<Smirnov> i think thats because of partial application
<pango> # let idid y = let id x = x in id (id y) ;;
<pango> val idid : 'a -> 'a = <fun>
<dan2> pango: what's the way that you can match functions with i.e. function n > 5 ...
<dan2> pango: I remember you showing it to me once, I don't remember how
<pango> dan2: the guards we were talking of previously ?
<pango> dan2: match x with n when n > 5 -> ...
<dan2> ahh, thanks
<dan2> pango: does that work with function n syntax?
<dan2> it does
<dan2> cool stuff
<pango> Smirnov: ah, "This modification of the typing of application has consequences for pure functional programs." just below in "developing apps..." book :)
chessguy has joined #ocaml
<pango> dan2: since function is equivalent to fun x -> match x with, you can write function n when n > 5 -> ...
<dan2> nice
<pango> brb
<dan2> pango: that syntax is so nice
<Smirnov> is there a shortcut to convert true->1, bool -> 0?
pango has quit ["Leaving"]
pango has joined #ocaml
<abez> Smirnov: if x then 1 else 0 XD (sorry)
<Smirnov> hah
<pango> Smirnov: nothing healty ;)
<Smirnov> hmm
<Smirnov> should I always enclose a match or if in ()s if I want to use the value of that expression somewhere else?
<Smirnov> i was doing some if x then 1 or 0 + if y then 1 or 0 + if z then 1 or 0, and it was getting majorly confused
<pango> let int_of_bool x : bool-> int = Obj.magic x
<pango> or malc's external int_of_bool : bool -> int = "%identity" ;)
<Smirnov> whats x : bool ?
<pango> (but both depend on runtime implementation)
<Smirnov> i'm so confused as to what you just did
<Smirnov> and when I typed that in its returning a function anyways
<pango> parenthesis, or let bindings
<pango> if for anything else, to avoid confusing programmers :)
<pango> expr:type the syntax to declare the type of an expression explicitly
<Smirnov> oh
<Smirnov> cool
<pango> in above case, it was the type of the function int_of_bool that I declared, not the type of x
<Smirnov> Obj.magic sounds magical
<pango> I would have to write (x:bool) for that
<Smirnov> it just returns a <poly> though :(
<pango> Obj.magic is magical
<pango> # 1 + Obj.magic 2. ;;
<pango> - : int = 67364391
<Smirnov> wtf
<pango> # 1. +. Obj.magic 2 ;;
<pango> Segmentation fault
jajs has joined #ocaml
jajs has quit [Remote closed the connection]
jajs has joined #ocaml
jajs has quit [Remote closed the connection]
jajs has joined #ocaml
<pango> it only works in controlled ways
jajs has quit [Remote closed the connection]
jajs has joined #ocaml
jajs has quit [Remote closed the connection]
jajs has joined #ocaml
jajs has quit [Remote closed the connection]
<pango> it's a way to bypass the type system, when you *really* know what you're doing
<Smirnov> cool
<Smirnov> Is that a core feature?
<Smirnov> Or just tacked on?
<Smirnov> Heheheh.
<pango> it's hardcode feature :)
<pango> hardcore even
<Smirnov> but does that depend on the ocaml compiler i mean
<pango> it depends on the similar memory layout of ints and bools, in that case
<pango> that allows for your 0 <-> false, 1 <-> true mapping
<Smirnov> yeah I was just playing with Obj.magic
<Smirnov> seems like it lets you C-style unions
<pango> just as bad as that, yes ;)
<pango> the closest equivalent in ocaml, variants, is safe, so it would be a very bad trick to use Obj.magic to simulate unions!
<dan2> pango: have you used camlidl before?
<pango> no
<dan2> hmm
<Smirnov> mmm, Obj.magic rocks
chessguy has quit [Read error: 145 (Connection timed out)]
<bluestorm> hum
<Smirnov> although I'm guessing it would horribly break across different platforms :-D
<bluestorm> i found in a caml light book
<bluestorm> something like
<bluestorm> fun true true -> true | _ _ -> false
<Smirnov> thats not right
<Smirnov> you cant do matching with fun
<bluestorm> i thought the same
<pango> Smirnov: better only use it when anything else fails
<Smirnov> you can do function true -> true | _ -> false
<dan2> pango: does Unix implement the fopen interface of POSIX systems?
<pango> let, fun, match, try, all those do pattern matching
<bluestorm> actually Smirnov, caml light can
<Smirnov> pango: lol i am telling all my friends about Obj.magic, its awesome :-D
<pango> (maybe I missed some ?)
<bluestorm> hum
<Smirnov> hmm
<Smirnov> i'm guessing caml-light isnt the same as ocaml then
<pango> how do you think let (a, b) = (3, 4) works ?
<bluestorm> do you know a way to do a single pattern matching on numerous de-curryfied arguments in ocaml ?
<Smirnov> pango: i meant implicit matching just with the fun keyword
<pango> Smirnov: works too
<bluestorm> i think this feature was interesting
<Smirnov> put it in a tuple bluestorm?
<Smirnov> fun x y z -> match (x,y,z) with (_,_,_) -> true
* pango checking...
<bluestorm> yeah, i know this way
<pango> ah, no, not in ocaml
<bluestorm> but matching without tuples may be more performance-friendly, i guess
<bluestorm> (actually, it may have been implemented by some hidden tuple or something like that)
<Smirnov> thats compiler-specific
<Smirnov> not language specific
<pango> bluestorm: native compiler optimizes tuples away
<bluestorm> ah ?
<Smirnov> shift the burden of optimization on the compiler writers ;)
batdog is now known as batdog|gone
<bluestorm> Smirnov: building a tuple is language-specific
<Smirnov> no but tuples not being performance-friendly is compiler specific
<bluestorm> i mean, it's great to learn that it's not kept by the compilator, but i cannot say "ok, this is heavier, but the compiler could/should change it so there is no problem"
<bluestorm> ah
<bluestorm> hum pango
<bluestorm> great :p
<bluestorm> i read this one time
<bluestorm> but i forgot the native-code part :p
<bluestorm> Smirnov -> when you ask the program to build a tuple, this cost is program specific, i think
<mellum> ocamlopt doesn't optimize away redundant tuple allocations, BTW.
<mellum> In fact the ocaml optimizer is utterly lame, it doesn't even do CSE. It's really a miracle that the programs usually run fast...
<Smirnov> lol
Snark has quit ["Leaving"]
<bluestorm> (CSE ?)
<pango> common subexpressions elimination
duncanm has quit [Remote closed the connection]
duncanm has joined #ocaml
<pango> (not that I endorse this answers, or that it rules out cse optimization -common subexpressions can arise in intermediary code that is not present in source-, just to let you know "official" stand on the topic of compiler optimizations)
<pango> (2 years old, at that)
<bluestorm> thanks
velco has quit ["I'm outta here ..."]
<mellum> I think the answer is moronic. I don't want to make my programming style dependent on the lameness of a compiler.
<mellum> and contrary to his assertion, when I write "let a, b =" I do not want to express "please allocate a tuple on the heap".
<pango> agreed, and I'd like to know if it's still his stand today
<mellum> probably yes.
<mellum> The real reason is of course that implenting CSE won't get you a publication :)
<mellum> unlike weird type system shit that nobody needs
jajs has joined #ocaml
jajs has quit [Remote closed the connection]
jajs has joined #ocaml
<pango> I agree on the former only ;) Some has to work on 'weird type systems', and who knows what will come out of it...
<mellum> sure, this stuff needs to be researched. But ocaml would profit from some more down to earth tasks more...
<mellum> and since nobody outside of inria is allowed to do this, it doesn't happen
<bluestorm> hum
<bluestorm> if you submit a code with something like that implemented
<bluestorm> they wouldn't use it ?
<mellum> I don't know. Maybe they actually would. But they don't do the slightest thing of encouraging things like that. And I wouldn;'t want to try it for fear of it being turned down.
<Smirnov> Where do I find more info about "begin" and "end" ? I'm having a hard time looking up iterators in the manual
<mellum> iterators?
<pango> begin and end are synonyms for ( and )
<pango> # 1 * begin 2 + 3 end ;;
<pango> - : int = 5
<pango> (bad example, but you get the idea ;) )
<bluestorm> hey, your example is good !
<bluestorm> i never tried begin/end in simple expressions
<bluestorm> interesting to see how much it's "the same as ( )"
<Smirnov> it is ???
<Smirnov> then how does that make it an iterator
<bluestorm> hum, where did you heard about iterators in ocaml ? o_O
<bluestorm> (argh)
<Smirnov> on the pervasives page
<Smirnov> yes
<Smirnov> er.. no
<pango> I see no mention of iterator(s) there
<pango> while you could use begin/end with them (as said before), parenthesis are much more common
<Smirnov> oh.. so there arent really iterators?
<pango> List.fold_left (fun acc e -> acc + e) 0 [1;2;3;4] instead of List.fold_left begin fun acc e -> acc + e end 0 [1;2;3;4]
<Smirnov> so you cant even fake coroutines?!
<pango> iterators sucks
<pango> if that's those kind of 'iterators' you're talking of
<Smirnov> i was thinking more along the lines of generators
<Smirnov> ah
<Smirnov> python iterators are much more powerful out of the box than C++ iterators :)
<Smirnov> ah, nice, it talks about generators here
<Smirnov> hm.. i never thought of iterators on a tree
<bluestorm> [23:42:27] <Smirnov> so you cant even fake coroutines?!
<bluestorm> hum
<bluestorm> coroutine is the thing that can "yield" some values ?
<Smirnov> but iterators on linear objects are cool :P
<pango> I don't miss them ;)
<Smirnov> I always thought of them as quite useful for describing infinitely large ADTs
<pango> what about lazy values ?
<Smirnov> ah, i have no idea what that is
<Smirnov> "The difference is that these closure objects are created automatically during the execution of the mapping functions, rather than having to be explicitly created by the programmer, as in C++, and the side-effect-free nature of mappers is obvious to a compiler based on a cursory syntactic scan." seems like a complaint about the language
<Smirnov> some languages like python use iterators implicitly
<Smirnov> anyways i wish I knew ada and lisp cause most of that code went over my head
<Smirnov> btw how are you supposed to do for-loops without using a reference type?
<pango> recursive function
<Smirnov> well yes
<Smirnov> but i was specifically inquiring about the "for" construction
<pango> for loops are useless for pure functional programming
<Smirnov> i know that, im just curious
<pango> they could be used without references, but not without side effects
<pango> (for example copy the content of a file to another,...)
david_koontz has quit [Read error: 131 (Connection reset by peer)]
david_koontz has joined #ocaml
postalchris has quit [Read error: 113 (No route to host)]
bluestorm has quit ["Konversation terminated!"]
pango is now known as pangoafk
pangoafk is now known as pango
jajs has quit [Remote closed the connection]
RSi is now known as RSi_
Smirnov has left #ocaml []
romildo has joined #ocaml
pango has quit [Remote closed the connection]
smimou has quit ["bli"]
duncanm_ has joined #ocaml
duncanm has quit [Read error: 104 (Connection reset by peer)]