<mikeX>
isn't it like function evaluation (right to left)?
<jip>
is it easy to program in ocaml in a side-effects-free style, or can it sneak up on you?
<mikeX>
# let x = ref 0 in ( !x, (x := 2) , !x + 1);;
<mikeX>
- : int * unit * int = (2, (), 1)
<zmdkrbou>
it's quite easy if you're careful
<jip>
i really like how haskell does side-effects, but i don't like haskell's performance :\
<mrpingoo>
I think I don't like Haskell.. but I'd need to try it to be able to say that.
<zmdkrbou>
the syntax is ugly :s
<metaperl>
does ocaml have a map function?
<zmdkrbou>
yep
<metaperl>
I keep seeing things I would do with a map like this:
<zmdkrbou>
List.map
<metaperl>
let rec apply_fun_list x f_list =
<metaperl>
if null f_list then []
<metaperl>
else ((List.hd f_list) x)::(apply_fun_list x (List.tl f_list)) ;;
<mikeX>
where do you see these?
<metaperl>
the ocaml ora book
<mikeX>
pattern matching would be more common there
<mikeX>
maybe it's in an introductory chapter
<mikeX>
the book starts kinda slow
<metaperl>
yes, I guess they are doing it that way for didactic purposes
<mikeX>
even though that's not like your standard map function
<mikeX>
a map function applies a single function to a list, right?
* zmdkrbou
would say that this defines List.iter
<zmdkrbou>
a map function creates the image of a list by a function
<mikeX>
but this applies a list of functions to a value
Revision17 has joined #ocaml
<zmdkrbou>
gni ?
<zmdkrbou>
iter ?
<mikeX>
no, the example, wait i'm confused (kinda tired)
<zmdkrbou>
:)
<mikeX>
val apply_fun_list : 'a -> ('a -> 'b) list -> 'b list = <fun>
<mikeX>
isn't that correct?
<mikeX>
whereas List.iter =
<mikeX>
List.iter;;
<mikeX>
- : ('a -> unit) -> 'a list -> unit = <fun>
<mikeX>
and List.map =
<mikeX>
- : ('a -> 'b) -> 'a list -> 'b list = <fun>
<mikeX>
so these 3 are all different, right?
<zmdkrbou>
yep
<mikeX>
so a map function isn't fitted to the first case, no?
<pango>
let apply_fun_list x f_list = List.map (fun f -> f x) f_list ?
<mikeX>
aaaahh, yes
<mikeX>
ok, I should really sleep now :)
<mikeX>
trying to think is almost painful :P
mikeX has quit ["zzz"]
shawn has quit [Read error: 110 (Connection timed out)]
<dvorak>
I'm reading the tutorial at ocaml-tutorial.org, and it mentions that file descriptors and such aren't closed automatically when the associated object is destroyed. is that still the case? (not sure how out of date the tutorial might be)
<pango>
to be accurate, they're closed when the associated object is freed, but you don't control when they're freed
<dvorak>
ah, ok. maybe I misread, I got the impression they might leak
<pango>
so better closing them explicitly
<dvorak>
so you just have to be aware that it might take some time, and clean up as appropriate
<pango>
no, just don't forget to close them
<pango>
that way you get deterministic behavior ;)
<dvorak>
nod, that makes sense
<dvorak>
but I just wanted to be sure that if I do forget to close them somewhere that it won't necessarily leak forever either
<pango>
I don't think so, memory object can have finalizers, I suppose it's being used to close dangling file descriptors
<dvorak>
can you call finalisers explicitly? seems like you might have a similar issue with some objects
<pango>
I don't think you can force an object to be freed, but it's been a while since I read the chapters on finalizers
<dvorak>
nod. might be better to have an explicit close/kill function for cleaning up anyway, instead of waiting for gc
<dvorak>
I was just thinking of you had an object that represented a network connection to another server or some such, you'd probably want to be prompt about closing it in a lot of cases
<dvorak>
most of my experiences with GC'ed languages has been with perl, which is reference counted, so very different in this regard
<metaperl>
ocaml must be the only langauge to separate list elements with a semicolon instead of a comma
* metaperl
wonders what drove that decision
<metaperl>
how can I get this to work:
<metaperl>
type trumpint = 1 .. 21;
<metaperl>
how wouold you add a test for b > a here
<metaperl>
let rec interval a b = if a = b then [b] else a::(interval (a+1) b) ;;
shawn has joined #ocaml
<pango>
let rec interval a b = if a > b then [] else a :: interval (a+1) b
<pango>
unless you'd prefer an exception ?
<pango>
metaperl: and to answer previous question, commas are used for tuples
<metaperl>
haskell uses them for both :_
<metaperl>
:)
<pango>
then it probably needs additionnal punctuation for lists of tuples
<metaperl>
pango: I was wondering if there were if .. elsif ... else
<pango>
# [1,2;3,4] ;;
<pango>
- : (int * int) list = [(1, 2); (3, 4)]
<pango>
yes, if ... else if ... else
<metaperl>
i'm a bit lost here:
<metaperl>
type t =
<metaperl>
C of int * bool
<metaperl>
| D of (int * bool) ;;
<metaperl>
the book says that you match the second one as a single parm
<metaperl>
the first as 2 parms
<metaperl>
well. there
<metaperl>
is nothing to be confused about... it's just very subtle... Perl has a lot of subtleties like that. Haskell doesnt. I tried haskell for a whole year. I'm still drowing in thatlanguage
<metaperl>
this ocaml thing slips on like a glove
<pango>
yes, constructor with two values vs. constructor of a tuple
<pango>
not very useful in ocaml, but probably used to make more sense in caml light, were constructors could by curryfied
<Smerdyakov>
SML has no such goofyness. :P
<metaperl>
Ocaml has caught the attention of corporate america. The sign of that is an O'Reilly book. not to mention the google ads for ocaml programmers in the corporate sector
<metaperl>
Ocaml may not be as principled as sml or haskell, but getting away from Perl is the way to go. Before I slip the other way and end up doing perl/php and commit suicide as a result
<metaperl>
it was a bitter 2-day struggle with a module that took me 1 hour to write in Perl ( due to Haskell's finickiness about I/O that got me thinking I had made a wrong choice)
<metaperl>
I/O changes the whole way a Haskell program looks
<metaperl>
but I/O is mostly what you do: read CGI input, connect to databases
<dylan>
I/O, I/O, it's off the bus I go...
<metaperl>
pulling things out of monads for 90% of a program gets to be tedious
<metaperl>
off the cliff
<metaperl>
lol
<dylan>
it's from Snobal Light and the Seven-bit bytes. ;)
<metaperl>
uhhhh oook
<pango>
english translation of the oreilly book is something like 5 years old
<metaperl>
the best mix of LAMP languages and static typing i've seen
<dylan>
Was merd ever more than a spec or collection of ideas?
<metaperl>
without the anal focus on I/O -- I don't know.... I think there's something to d/l at sf.net
<metaperl>
dylan: doyou program in dylan?
<dylan>
dude, don't mention I/O and anal at the same time.
<metaperl>
why?
<metaperl>
why not?
<dylan>
metaperl: it is my given name. I looked at Dylan a few months back and wasn't interested.
<dylan>
(and I've heard about the language most of my life as a programmer... and in fact Dylan is about the same age as me)
<dylan>
Mostly from Chris Double, who was.. Not a friend, but an associate in some online community.
<dylan>
Actually, it's sort of funny. People used to think Chris Double and I were the same person, because he programs in Dylan (or used to, circa 1999ish)
<metaperl>
this unison is a wonderful directory synchronization tool
<dylan>
and wyrd is a wonderful calendaring program.
<dylan>
and then there's ml-donkey, which is also very nice. :)
<metaperl>
pango: Nil is not of that type you listed
<dylan>
I never post code on the internet without testing it.
<metaperl>
only Acons and Bcons are
<pango>
# type ('a, 'b) list2 =
<pango>
Nil
<pango>
| Acons of 'a * ('a, 'b) list2
<pango>
| Bcons of 'b * ('a, 'b) list2 ;;
cyyoung has quit ["Leaving"]
ramkrsna has joined #ocaml
hikozaemon has joined #ocaml
love-pingoo has joined #ocaml
mrpingoo has quit [Read error: 110 (Connection timed out)]
ellisonch has joined #ocaml
<vincenz>
pango: why do you need this?
<vincenz>
pango: there is a better solution imho
slipstream-- has joined #ocaml
bohanlon has quit [Remote closed the connection]
<pango>
vincenz: just quoting the whole type from the page, to show that Nil is definitely a constructor of the type
<vincenz>
pango: there is a cleaner solution
<vincenz>
where you detangle the concept of list and the concept of multiple types
<vincenz>
type ('a, 'b) either = Left of 'a | Right of 'b
<vincenz>
(a', 'b) either list
<pango>
that's neither my problem, nor my solution
<pango>
but I see what you mean ;)
<vincenz>
it allows you to use all the std list functions
<pango>
which means that this o'reilly book example is a bit artificial
slipstream has quit [Connection timed out]
<vincenz>
hmm
love-pingoo has quit ["night"]
WhatTheDeuce has left #ocaml []
Schmurtz has quit [Read error: 104 (Connection reset by peer)]
Smerdyakov has quit ["Leaving"]
grirgz has quit [Read error: 110 (Connection timed out)]
slipstream-- has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
girodt has joined #ocaml
<girodt>
hi there. noob question. I have a function with a "let x = val in ..." at the beginning. then i have to iterate and maybe change the value of x. does it make sense to do "let x = new_val" inside my iteration ?
<mellum>
That's a pretty vague question... my crystal ball says the answer is "use recursion"
<girodt>
well ...
<girodt>
i guess again on this I have to use "ref" rather than "let"
<girodt>
damn, i'm reaaaally rusty on caml programming
<girodt>
gotta get those imperative languages outside of my mind.
<girodt>
thank you for getting me back in the good path.
<girodt>
bye
girodt has quit ["leaving"]
ski has quit [Read error: 104 (Connection reset by peer)]
gim_ has joined #ocaml
ski has joined #ocaml
girodt has joined #ocaml
<girodt>
hi again. another question : if I define several functions with the same signature but different code (thus different type inference of parameters), will there be a conflict ? I want to use a function "display 'a" to display various types, each of them having its own code. I wonder if it is possible to return the type of a var.
<pango>
there's no overloading, nor introspection
<pango>
what you're trying to do looks like dynamic typing stuff, ocaml is statically typed
<girodt>
okay. In fact I was wondering if it could do something like in prolog : the first appearing function fails with an error on type inference, so it goes to the second one which actually succeeds.
<pango>
the new declaration of the same identifier shadows the previous one
hikozaemon has quit ["Leaving..."]
<girodt>
alright. and if there is no introspection, I can't do a function which will find the type of data passed as argument and launch the right function to display it ...
<pango>
what about having a function for each type ?
<girodt>
that's what I am doing ... but I thought calling the same function name to display anything would be quite convenient in my code. That's not too bad, though ...
<mellum>
You can use a module for each type and call the function M.display.
<girodt>
interesting. I'm really novice on Ocaml and didn't have a look to modules yet.
Skal has joined #ocaml
girodt has quit ["leaving"]
<vincenz>
Anyone here good at both haskell and ocaml?
ski has quit [Read error: 110 (Connection timed out)]
ski has joined #ocaml
<dylan>
pango: actually, what girodt said is more like type classes in haskell.
<pango>
or OO
* vincenz
prefers type classes
<vincenz>
they were something I REALLY missed n ocaml
<dylan>
I miss I/O in haskell. ;)
<vincenz>
heh...
* vincenz
autoignores trolls
<dylan>
Eh. I'm writing a parsec parser in haskell right now.
<dylan>
so I'm obviously trolling it.
<vincenz>
dylan: need help
<vincenz>
I just finished one
* vincenz
is working on the compilation process now
<dylan>
vincenz: I'm far, far to bad at haskell to offer help. :)
<vincenz>
no I'm asking
<vincenz>
need any help?
<dylan>
Nah. What's the fun in that?
<vincenz>
btw, you know about hte IO monad?
<dylan>
Yep
<dylan>
I much prefer o'caml, when I want strong typing.
<vincenz>
I used to be a strong ocaml proponent
<vincenz>
but finally haskell won me over
<dylan>
But languages are a hobby.
<vincenz>
yep
<dylan>
I've written a large-ish project in ocaml, so it's got a lot of love from me. :)
* vincenz
ahs as well
<vincenz>
a memory access analysis tool
<dylan>
Cool.
<vincenz>
yep
<dylan>
I tried six times to learn ocaml. :-D
<vincenz>
going to present it at a conference soon :)
<dylan>
I only learned it by reading the standard library and writing a funtional-style CGI library (unused and unreleased). Then I made Yet Another Make Replacement. :)
Amorphous has quit ["arg... must... shutdown... computer burnin..."]
Amorphous has joined #ocaml
mikeX has joined #ocaml
pwned has joined #ocaml
<pwned>
yay, free book.
love-pingoo has joined #ocaml
mikeX has quit ["leaving"]
lde has quit [Read error: 104 (Connection reset by peer)]
haelix has joined #ocaml
Revision17 has quit [Read error: 110 (Connection timed out)]
Oobledegork has joined #ocaml
<Oobledegork>
salut!!!
<Oobledegork>
je cherche un tuto pour utiliser la fonction caml sys.time
<Oobledegork>
(je suis un debutant en premiere annee de prepa, on fait du caml en info)
<love-pingoo>
what do you need, more precisely ?
<Oobledegork>
ok
<Oobledegork>
im writing a program
<Oobledegork>
to reproduce conway's game of life
<Oobledegork>
or whatever its called in english
<love-pingoo>
that's how they say
<Oobledegork>
and i need to use the sys.time function to space out the displays of the matrix
<Oobledegork>
any idea how i use this function
<love-pingoo>
you just want your program to pause a bit ?
<Oobledegork>
well
<Oobledegork>
do you know the concept of the game?
<love-pingoo>
Oobledegork: linux or windows ?
<Oobledegork>
windows
<love-pingoo>
I do know that game
<Oobledegork>
ok
<Oobledegork>
so
<Oobledegork>
the first step is creating a matrix with random boxes filled
<love-pingoo>
I'd have said Unix.sleep
<Oobledegork>
then successive steps where the boxes evoluate
<love-pingoo>
but if you're on windows, I'm not sure you can use that
<Oobledegork>
i need to use the function to decide how fast the display changes
<Oobledegork>
like
<Oobledegork>
every 0.5 second, go to next step
<love-pingoo>
Oobledegork: Sys.time returns the time (number of seconds since 1 Jan 1970), but doesn't allow you to pause
<Oobledegork>
i know that
<Oobledegork>
not pausing
<Oobledegork>
but deciding the time between each cycle
<Oobledegork>
well, rather,
<Oobledegork>
between each generation
<love-pingoo>
you want to compute the time of computation ?
<Oobledegork>
????
<love-pingoo>
your cycle goes like that: next, display, pause, next, display, pause, ...
<Oobledegork>
more precisely, the program is supposed to look at each boxe and see how many of its neighbors are alive
<love-pingoo>
that I know
<Oobledegork>
then go to next step by acting on that
<Oobledegork>
the function is supposed to be used to decide how fast this is done
<love-pingoo>
ok so you want to get the time of the computation
<Oobledegork>
yes
<Oobledegork>
and be able to change it
<Oobledegork>
how is the function used
<Oobledegork>
?
<Oobledegork>
i want to say:
<Oobledegork>
creation of the matrix is time t = 0
<love-pingoo>
the problem is that Sys.time is not very precise (doesn't give info below the second)
<Oobledegork>
then each frame appears after 0.5 sec
<Oobledegork>
ok then 1 second
<Oobledegork>
doesn't matter
<love-pingoo>
the computation of the next matrix certainly doesn't take 1 sec
Smerdyakov has joined #ocaml
<Oobledegork>
what do you mean?
<Smerdyakov>
Anyone read ICFP reviews?
<Oobledegork>
the time i want to use is the time of the display not that of the computation
<love-pingoo>
Oobledegork: it should be below the second too..
<love-pingoo>
nevermind
<love-pingoo>
get Sys.time() before the display, and after, make the difference, you've got the duration of the display step
<love-pingoo>
to change it you must use some kind of sleep function
<Oobledegork>
ok
<Oobledegork>
thnx
<love-pingoo>
I know only Unix.sleep (or Unix.select to have better precision) or using special callbacks depending of the graphical toolkit you're using
<Oobledegork>
pfff
<Oobledegork>
like i said in french
<Oobledegork>
im a programming noob
<Oobledegork>
what you said makes no sense whatsoever
<Oobledegork>
^^
<Oobledegork>
sorry
<Oobledegork>
XD
<Oobledegork>
so
<love-pingoo>
let t0 = Sys.time () in display_next () ; let duration = Sys.time () -. t0 in ... you've got your duration ...
<Oobledegork>
ok
<love-pingoo>
this allows you to compute the duration of the step
<love-pingoo>
but doesn't allow you to change it
<love-pingoo>
Oobledegork: are you using Graphics ?
<Oobledegork>
can i set a specific sys.time to 0
<Oobledegork>
like
<Oobledegork>
say the time of the creation of the matrix is 0
<love-pingoo>
Oobledegork: no you can't, you do that yourself
<Oobledegork>
kk
<Oobledegork>
hmmm yes using graphics
<Oobledegork>
but later
<Oobledegork>
first just the core program
<Oobledegork>
then we'll use graphics functions to display the mess
<Oobledegork>
XD
<Oobledegork>
look ill sum it up:
<Oobledegork>
"protocol:
Smerdyakov has quit ["Leaving"]
<Oobledegork>
1. main program - initialize the matrix, and make a loop which displays the matrix and makes it evoluate. To space out the displays, you can use the caml sys.time function which gives you the time since starting up the program
<Oobledegork>
2. display - first make a text version of the matrix, then use graphics functions to display using colors, shapes, etc..."
<Oobledegork>
that's it
z|away has left #ocaml []
<love-pingoo>
Oobledegork: who told you to use Sys.time to space out the displays ?
<Oobledegork>
the print out for the exercice
<love-pingoo>
you can do a stupid thing: while Sys.time () < next_time do done... but that's a CPU-burner. Usually people have a sleep function to wait
<Oobledegork>
the one our teacher gave us
<Oobledegork>
ok
<Oobledegork>
CCP Grenoble
<Oobledegork>
Cycle Preparatoire Polytechnique de l'INPG
<Oobledegork>
a Grenoble...
<love-pingoo>
ok
<Oobledegork>
tu parles francais?
<love-pingoo>
bah oui :)
<Oobledegork>
bah fallait le dire
<love-pingoo>
ms ici c'est pas censé etre français
<Oobledegork>
bah
<Oobledegork>
caml c'est un langage francais non?
<Oobledegork>
invente a l'inria
<Oobledegork>
il me semble
<Oobledegork>
(pas sur)
<love-pingoo>
you should ask your teacher what was his idea about Sys.time, and if he was thinking of the while loop... there's probably better
<Oobledegork>
ok
<love-pingoo>
Oobledegork: yes but it is used outside france :)
<Oobledegork>
je viens de demander
<love-pingoo>
got to go now
<Oobledegork>
i know its used outside france
<love-pingoo>
good luck
<Oobledegork>
thnak you
<Oobledegork>
thank you
love-pingoo has quit ["Connection reset by by pear"]
<Oobledegork>
hahaha
<Oobledegork>
fuck
<Oobledegork>
she doesn't even understand what you told me
<Oobledegork>
ah
<Oobledegork>
you left...
Oobledegork has quit ["-=SysReset 2.53=-"]
Schmurtz has joined #ocaml
Smerdyakov has joined #ocaml
Revision17 has joined #ocaml
Fullmoon has joined #ocaml
<Fullmoon>
Anyone here is running ocaml on an Intel iMac?
<Fullmoon>
-i, can be a portable too, or a mini ;)
<Schmurtz>
I'm on a ppc mac, sorry
work_metaperl has joined #ocaml
<haelix>
Oh, just a question here:
<haelix>
why is 'exception' the only extensible sum type out there ?
notwoggle has joined #ocaml
<haelix>
I'd like to have
<haelix>
the possibility to define a generic function
<pango>
check polymorphic variants
<haelix>
('a -> dependent_of_a)
<haelix>
that can be specialized, according to the type of its arguments
<haelix>
but extensible, like with C++ template
<haelix>
pango: ?
<ketty>
haelix: you want function overloading?
<haelix>
ketty: yes
<ketty>
you can't have that in ocaml :)
<ketty>
but you can have extensible types thou..
<haelix>
ketty: well, I can fake it, provided there is a constructor type that enumerate all known overloads
<haelix>
So I supposed a first step would have to be able to extend this type
<ketty>
yes, that is true..
<ketty>
but how would you extend the function?
<haelix>
and the only extensible type there is around is exception
<pango>
I think there's also private row types... Not sure I understand how they work yet ;)