ayrnieu changed the topic of #ocaml to: OCaml 3.08.4 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/
dfgp has quit [Read error: 113 (No route to host)]
OtherAlfie has joined #ocaml
dfgp has joined #ocaml
dfgp has quit [Read error: 113 (No route to host)]
mlh_away has quit ["Chatzilla 0.9.68a [Firefox 1.0.6/20050716]"]
dfgp has joined #ocaml
mlh_away has joined #ocaml
drpingouin is now known as zzpingouin
spiffy has joined #ocaml
<spiffy> Im reading the free book, and it seems over my head. Does that mean I should just walk away with my pride?
<mlh_away> which free book?
<zzpingouin> I don't think so
mlh_away is now known as mlh_
<spiffy> the one called "a free book" in the topic
<mlh_> i don't think so . that's targeted at undergrads as course notes afaict
<spiffy> ooo
<spiffy> any suggestions on where to start then?
<spiffy> thanks
<mlh_> and see the links on that front page. especially jason hickey's intro
<spiffy> on the ocaml-tutorial page?
<mlh_> yeah
<spiffy> ah found it
<spiffy> link that is
<spiffy> appears the server is down
spiffy has quit []
pango_ has joined #ocaml
pango has quit [Read error: 145 (Connection timed out)]
OtherAlfie has quit ["*padpad*"]
vezenchio has joined #ocaml
dfgp_ has joined #ocaml
dfgp has quit [Read error: 113 (No route to host)]
Snark has joined #ocaml
zzpingouin has quit [Read error: 60 (Operation timed out)]
vodka-goo has joined #ocaml
ramkrsna has joined #ocaml
revision17_ has quit [Remote closed the connection]
Submarine has joined #ocaml
vodka-goo has quit ["buro"]
pango_ has quit [Remote closed the connection]
ramkrsna has quit [Read error: 113 (No route to host)]
pango has joined #ocaml
Chipster1 has joined #ocaml
Revision17 has joined #ocaml
ChipsterOne has joined #ocaml
ellisonch has quit ["Leaving"]
ChipsterOne has left #ocaml []
Revision17 has quit [Remote closed the connection]
ppsmimou has joined #ocaml
ChipsterOne has joined #ocaml
_fab has joined #ocaml
ChipsterOne has left #ocaml []
Skal has joined #ocaml
Submarine has left #ocaml []
Submarine has joined #ocaml
_fab has quit [Remote closed the connection]
dfgp has joined #ocaml
gim has quit ["x restart"]
gim has joined #ocaml
dfgp_ has quit [Read error: 113 (No route to host)]
Chipster1 has left #ocaml []
ChipsterOne has joined #ocaml
ChipsterOne has left #ocaml []
oracle1 has joined #ocaml
<oracle1> is it bad practice to have circular dependencies on files? A opens B and vice versa.
<Snark> no, it is pure fun
<mellum> Except Ocaml cannot handle it.
Submarine has quit ["Leaving"]
Submarine has joined #ocaml
Bigb[a]ng is now known as Bigbang
Bigbang is now known as Bigb[a]ng
ramkrsna has joined #ocaml
Submarine has quit ["Leaving"]
mlh_ has quit ["Chatzilla 0.9.68a [Firefox 1.0.6/20050716]"]
Chipster1 has joined #ocaml
ChipsterOne has joined #ocaml
Chipster1 has quit [Connection reset by peer]
ChipsterOne has quit [Client Quit]
Chipster1 has joined #ocaml
Bigb[a]ng is now known as Bigbang
ramkrsna has quit [Read error: 113 (No route to host)]
bernardo has joined #ocaml
Snark has quit [Remote closed the connection]
qknight has joined #ocaml
<qknight> hey
<qknight> compiling this two lines of code:
<qknight> # let rec fact n = if n=0 then 1 else n * fact(n-1);;
<qknight> val fact : int -> int = <fun>
<qknight> i get
<qknight> ocamlc -o hello hello.ml
<qknight> File "hello.ml", line 9, characters 0-1:
<qknight> Syntax error
<qknight> i don't understand what's wrong here because it's the example code of the wikipedia
<qknight> also other code snippets won't compile
<qknight> ;P
<bernardo> i'm a newbie, but i think you shouldn't include the second line
<ppsmimou> nor the #
<qknight> ha!
<qknight> bernardo, ppsmimou: removed # and the second line
<qknight> it's working now
<qknight> thanks
<bernardo> qknight: some examples are for the interactive environment, the # is the prompt
<qknight> bernardo: right
<qknight> bernardo: now i understand
hyakume- has joined #ocaml
qknight has quit ["have to got, thanks for help!"]
dfgp has quit [Read error: 104 (Connection reset by peer)]
dfgp has joined #ocaml
bernardo has quit ["Chatzilla 0.9.68.5 [Firefox 1.0.7/20050915]"]
bernardo has joined #ocaml
hyakume- has left #ocaml []
Snark has joined #ocaml
Chipster1 has left #ocaml []
brx_ has joined #ocaml
brx has quit [Read error: 110 (Connection timed out)]
bernardo_ has joined #ocaml
OtherAlfie has joined #ocaml
bernardo has quit [Connection timed out]
bernardo__ has joined #ocaml
bernardo__ is now known as bernardo
bernardo has quit [Client Quit]
bernardo has joined #ocaml
__DL__ has joined #ocaml
bernardo_ has quit [Read error: 110 (Connection timed out)]
vezenchio has quit [Read error: 104 (Connection reset by peer)]
vezenchio has joined #ocaml
Demitar has quit [Read error: 110 (Connection timed out)]
Demitar has joined #ocaml
bernardo_ has joined #ocaml
pango has quit ["Leaving"]
bernardo__ has joined #ocaml
ramkrsna has joined #ocaml
vincenz has joined #ocaml
bernardo has quit [Read error: 110 (Connection timed out)]
bernardo_ has quit [Read error: 110 (Connection timed out)]
pango has joined #ocaml
Chipster1 has joined #ocaml
dfgp_ has joined #ocaml
Chipster1 has left #ocaml []
Chipster1 has joined #ocaml
bernardo__ has quit [Read error: 110 (Connection timed out)]
ramkrsna has quit [Read error: 110 (Connection timed out)]
dfgp has quit [Read error: 113 (No route to host)]
bernardo has joined #ocaml
vezenchio has quit ["\o/ futari ga kitto deaeru you ni mahou o kakete - ryoute o sotto kasanete hora hohoemu kara \o/"]
__DL__ has quit ["Bye Bye"]
__DL__ has joined #ocaml
Chipster1 has left #ocaml []
mflux_ has quit [Remote closed the connection]
flux__ has joined #ocaml
vodka-goo has joined #ocaml
bernardo has left #ocaml []
ppsmimou has quit ["Leaving"]
Demitar has quit [Read error: 110 (Connection timed out)]
Demitar has joined #ocaml
Demitar has quit [Client Quit]
Demitar has joined #ocaml
qknight has joined #ocaml
<qknight> hey
<qknight> (* potenzfunktion a^b berechnen *)
<qknight> let rec potenz a b =
<qknight> if b=1 then a
<qknight> else a * potenz(a b-1);;
<qknight> error: This expression is not a function, it cannot be applied
<qknight> i can't understand why
<qknight> the recursive function i wrote with one parameter is working, it is the third line of the code (comment does not count)
<OtherAlfie> Try: else a * potenz a (b - 1);;
<qknight> *g*
<qknight> OtherAlfie: working
<qknight> OtherAlfie: i'm new to ocaml, so excuse my missing knowledge...
<qknight> however interesting that it's working _THIS_ way!?
<qknight> ;-)
Revision17 has joined #ocaml
<OtherAlfie> qknight: I'm new to ocaml, too, but I think it was trying to interpret (a b-1) as a function "a" acting on b-1
<flux__> qknight, yeah, that's they way you do function calls. note that you can write potenz 1 2 as (((potenz) 1) 2) too
<flux__> (of course you wouldn't want to, but that demonstrates the associativity)
<flux__> (and how foo (a b) would be completely opposed to that)
<qknight> thanks ;-)
Submarine has joined #ocaml
* Demitar hugs the "How to edit programs" section[1]. It perfectly describes how I use my emacs. :) [1] http://caml.inria.fr/pub/old_caml_site/FAQ/pgl-eng.html
Snark has quit ["Parti"]
__DL__ has quit [Remote closed the connection]
dfgp has joined #ocaml
dfgp_ has quit [Read error: 113 (No route to host)]
exa has joined #ocaml
Oatmeat|cs has joined #ocaml
Oatmeat|umn has quit [Read error: 110 (Connection timed out)]
dfgp has quit [Read error: 113 (No route to host)]
dfgp has joined #ocaml
<qknight> how could i implement the find_min element of a list without using the list: functions?
<qknight> will i have to use several functions?
<qknight> i've managed to implement
<qknight> min3 : int -> int -> int -> int
<qknight> which isn't that hard to do
<qknight> but i've problems with lists
<pango> think recursively... what's the minimum of a list with one element ? what's the minimum of a list of n+1 elements...
gonnet has joined #ocaml
gonnet has left #ocaml []
<qknight> in c++ it would be easy: value=vector[0]; for(int i=0; i < vector.size(); ++i) { if (vector[i] < value) value= vector[i]; }
<pango> lists aren't arrays
<qknight> ;P
<pango> and you have a strange definition of easy ;)
<qknight> pango: i've notices this already *gf*
<qknight> pango: right
<qknight> however
<qknight> now i shold do this with recursion?
<qknight> mmmh
<qknight> something like:
<pango> lists can be split in a head (first element) and a tail (all but first element)
<qknight> while running trough all elements set value or something
<pango> let's suppose you know how to compute the minimal element of the tail, can you compute the minimal element of the whole list ?
<qknight> i think i even fail in the first task
<pango> if l = h :: t, what's the relation between find_min l and find_min t ?
<qknight> don't know
<qknight> h is head
<pango> yes
<qknight> i've read that already
<qknight> but can't think even about a working solution:
<qknight> let rec minList own_list value temp =
<qknight> match own_list with
<qknight> | h :: t -> temp
<qknight> | [] -> invalid_arg "first";;
<qknight> that's what i have already but i don't understand what's happening to be true
<qknight> pango: don't want to steal your time anyway
<pango> you have a list, you know it's minimum; you add an element, what's the minimum of that list and this element together ?
<qknight> min(already_known_min, new_element)
<pango> exactly
<qknight> but the function has to find min [3;4;5;2;3;4;5;6;7;8;;34;2;24;2;525] for example
<pango> something like, find_min (h :: q) = min (h, find_min q)
<qknight> i just pass the list and it should return the smales element
<qknight> but it has to be recursive, right?
<pango> that definition is recursive, I just defined find_min by using find_min
<pango> but on a smaller list, so I know it will eventually compute something
<qknight> oh interesting
<qknight> so i have to pass h and q to the find_min
<pango> I just have to give the "base case" : when the list only has one element
<pango> (empty list is a special case, maybe it should be handled separately...)
<qknight> how do i jump trough the elements in that recursion?
<qknight> ignore empty list for now
<pango> let rec find_min l =
<pango> match l with
<pango> | [e] -> e
<pango> | h :: q -> let minq = find_min q in
<pango> if h < minq then h else minq ;;
<pango> it's not the best possible implementation, but it's the straightforward implementation of the mathematical definition
<pango> among things, ocaml complains because l = [] case is not handled
<qknight> thanks for the help
<qknight> hehe
<qknight> i've already fixed that
<qknight> | [] -> invalid_arg "first"
<pango> yes
* qknight is looking at the code, still trying to understand it
<Demitar> Interestingly pango is as patient as a textbook. :)
<qknight> defining a function in a function (which is then a value) is quite new for me
<qknight> *wonder* ;-)
<qknight> pango: yes, thakns for being so patient
<pango> np
* Demitar of course didn't understand a thing the first time he looked at ocaml, the second time around (after looking at lots of weird languages) I started understanding, and now I'm stuck. :)
<qknight> Demitar: hehe, cool
<qknight> Demitar: i've downloaded a nice gravitiy simulator in ocaml
<qknight> Demitar: very funny program
<qknight> pango: what does the | [e] -> e
<qknight> line do? erase a element from the list?
<pango> since you seem to know c++, I'd say match ... with is like a big switch() statement
<Demitar> qknight, perhaps it's easier to parse if you s/e/element/ s/h/head/ s/q/tail/ :)
<pango> it tests a value against a list of patterns 'til it finds one that matches
<pango> the first pattern, [e] is a list with just one element. If l is a list with one element, the pattern matches, and the action at the right of -> is evaluated
<pango> e is given the value of that first element automatically, so you just have to return it...
<qknight> oh on [e] -> e the last element is returned and the last minimum compare is performed
<qknight> right?
Bigbang is now known as Bigb[a]ng
<qknight> btw: is there a good book about that stuff? onlinebook
<pango> it reads as, the minimum of a list with just one element, is that element
<pango> whether find_min was called with just one element by you, or by find_min itself, doesn't matter : this is always true
<qknight> ok
<qknight> ;-)
<pango> a good introduction to functional programming, with examples in ocaml ? mmh... I'm not sure
<pango> I already knew about fp when I learned ocaml
<pango> btw, an interesting remark about what you said : the evaluation of the minimum of your list doesn't end when the last element of the list is reached
<pango> find_min called itself as many times as needed, and you have as many if ... then ... else tests that are waiting before any result will get back to you
<Demitar> Ah, the option type, how I tried to work around it in the beginning, now I wonder how I ever lived without it. :) (Looking through ocaml-tutorial.org)
khaladan has joined #ocaml
<pango> if I slightly modify find_min to be of type int -> int -> int, then run #trace find_min, then evaluate find_min [3;1;2], I get
<pango> # find_min [3;1;2] ;;
<pango> find_min <-- [3; 1; 2]
<pango> find_min <-- [1; 2]
<pango> find_min <-- [2]
<pango> find_min --> 2
<pango> find_min --> 1
<pango> find_min --> 1
<pango> - : int = 1
<pango> find_min first splits the list 'til it reaches the base case (list with one element), then recursive calls return one by one, in reverse order
<pango> (find_min [2] = 2, find_min [1;2] = 1, find_min [3;1;2] = 1)
<pango> if it's still unclear, it's probably worth trying to single step find_min evaluation by hand
_fab has joined #ocaml
mlh has joined #ocaml
Submarine has quit ["Leaving"]
<qknight> how can i compare two float values?
<qknight> if (b > a) then
<qknight> This expression has type float but is here used with type unit
<qknight> a, b are floats
<qknight> can i do casts?
<pango> if ( b > a ) then ... should work, > is polymorphic
<qknight> hmmm
<qknight> but not for me
<pango> # let a = 1.0 ;;
<pango> # let b = 2.0 ;;
<pango> # if (b > a) then b else a ;;
<pango> - : float = 2.
<pango> (parenthesis are not needed in that case btw)
<qknight> let mitternacht a b c = c*a;;
<qknight> print_float (mitternacht 2.1 3.3 50.1);;
<qknight> does not work
<qknight> This expression has type float but is here used with type int
<pango> # ( * ) ;;
<pango> - : int -> int -> int = <fun>
<pango> you need *. to compute the product of floats
<qknight> yor example is working
<qknight> strange
<qknight> let a = 1.0 ;;
<qknight> let b = 2.0 ;;
<qknight> let c = a*b;;
<qknight> is not working, too
<pango> let c = a *. b ;;
<qknight> oh
<qknight> why?
<qknight> that's strange
<qknight> don't think i've ever needed that in c/c++
<pango> it's needed for type inference
<pango> implicit conversions can also hide interesting bugs, so all conversions are explicit in ocaml
<pango> int_of_float, float_of_int, ...
<qknight> *argl*
<qknight> ok
<qknight> interesting
<qknight> aaaaaaaaaaahhhhhhh
<qknight> let mitternacht a b c =
<qknight> if ((b *. b) > (a *. c)) then
<qknight> c;;
<qknight> This expression has type float but is here used with type unit
<qknight> i think ocaml doesn't like me
<qknight> i'm doing exaclty what you wrote above
<qknight> and still it doesn't work
<pango> they're no instructions in ocaml, everything is a function
<pango> including if then else
<qknight> ?
<qknight> however it was working once
<qknight> ...
<qknight> not with float of course
<pango> if then else works like the ternary operator ? :
<pango> problem is, when ocaml tries to determine the type of its result
<qknight> pango: one question: did you help to invent ocaml?
<pango> you have one branch that's of type float (c), and the -missing- other of type unit ()
<pango> types don't match, so ocaml complains
<pango> no, I started learning ocaml 3 years ago
nicholas has joined #ocaml
<pango> # let mitternacht a b c =
<pango> if b *. b > a *. c then
<pango> c
<pango> else
<pango> 1.0 ;;
<pango> val mitternacht : float -> float -> float -> float = <fun>
<pango> that works, because both branches are of type float
<qknight> ok
<qknight> to much for tonight
<pango> if you don't use a "else" clause, the first branch must be of type unit
<qknight> oh
<qknight> ok
<qknight> good argument
<nicholas> Is there an ocaml function to remove a value from a list based on its index? For example, something like remove [3;4] 0 ->[4].
<pango> # let mitternacht a b c =
<pango> if b *. b > a *. c then
<pango> Printf.printf "%f" c ;;
<pango> nicholas: not in standard lib, but defining that function yourself is easy
Skal has quit [Remote closed the connection]
<nicholas> True, but I think it would be a nice thing to have in the standard library.
<pango> nicholas: it cannot be implemented efficiently, that's why it's not in standard lib
<pango> removing the nth element requires n steps
<qknight> oh
<pango> let rec deln n l =
<pango> match l with
<pango> | [] -> l
<pango> | h :: q -> if n = 0 then l else deln (n-1) q ;;
nicholas has quit [Remote closed the connection]
<pango> mmh wrong if n = 0 deln must return q
<qknight> pango: thanks for all your good hints
<pango> np... have fun learning functional programming ;)
<pango> btw ocaml also allows imperative programming
<pango> let find_min l =
<pango> let min = ref (List.hd l) in
<pango> List.iter (fun e -> if e < !min then min := e) l;
<pango> !min
<pango> that's an implementation of find_min closer to your c++ version
<pango> the goal is not know the two styles, and pick the one that matches better the problem at hand...
qknight has quit ["thanks, again... great master pango!"]
premchai21 has joined #ocaml