rwmjones changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | Grab Ocaml 3.10.1 from http://caml.inria.fr/ocaml/release.html (featuring new camlp4 and more!)
zmdkrbou_ is now known as zmdkrbou
buluca has quit [No route to host]
piggybox__ has quit [Read error: 110 (Connection timed out)]
ikaros has quit ["segfault"]
ita has quit [Remote closed the connection]
middayc has joined #ocaml
rwmjones has quit ["Closed connection"]
mbishop has quit ["brb"]
mbishop has joined #ocaml
leo037 has quit ["Leaving"]
hsuh has joined #ocaml
<middayc> anybody here?
* mwc is
<middayc> uh I just found the answer
* mwc slinks off
<middayc> I couldn't find what is between items when you create new record from existing record .. { speed with x = speed.x + 2 ; y = speed.y + 2 } -- ; is the answer
<middayc> and I couldn't find this example in any of html docs .. but it was in that book.pdf
<Smerdyakov> You shouldn't need an example, as the manual has the complete language grammar.
hsuh has quit ["rcirc on GNU Emacs 23.0.60.1"]
<middayc> which manual
<mwc> middayc, the official one, in the info pages, and online: http://caml.inria.fr/pub/docs/manual-ocaml/manual008.html
hsuh has joined #ocaml
<cygnus_> can someoen please expali nthis
<cygnus_> #type 'a wlist = [`Nil | `Cons of 'a * 'a wlist | `Snoc of 'a wlist * 'a];;
<cygnus_> its a polymorphic variant i think
<mwc> it's saying your a wlist of items of a contains those polymorphic variant tags, and only those
<cygnus_> i don't understand polymorphic variant tags
<middayc> mwc: thanks
<mwc> cygnus_, well, with regular variant types, the "tags" or constructors can only be associated with one type
<cygnus_> like a list ?
<mwc> type 'a mylist = Nil | Cons of 'a * 'a mylist;;
<mwc> So now Nil is a value only associated with mylist
<mwc> # Nil;;
<mwc> - : 'a mylist = Nil
<cygnus_> yes
<mwc> on the other hand, you could define
<mwc> # type 'a foolist = [`Nil | `Cons of 'a * 'a foolist ];;
<mwc> type 'a foolist = [ `Cons of 'a * 'a foolist | `Nil ]
<mwc> # type 'a barlist = [`Nil | `Cons of 'a * 'a barlist ];;
<mwc> type 'a barlist = [ `Cons of 'a * 'a barlist | `Nil ]
<cygnus_> #let wlist_of_vlist l = (l : 'a vlist :> 'a wlist);;
<cygnus_> what is the :> doing
<mwc> type restricting
<cygnus_> #let open_vlist l = (l : 'a vlist :> [> 'a vlist]);;
<cygnus_> is this one too?
<mwc> yeah, that's what the operator means.
<cygnus_> what is the differecne between these two
<mwc> okay, :> indicates that you're trying to widen the types in a smaller set of polymorphic variants to a larger one. let me come up with an example.
<mwc> Alright
<mwc> see how vlist is defined?
<mwc> type 'a vlist = [`Nil | `Cons of 'a * 'a vlist];;
<mwc> the type wlist is a "widening" or a superset of the labels in vlist
<cygnus_> ok
<mwc> type 'a wlist = [ `Cons of 'a * 'a wlist | `Nil | `Snoc of 'a wlist * 'a ]
<mwc> so make some values in the toplevel
<mwc> # let a : int vlist = `Cons (4,`Nil);;
<mwc> val a : int vlist = `Cons (4, `Nil)
<mwc> # let b : int wlist = `Cons (5,a);;
<mwc> but that fails
Snrrrub__ has joined #ocaml
<mwc> because the `Cons tag in the context of vlist is expecting to be constructed of an int and an int vlist, and that's exactly what a is
<mwc> the problem is, `Cons in the context of a wlist is expecting an int and a wlist,
<mwc> so if we apply the :> notation, that'll tell :> to "widen" the types
<mwc> since vlist is a subset of wlist
<mwc> # let b : int wlist = `Cons (5,(a :int vlist :> int wlist));;
<mwc> val b : int wlist = `Cons (5, `Cons (4, `Nil))
<mwc> the :> syntax is defined here: http://caml.inria.fr/pub/docs/manual-ocaml/expr.html
<mwc> well, really it's the semantics that's defined there. :)
<mwc> I'd better add that before Smerdyakov yells at me :)
Mr_Awesome has joined #ocaml
Snrrrub has quit [Read error: 110 (Connection timed out)]
cmeme has joined #ocaml
cmeme has quit [Read error: 104 (Connection reset by peer)]
cmeme has joined #ocaml
ecc_ has quit ["Client exiting"]
<cygnus_> mwc: sorry back
<cygnus_> mwc: how come it fails since it's a wlist not a vlist for Cons(5,a) or does the wlist only extend it?
<mwc> cygnus_, I made if a wlist for the sake of showing you why we need :> to coerce a type
<mwc> I don't like the word coerce, because it won't be allowed to happen in an inconsistent way
<mwc> so I prefer the term "widen"
mwc has quit ["Leaving"]
zmdkrbou_ has joined #ocaml
zmdkrbou has quit [Read error: 110 (Connection timed out)]
middayc has quit []
cmeme has quit [Read error: 104 (Connection reset by peer)]
cmeme has joined #ocaml
thermoplyae has quit ["daddy's in space"]
<cygnus_> ok ty
thermoplyae has joined #ocaml
Snrrrub__ is now known as Snrrrub
pango has quit [Remote closed the connection]
pango has joined #ocaml
ttamttam has joined #ocaml
ttamttam has left #ocaml []
ttamttam has joined #ocaml
madroach has joined #ocaml
middayc has joined #ocaml
buluca has joined #ocaml
madroach has quit [Remote closed the connection]
alexp has joined #ocaml
hsuh has quit [Remote closed the connection]
ygrek has joined #ocaml
hkBst has joined #ocaml
rwmjones has joined #ocaml
rwmjones has quit ["Closed connection"]
rwmjones has joined #ocaml
thermoplyae has quit ["daddy's in space"]
Yoric[DT] has joined #ocaml
<Yoric[DT]> hi
<middayc> (hi)
<Yoric[DT]> How do you do ?
<middayc> I am ok, watching over my son, how are you
<Yoric[DT]> Fine.
<Yoric[DT]> Trying to get the courage to start researching bibliography about a paper.
filp has joined #ocaml
asmanur has joined #ocaml
<middayc> "bibliography about a paper" what does this mean (I am not native eng. speaker)
buluca has quit [Read error: 104 (Connection reset by peer)]
<Yoric[DT]> I'm not sure it's the right term anyway (I'm not a native Eng. speaker either).
<Yoric[DT]> I'm considering writing a paper (i.e. an article) about static analysis of C programs.
<Yoric[DT]> But right now I need to find out if somebody has done this kind of analysis already.
buluca has joined #ocaml
<middayc> aha. I understand this better :). well are you hoping that someone did or didn't (because you said you need courage I suppose you care)
<Yoric[DT]> I'm hoping nobody did.
<Yoric[DT]> Otherwise, my paper is going to be redundant :/
<middayc> yes ... I have similar issues when I try to make some software or service and then I see it's been already done
<middayc> but positive thing is that if someone did it you don't have to :)
<Yoric[DT]> Well, as I'm a Researcher, that's a negative thing :)
<middayc> :) ok you win
<middayc> I have a different problem these days
<middayc> I work for contract mainly on java, python, php.. and I thought that I became quite good programmer through the year, now that I started coming and looking and Ocaml and similar languages I discovered I am pretty lame programmer :/
<middayc> year = years
<Yoric[DT]> Well, you live and you learn...
<Yoric[DT]> I think it was Stallman who said that, no matter how good you are with C, you need to learn Lisp, even if you're never going to use it, because it will make you better.
<Yoric[DT]> Well, OCaml is one of the many descendants of Lisp :)
<alexp> Yoric[DT], hello! did you check this ? http://www.astree.ens.fr/
<Yoric[DT]> (on the other hand, so is Python)
<Yoric[DT]> Gasp, Clousot again :)
<Yoric[DT]> s/Clousot/Cousot/
<middayc> aha ... well but python can be more conventional ...
<Yoric[DT]> alexp: I'm actually analyzing quite different properties.
<Yoric[DT]> I'm basically attempting to extract system-level security policies (à la SELinux) from C code.
<middayc> hmm.. ocaml "variables" and types can't begin with upper case ?!
<Yoric[DT]> Nope.
<asmanur> middayc: it's for modules names and type constructor
<Yoric[DT]> There is a syntactic difference between variables (lower-case) and constructors/module names (upper-case).
<Yoric[DT]> It's actually something of a hack in the type system, but nobody really minds because it does make code more readable.
<Yoric[DT]> Only error messages are somewhat suprising.
<middayc> I was just trying to make all types uppercase so I would diferentate them a little with variables and functions..
<asmanur> Yoric[DT]: why it's a hack ?
<Yoric[DT]> Because that's a way to put some type information inside the name of the variable.
<middayc> now all looks the same.. ok than, undo 50x :)
<Yoric[DT]> middayc: in practice, it's more important to differentiate constructors from variables than types from variables.
<Yoric[DT]> Types and variables are seldom mixed in the same context.
<Yoric[DT]> Constructors and variables always are.
<middayc> (I meant to start with upper case , like Vector2 .. etc.)
<Yoric[DT]> You Java coder :)
<Yoric[DT]> (Javaista ?)
<middayc> :) Vector2 sounds a little javaish
<middayc> ok I had Vec2 which is a little more cryptic :)
<middayc> Javaista?
<Yoric[DT]> Well, Python coders are "Pythonistas".
<Yoric[DT]> I don't know about OCaml coders.
<Yoric[DT]> Nor about Java coders.
<middayc> aha :) ... I don't know too
ygrek has quit [Remote closed the connection]
<middayc> It hurt my brain to start using some_var instead of someVar too and I am still getting used to it
<Yoric[DT]> I had the same problem.
<Yoric[DT]> (I came from Pascal, which has the same conventions as Java)
<Yoric[DT]> But after some use, I actually started finding this more readable.
ygrek has joined #ocaml
<middayc> I used this in php a long back and have been fully converted to camelCase, but camelCase looks strange if native funcs are _ so OK
<middayc> ha .. I just for the first time saw how usefull currying can be
jderque has joined #ocaml
<Yoric[DT]> good :)
<middayc> (I made another example at that ocaml + sdl yesterday and now I am trying to make code more systematic and beautifull to look at)
rwmjones_ has joined #ocaml
rwmjones has quit ["Closed connection"]
olleolleolle has joined #ocaml
<middayc> this is the source of my ocaml+sdl learning heist no.3 .. if anyone looks and notices anything stupid he is welcome to tell http://pastebin.be/8449
<middayc> this is the screenshot, http://itmmetelko.com/blog/images/jj_sdl3ml.jpg I will put both in a blog post as I did before
zmdkrbou_ is now known as zmdkrbou
leo037 has joined #ocaml
jderque has quit [Read error: 113 (No route to host)]
middayc has quit []
dramsay has joined #ocaml
ygrek has quit [Remote closed the connection]
middayc has joined #ocaml
ygrek has joined #ocaml
ygrek_ has joined #ocaml
<petchema> middayc: you can't keep adding parameters to your draw function... At one point you'll have to group information in some "scene" record...
ygrek has quit [Remote closed the connection]
<middayc> yes, I suspect I will .. but I am learning FP and ocaml and all this so I will probably gradually came to that
Tetsuo has joined #ocaml
piggybox_ has quit ["Leaving"]
Yoric[DT] has quit [Read error: 113 (No route to host)]
Yoric_ has joined #ocaml
middayc_ has joined #ocaml
middayc has quit [Read error: 110 (Connection timed out)]
ygrek_ has quit [Remote closed the connection]
olleolleolle has quit []
seafood has quit [calvino.freenode.net irc.freenode.net]
seafood has joined #ocaml
Demitar_ has joined #ocaml
pango has quit [Remote closed the connection]
pango has joined #ocaml
Demitar has quit [Read error: 110 (Connection timed out)]
buluca has quit [No route to host]
bluestorm has joined #ocaml
<middayc_> petchema: when you said "scene record" did you mean that I will have to use one more complex structure (a kind of a scene graph) that will also be immutable and recreated each run or will that have to be mutable then?
<petchema> OCaml's record are immutable by default, and I don't think it would be a problem using an immutable record in this case (if you want to keep experimenting with functional style)
<middayc_> yes thats why I ask because I would like to keep it all immutable if possible
rwmjones_ has left #ocaml []
<middayc_> I will most likely try to do this in next version
<petchema> everything but simple scalars (int, char,...) are "references" in OCaml, so creating a copy of a record is not so expensive
<middayc_> at first when people on this channel said to me "don't move the bullet, create a new one on different location" it sounded very strange but toally revealing and so far I have done it all in this way and saw not a hinch of problems
<middayc_> so for now i just try to create new ones and trust the compiler will reuse things or whatever to make it work fast
<middayc_> can I ask how would you create that "scenegraph" I for now only know records and lists (and arrays) in ocaml.. would you do something like ->
<middayc_> let scene = { myship = {..} ; rocks = [..] ; bullets = [] ...}
<petchema> yes, that should be enough
<middayc_> aha. cool. that is easy for now. Thanks!
<petchema> (I didn't think of building a graph... but your idea is interesting)
<middayc_> 3d and also some 2d engines use "scene" graph as core of everything
<middayc_> but I always used them from OO , it now seems that running a scenegraph might be even more suitable for FP
<middayc_> OO - Object Oriented progr.
<middayc_> (well not all use scenegraph but most more complete 3d ones do - as an example of 2d scenegraph is Flash and Torque game builder)
<petchema> well, in OCaml it may be more natural to use some sum type... as in http://www.ffconsultancy.com/languages/ray_tracer/comparison.html
FZ has joined #ocaml
<middayc_> I don't know what is meant by sum type (I found in in text on the page)
ttamttam has quit ["Leaving."]
<petchema> aka variant type, algebraic type,...
<middayc_> but this scentence suggest that such graphs are clumsy as OO """The object-oriented representation of a trivial sum type as an inheritance hierarchy of classes is needlessly inefficient."""
Snrrrub__ has joined #ocaml
<middayc_> petchema.. what are you using ocaml for?
<petchema> prototyping, statistics... I'm the only one using OCaml at work ATM, so I can only use it on projects I'll be the only one working on
<middayc_> aha.. interesting :)
marmottine has joined #ocaml
<middayc_> aha .. variant type is a concrete thing in ocaml .. like tuple, record ... I now see it's that with ` signs - I havent yet came to them
<bluestorm> you don't really them at first
<bluestorm> use standard algebraic datatypes and you'll be happy
<middayc_> ok, I just read something like that http://t-a-w.blogspot.com/2006/05/variant-types-in-ocaml-suck.html -- last comment below said something like you
filp has quit ["Bye"]
rwmjones has joined #ocaml
Snrrrub has quit [Connection timed out]
<bluestorm> hum
<bluestorm> middayc_: what about learning the basic stuff before going into OO, variant types and so on ? :p
<middayc_> hey I am not rushing into OO or variant types... I currently have no intention of doing ocaml the OO way and I just heard of variant types
<middayc_> I was saying above that I have so far seen (in other languages) in game related products a concept of scene-graph and it was done using OO but that now I suspect something like scene graph might be done nicer with FP style
<middayc_> (seen = used too). then we talked about ffconsultancy example where I stumbled upon something called variant type
<middayc_> so no fear... I am grinding TEH basics
<middayc_> :)
jderque has joined #ocaml
<bluestorm> :p
rwmjones has left #ocaml []
Morphous has joined #ocaml
hcarty has quit [Read error: 110 (Connection timed out)]
Morphous_ has quit [Read error: 110 (Connection timed out)]
alexp has quit ["Leaving"]
<jonafan> here's a summary of that taw guy's blog: waaaah i had a problem in ocaml and ocaml sucks because things don't work because i want them tooooooo waaaaaaah
_KS has joined #ocaml
Dazhbog has joined #ocaml
<Dazhbog> hello
<Dazhbog> Wha libraries/toolkits do people use when writing games in ocaml?
<Dazhbog> I found SDL bindings but they seems a bit.. dated
<bluestorm> i know of two different SDL bindings but
<bluestorm> Dazhbog: are two-year-olds bindings a real problem ?
<Dazhbog> well I found ocamlsdl (http://ocamsdl.sourceforge.net)
<bluestorm> i don't think SDL evolved that much since
<Dazhbog> maybe not :P
<Dazhbog> are there better alternatives?
<Dazhbog> I'm an ocaml newbie and I would like to try writing a few simple games to get started
ygrek has joined #ocaml
smimou has quit ["bli"]
<bluestorm> i'd try ocamlsdl if i were you
<asmanur> Dazhbog: you have also mlgames based on ocamlsdl, it seems to be more high-level
<bluestorm> if you run into problems, complain
<Dazhbog> bluestorm: okay.. I'll do that. Thanks.
<bluestorm> asmanur: the good think with bare (~ low-level) bindings is that they're still useful, even when they're dead (... :-' )
<Dazhbog> I wonder why a lot of ocaml projects/libraries seem to have died around 2004-2005 .. did something happen then or are people migrating somewhere..?
<middayc_> GLCaml has SDLCaml and they are both up to date
<Dazhbog> middayc_: ah.. that'd explain why ocamlsdl hasn't been updated
<middayc_> and they compile on windows too..
<middayc_> I made a mini tutorials obour sdlcaml
<middayc_> and I will publish number 3 soon ..
<Dazhbog> middayc_: glcaml looks promising.. thanks for the pointers =)
<bluestorm> hm
<bluestorm> the problem with glcaml/sdlcaml is that they're quite low-level
<bluestorm> from what i've seen
<bluestorm> ocamlsdl is a bit more nicely wrapped than sdlcaml
<Dazhbog> btw. do you use ocaml-mode / tuareg and emacs or some hip eclipse plugin...?
<bluestorm> i use tuareg
<bluestorm> have used ocaml-mode for some time
<bluestorm> (and you can have vim tools if you want to)
<Dazhbog> bluestorm: low-level bindings also have the advantage that c/c++ examples are easily mapped to them
<bluestorm> you have to take into consideration that SDL is an inherently imperative library
<bluestorm> good if it helps you getting motivated with OCaml
<bluestorm> but maybe not the best thing if you want to see the functional land
<middayc_> there is also Allegro binding , but I think it only works on linux but am not sure
<bluestorm> (but you still will hear about those, and on the other hand i haven't any good "functional toy example" in mind)
<jderque> (never tried it)
<bluestorm> i think it is
<middayc_> if you look at my example there is very little SDL imperativish code
<middayc_> yes, I meant that one , that one is also regularly updated , it was just a while back
<middayc_> (I am also only learning ocaml and FP)
<Dazhbog> bluestorm: yes.. imperativeness of SDL did bother me a bit with lisp as well..
<Dazhbog> is ocaml's Graphics module more functional?
<flux> graphics module is not very useful except for debug output of algorithms etc
<Dazhbog> okay :P
marmottine has quit [Remote closed the connection]
<Dazhbog> I think I'll study middayc_'s examples carefully and try to learn to prevent imperativeness of SDL from creeping to other parts of code
<Dazhbog> (other than rendering that is)
<middayc_> rememeber that I should not be your FP role-model as I just learned few basic things 2 weeks back :)
<middayc_> but I did get away so far and intend to continue without any mutual or global state
ita has joined #ocaml
<Dazhbog> hehe.. well I'm not a total FP newbie.. but I'll have a look if I can learn a trick or two
<flux> sadly I foresee at some point you will find the game objects need to interact in such a fashion that you need to thread the global state to many places
<flux> I have up with goba, and went the mutable way ;)
<flux> s/have/gave/
marmottine has joined #ocaml
<middayc_> I will be doing collisions between things next... I will se what problem wait me there
<middayc_> flux: you made games with ocaml?
<flux> middayc_, I wrote this: http://www.modeemi.cs.tut.fi/~flux/goba/
<middayc_> how did you manage to hide it from google ... I searched for ocaml games for weeks and didn't see that page yet
<flux> pretty succesfully I guess :)
<flux> perhaps the page could mention (or have as keywords) "ocaml game", apparently when they are mentioned separately google doesn't quite value it
<middayc_> looks very interesting.. just the sort of game I wanna make too
<Yoric_> flux: I haven't looked at it yet, but do you mind if I borrow extracts for teaching purposes ?
<flux> yoric_, go ahead, although I'm not quite convinced how good teaching material it is :-)
Yoric_ is now known as Yoric[DT]
<Yoric[DT]> thanks
* middayc_ opens the sources and starts to copy paste :)
<flux> surprisingly many of the .mli-files have some comments..
buluca has joined #ocaml
<flux> I suppose it's not that much easier to dig into an ocaml project than it is to dig into projects in other languages (say, C).. although I can see the typing information retrieval being very handy (but afaik MSVC has that too)
<Yoric[DT]> :)
<middayc_> Dazhbog: the example I made yesterday and I haven't yet posted on blog looks a little more like a game than first 2. I will publish it tomorrow probably
<flux> a vectorized version of that could be a new project.. Goba2 :-)
<middayc_> I need to come up with a linux box .. to try this Mushroom (Goba = mushroom in my lang)
_KS has quit []
<flux> heh
<flux> btw, are there any code coverage tools for ocaml?
<flux> or did ocamlp do that too..
<flux> (I've never had much luck with ocamlp)
<flux> ocamlcp even..
<middayc_> how do you mean vectorized.. veith vector graphics? or like opengl additive blending primitives and stuff (glowy)
<flux> yes, with opengl
<flux> it would reduce the memory requirements immensely
<flux> because now there are manymanymany bitmaps around
<flux> (because software blending is so slow, it caches everything)
<middayc_> aha.. and it would also look cool. thats the look I am aiming for with my action oriented games too
ttamttam has joined #ocaml
<middayc_> (i made this in processing , I hope to make something in similar style GLCaml if all goes well )
hcarty has joined #ocaml
<Yoric[DT]> What's ocamlp ?
<flux> ocamlcp, the profiler
<Yoric[DT]> ok
<jonafan> the profiler pretty much tells you how many times a function gets called, right?
<flux> right
<jonafan> not very useful
<bluestorm> and what is "code coverage" exactly
<bluestorm> ?
<bluestorm> jonafan: i use the native profiler
<bluestorm> that gives time usage repartition among the functions
<jonafan> yeah, i think i tried that once
<bluestorm> and this one is very useful
<bluestorm> when you get to that level of optimization (that is, once a year)
<flux> bluestorm, basically information on which expressions are evaluated in the code
<bluestorm> hm
<jonafan> yeah... i haven't actually need to use it
<bluestorm> then i guess the bytecode profiler can do that
<bluestorm> hm
<flux> and also combinatorical information, like: if a = 4 || c = d then .. it'll tell you how many times the condition has been true/false, and how many times it has been false || false, false || true, etc..
<bluestorm> and native-code profiler can be used to generate call graph, wich are quite nice (but a bit noisy with the Pervasives functions)
<bluestorm> flux: do you need that very often ?
<jonafan> hey, you know the Map module?
<flux> bluestorm, no, but I suppose that information could be useful once in a while
<bluestorm> apart from diving into legacy code, i don't really see the use for that
<bluestorm> jonafan: dont ask to ask :p
<flux> to hint which parts of code aren't really being evaluated, and which are even if you think they shouldn't be
<jonafan> is there a way to make one for ints without defining your own int module first?
<jonafan> not that it's hard to do, but it's kind of bothersome
<bluestorm> hm
<bluestorm> the module is five lines long
<flux> no. in a perfect world there would be an Int-module, though, which would even further minimize the task
<bluestorm> but extlib provides a "polymorphic map" module
asmanur has quit [Remote closed the connection]
<bluestorm> flux: http://bluestorm.info/ocaml/numeric/numeric.mli.html can help you for that :-'
<Yoric[DT]> bluestorm: nice.
<Yoric[DT]> You should submit that to ExtLib.
<Yoric[DT]> (and add NumInt32)
<jonafan> i guess you can just do module M = Map.Make(struct type t = int let compare = Pervasives.compare end);;
<bluestorm> yes you can
<pango> code coverage is useful in combinaison with unit testing (to check that unit testing exercices all your code,...)
<bluestorm> Yoric[DT]: thanks for your support :p
<Yoric[DT]> :)
<bluestorm> i have a question concerning the Option module of extlib
<bluestorm> don't you think it could be interesting to add the monadic "bind" ?
<jonafan> that's what map does
smimou has joined #ocaml
postalchris has joined #ocaml
<bluestorm> jonafan: it isn't
<bluestorm> map is | Some x -> Some (f x)
<bluestorm> bind is | Some x -> f x
<bluestorm> strictly more general
<jonafan> i guess that's true
<bluestorm> and actually, i've seen/wroten some code that could be factorized with bind, but wouldn't with map
<bluestorm> eg. http://pastebin.be/8460
<bluestorm> (but it's quite specious as this code was specifically crafted for an introduction to the benefits of monads)
<jonafan> haha
Snark has joined #ocaml
<bluestorm> but i remember having written similar code in the past
<Yoric[DT]> bluestorm: do you have a tutorial on monads handy ?
<bluestorm> hm
<Yoric[DT]> (that is, monads in OCaml, not in Haskell)
<bluestorm> not quite
<bluestorm> wait
<bluestorm> it's interesting, and quite deep for a "tutorial"
<bluestorm> but i'm not sure it's the easier one
<jonafan> i should try writing the DeferredMonad, ThreadMonad, and SerialMonads
<bluestorm> Yoric[DT]: what i've written are slides for a presentation
<bluestorm> and slides are not that great for in-front-of-computer learning
<bluestorm> (and they're mostly oriented on the mathematical thing)
<bluestorm> Yoric[DT]: is that for "personal use" ?
<bluestorm> (if you're willing to learn monads, i think the best "tutorial" i've seen is the Wadler's paper, bastaad.pdf)
<Yoric[DT]> I'm currently writing my OCaml tutorial.
<Yoric[DT]> I believe that monads will deserve one chapter.
<Yoric[DT]> I'm far from that point, but some inspiration would be nice.
<Yoric[DT]> Since I don't have experience with monads, I'd rather draw that inspiration rather than teaching something in which I only have "Hello World" level.
<bluestorm> the problem with monads is that it's not an easy notion
<bluestorm> i think most people need to read *several* monads tutorial before grasping it
<bluestorm> no matter the quality of the first one
<bluestorm> but Yoric[DT], i think http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf is the most natural introduction to monads i've seen so far
<bluestorm> or at least the first ten pages
<Yoric[DT]> ok, thanks
<bluestorm> the rest of the paper is a bit harder
* Yoric[DT] adds this to the "to read" list.
<Yoric[DT]> Hard paper should be ok, provided I can write down some code to practice that.
revax has joined #ocaml
ttamttam has left #ocaml []
love-pingoo has joined #ocaml
olleolleolle has joined #ocaml
olleolleolle has quit [Client Quit]
ygrek has quit [Remote closed the connection]
jderque has quit [Read error: 113 (No route to host)]
Snark has quit ["Ex-Chat"]
FZ has quit ["ChatZilla 0.9.78.1 [Firefox 2.0.0.11/2007112718]"]
Snrrrub__ is now known as Snrrrub
<Snrrrub> If I want to read a list of items from a file and preserve ordering, is the usual practice to read an item, cons it to the list, recursively apply and then reverse the list on end of file?
buluca has quit [Remote closed the connection]
buluca has joined #ocaml
<pango> with plain lists, that's the only way that is tail recursive
<bluestorm> Snrrrub: if the list of items is reasonably short, i'd do a naive (non-tail-rec) function
<Snrrrub> So the three options would be to use a mutable structure, use a non-tail-recursive function (short lists) or do what I mentioned above, yes?
<Snrrrub> And it's decided mostly on efficiency grounds?
<pango> another would be to create a lazy list of ints out of the file, and use that. It's sad there's no standard lazy list type in OCaml (streams are destructive, so they're not always satisfactory)
<pango> s/ints/items/
<jonafan> the tail recursion limit seems to be around 100,000
<pango> jonafan: depends on arch, so I'd say, "in the few tens of thousands"
postalchris has quit [Read error: 110 (Connection timed out)]
<jonafan> yeah
<pango> Snrrrub: another solution is to not build the list at all, if possible
<pango> say, give to the file reading function some function parameter to call for each item
<jonafan> heh, or you could make it work like a fold
<jonafan> with the seed parameters as well
<pango> sure
marmottine has quit ["Quitte"]
musically_ut has joined #ocaml
buluca has quit [Read error: 110 (Connection timed out)]
<Yoric[DT]> By order of preference, I'd write a file_fold / put things in a stream / put things in a lazy list.
jlouis has joined #ocaml
<bluestorm> Yoric[DT]: you should suggest a lazy list module to the Extlib maintainers
<Yoric[DT]> I will.
<Yoric[DT]> Actually, I might submit mine.
mattam has quit [Remote closed the connection]
mattam has joined #ocaml
jlouis_ has quit [Read error: 110 (Connection timed out)]
postalchris has joined #ocaml
buluca has joined #ocaml
love-pingoo has quit ["Connection reset by pear"]
Tetsuo has quit ["Leaving"]
ReachingFarr has joined #ocaml
hkBst has quit ["Konversation terminated!"]
<ReachingFarr> I read in a tutorial that I could do named matches, such as "y as (x::xs)". However, when I try this OCaml complains. Am I using the syntax incorrectly or is there no such feature?
<bluestorm> it's the other way around
<bluestorm> (x :: xs) as y
<bluestorm> the name is at the right
<ReachingFarr> Thanks.
dramsay has quit [Read error: 110 (Connection timed out)]
thermoplyae has joined #ocaml
leo037 has quit ["slip && sleep"]
bluestorm has quit [Read error: 113 (No route to host)]
<ReachingFarr> If I have an expression that returns a tuple of two lists and I want to add an item to the first of these lists how would I go about doing so?
buluca has quit [Read error: 113 (No route to host)]
Yoric[DT] has quit ["Ex-Chat"]
<middayc_> I think you create a new tuple with first list as new list that has @ appended something and second is the same
<cygnus_> List.map fun (x,y) z -> (x+z,y) list
<middayc_> is + for appending an element to a list?
<middayc_> I looked at various docs yesterday and couldn't find anything like that so I used list @ [item] which is not so elegant
<pango> adding an element and the (right) end of lists is an O(n) operation, so it should be avoided
musically_ut has quit [Remote closed the connection]
<ReachingFarr> `x::z` appends the item x to the left of the list z.
<cygnus_> it's only an O(n) operation in ocaml right ?
<pango> ReachingFarr: or more precisely, builds (and returns) the list made with x in the front of z (z is not affected)
<pango> cygnus_: It's an O(n) operation on all languages that use this datastructure
<ReachingFarr> pango: Oh, ya. Thanks for the correction.
<cygnus_> what if i maintain another pointer to the last element ?
<middayc_> aha thanks
<pango> cygnus_: there's no pointers in OCaml
<ReachingFarr> cygnus_: I ended up using a match statement. `let rec unzip lst = match lst with [] -> ([], []) | ((x,y)::rest) -> match unzip rest with (first, second) -> x::first, y::second;;`
<cygnus_> this is why i said it's only O(n) in ocaml right ?
<cygnus_> ReachingFarr: ok cool
<pango> ReachingFarr: or let first, second = unzip rest in x::first, y::second
<ReachingFarr> cygnus_ and no. If you don't have a pointer to the tail of a list (in a language with pointers) you have to go over every item in the list.
<cygnus_> i am not disputing that
<ReachingFarr> pango: ohh, that looks nicer. Thanks.
<thermoplyae> it's O(n) in ocaml because lists are immutable structures
<cygnus_> ok it's clear
<thermoplyae> great
<pango> ReachingFarr: btw check List.split in the standard lib
<ReachingFarr> pango: Homework assignment. They have had us re-implement some other standard stuff as well.