00:16
dfgp has quit [Read error: 113 (No route to host)]
00:25
OtherAlfie has joined #ocaml
00:26
dfgp has joined #ocaml
00:26
dfgp has quit [Read error: 113 (No route to host)]
00:41
mlh_away has quit ["Chatzilla 0.9.68a [Firefox 1.0.6/20050716]"]
00:54
dfgp has joined #ocaml
00:56
mlh_away has joined #ocaml
01:01
drpingouin is now known as zzpingouin
01:10
spiffy has joined #ocaml
01:21
<
spiffy >
Im reading the free book, and it seems over my head. Does that mean I should just walk away with my pride?
01:22
<
mlh_away >
which free book?
01:22
<
zzpingouin >
I don't think so
01:22
mlh_away is now known as mlh_
01:22
<
spiffy >
the one called "a free book" in the topic
01:23
<
mlh_ >
i don't think so . that's targeted at undergrads as course notes afaict
01:24
<
spiffy >
any suggestions on where to start then?
01:25
<
mlh_ >
and see the links on that front page. especially jason hickey's intro
01:27
<
spiffy >
on the ocaml-tutorial page?
01:30
<
spiffy >
ah found it
01:30
<
spiffy >
link that is
01:32
<
spiffy >
appears the server is down
02:50
pango_ has joined #ocaml
02:59
pango has quit [Read error: 145 (Connection timed out)]
03:12
OtherAlfie has quit ["*padpad*"]
04:27
vezenchio has joined #ocaml
05:00
dfgp_ has joined #ocaml
05:12
dfgp has quit [Read error: 113 (No route to host)]
05:35
Snark has joined #ocaml
06:02
zzpingouin has quit [Read error: 60 (Operation timed out)]
06:16
vodka-goo has joined #ocaml
06:20
ramkrsna has joined #ocaml
07:01
revision17_ has quit [Remote closed the connection]
07:07
Submarine has joined #ocaml
07:14
vodka-goo has quit ["buro"]
07:30
pango_ has quit [Remote closed the connection]
07:39
ramkrsna has quit [Read error: 113 (No route to host)]
07:40
pango has joined #ocaml
07:51
Chipster1 has joined #ocaml
08:10
Revision17 has joined #ocaml
08:18
ChipsterOne has joined #ocaml
08:18
ellisonch has quit ["Leaving"]
08:19
ChipsterOne has left #ocaml []
08:25
Revision17 has quit [Remote closed the connection]
08:33
ppsmimou has joined #ocaml
08:37
ChipsterOne has joined #ocaml
08:43
_fab has joined #ocaml
08:47
ChipsterOne has left #ocaml []
08:48
Skal has joined #ocaml
08:54
Submarine has left #ocaml []
08:54
Submarine has joined #ocaml
08:59
_fab has quit [Remote closed the connection]
09:00
dfgp has joined #ocaml
09:00
gim has quit ["x restart"]
09:09
gim has joined #ocaml
09:10
dfgp_ has quit [Read error: 113 (No route to host)]
09:13
Chipster1 has left #ocaml []
09:18
ChipsterOne has joined #ocaml
09:19
ChipsterOne has left #ocaml []
09:21
oracle1 has joined #ocaml
09:21
<
oracle1 >
is it bad practice to have circular dependencies on files? A opens B and vice versa.
09:26
<
Snark >
no, it is pure fun
09:39
<
mellum >
Except Ocaml cannot handle it.
09:39
Submarine has quit ["Leaving"]
09:58
Submarine has joined #ocaml
10:00
Bigb[a]ng is now known as Bigbang
10:09
Bigbang is now known as Bigb[a]ng
10:21
ramkrsna has joined #ocaml
10:45
Submarine has quit ["Leaving"]
10:53
mlh_ has quit ["Chatzilla 0.9.68a [Firefox 1.0.6/20050716]"]
10:55
Chipster1 has joined #ocaml
10:55
ChipsterOne has joined #ocaml
10:55
Chipster1 has quit [Connection reset by peer]
10:56
ChipsterOne has quit [Client Quit]
10:56
Chipster1 has joined #ocaml
10:58
Bigb[a]ng is now known as Bigbang
11:43
ramkrsna has quit [Read error: 113 (No route to host)]
11:55
bernardo has joined #ocaml
12:11
Snark has quit [Remote closed the connection]
12:16
qknight has joined #ocaml
12:17
<
qknight >
compiling this two lines of code:
12:17
<
qknight >
# let rec fact n = if n=0 then 1 else n * fact(n-1);;
12:17
<
qknight >
val fact : int -> int = <fun>
12:17
<
qknight >
ocamlc -o hello hello.ml
12:17
<
qknight >
File "hello.ml", line 9, characters 0-1:
12:17
<
qknight >
Syntax error
12:18
<
qknight >
i don't understand what's wrong here because it's the example code of the wikipedia
12:18
<
qknight >
also other code snippets won't compile
12:21
<
bernardo >
i'm a newbie, but i think you shouldn't include the second line
12:38
<
ppsmimou >
nor the #
12:41
<
qknight >
bernardo, ppsmimou: removed # and the second line
12:41
<
qknight >
it's working now
12:41
<
bernardo >
qknight: some examples are for the interactive environment, the # is the prompt
12:42
<
qknight >
bernardo: right
12:42
<
qknight >
bernardo: now i understand
12:52
hyakume- has joined #ocaml
12:54
qknight has quit ["have to got, thanks for help!"]
12:55
dfgp has quit [Read error: 104 (Connection reset by peer)]
13:00
dfgp has joined #ocaml
13:14
bernardo has quit ["Chatzilla 0.9.68.5 [Firefox 1.0.7/20050915]"]
13:22
bernardo has joined #ocaml
13:24
hyakume- has left #ocaml []
13:25
Snark has joined #ocaml
13:40
Chipster1 has left #ocaml []
14:05
brx_ has joined #ocaml
14:22
brx has quit [Read error: 110 (Connection timed out)]
14:25
bernardo_ has joined #ocaml
14:40
OtherAlfie has joined #ocaml
14:40
bernardo has quit [Connection timed out]
14:51
bernardo__ has joined #ocaml
14:51
bernardo__ is now known as bernardo
14:52
bernardo has quit [Client Quit]
14:53
bernardo has joined #ocaml
15:00
__DL__ has joined #ocaml
15:10
bernardo_ has quit [Read error: 110 (Connection timed out)]
15:27
vezenchio has quit [Read error: 104 (Connection reset by peer)]
15:28
vezenchio has joined #ocaml
15:56
Demitar has quit [Read error: 110 (Connection timed out)]
15:57
Demitar has joined #ocaml
16:33
bernardo_ has joined #ocaml
16:38
pango has quit ["Leaving"]
16:40
bernardo__ has joined #ocaml
16:46
ramkrsna has joined #ocaml
16:50
vincenz has joined #ocaml
16:51
bernardo has quit [Read error: 110 (Connection timed out)]
16:58
bernardo_ has quit [Read error: 110 (Connection timed out)]
17:01
pango has joined #ocaml
17:01
Chipster1 has joined #ocaml
17:01
dfgp_ has joined #ocaml
17:02
Chipster1 has left #ocaml []
17:02
Chipster1 has joined #ocaml
17:06
bernardo__ has quit [Read error: 110 (Connection timed out)]
17:14
ramkrsna has quit [Read error: 110 (Connection timed out)]
17:14
dfgp has quit [Read error: 113 (No route to host)]
17:30
bernardo has joined #ocaml
17:35
vezenchio has quit ["\o/ futari ga kitto deaeru you ni mahou o kakete - ryoute o sotto kasanete hora hohoemu kara \o/"]
17:50
__DL__ has quit ["Bye Bye"]
17:51
__DL__ has joined #ocaml
17:59
Chipster1 has left #ocaml []
18:06
mflux_ has quit [Remote closed the connection]
18:06
flux__ has joined #ocaml
18:13
vodka-goo has joined #ocaml
18:15
bernardo has left #ocaml []
18:28
ppsmimou has quit ["Leaving"]
18:31
Demitar has quit [Read error: 110 (Connection timed out)]
18:31
Demitar has joined #ocaml
18:32
Demitar has quit [Client Quit]
18:32
Demitar has joined #ocaml
18:40
qknight has joined #ocaml
18:40
<
qknight >
(* potenzfunktion a^b berechnen *)
18:40
<
qknight >
let rec potenz a b =
18:40
<
qknight >
if b=1 then a
18:40
<
qknight >
else a * potenz(a b-1);;
18:40
<
qknight >
error: This expression is not a function, it cannot be applied
18:40
<
qknight >
i can't understand why
18:41
<
qknight >
the recursive function i wrote with one parameter is working, it is the third line of the code (comment does not count)
18:45
<
OtherAlfie >
Try: else a * potenz a (b - 1);;
18:45
<
qknight >
OtherAlfie: working
18:46
<
qknight >
OtherAlfie: i'm new to ocaml, so excuse my missing knowledge...
18:46
<
qknight >
however interesting that it's working
_THIS_ way!?
18:54
Revision17 has joined #ocaml
18:56
<
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
18:57
<
flux__ >
qknight, yeah, that's they way you do function calls. note that you can write potenz 1 2 as (((potenz) 1) 2) too
18:58
<
flux__ >
(of course you wouldn't want to, but that demonstrates the associativity)
18:58
<
flux__ >
(and how foo (a b) would be completely opposed to that)
19:03
<
qknight >
thanks ;-)
19:21
Submarine has joined #ocaml
20:32
Snark has quit ["Parti"]
20:49
__DL__ has quit [Remote closed the connection]
21:02
dfgp has joined #ocaml
21:04
dfgp_ has quit [Read error: 113 (No route to host)]
21:08
exa has joined #ocaml
21:20
Oatmeat|cs has joined #ocaml
21:22
Oatmeat|umn has quit [Read error: 110 (Connection timed out)]
21:33
dfgp has quit [Read error: 113 (No route to host)]
21:46
dfgp has joined #ocaml
22:00
<
qknight >
how could i implement the find_min element of a list without using the list: functions?
22:00
<
qknight >
will i have to use several functions?
22:00
<
qknight >
i've managed to implement
22:01
<
qknight >
min3 : int -> int -> int -> int
22:01
<
qknight >
which isn't that hard to do
22:01
<
qknight >
but i've problems with lists
22:03
<
pango >
think recursively... what's the minimum of a list with one element ? what's the minimum of a list of n+1 elements...
22:04
gonnet has joined #ocaml
22:13
gonnet has left #ocaml []
22:15
<
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]; }
22:15
<
pango >
lists aren't arrays
22:15
<
pango >
and you have a strange definition of easy ;)
22:15
<
qknight >
pango: i've notices this already
*gf*
22:15
<
qknight >
pango: right
22:16
<
qknight >
now i shold do this with recursion?
22:16
<
qknight >
something like:
22:16
<
pango >
lists can be split in a head (first element) and a tail (all but first element)
22:17
<
qknight >
while running trough all elements set value or something
22:17
<
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 ?
22:17
<
qknight >
i think i even fail in the first task
22:18
<
pango >
if l = h :: t, what's the relation between find_min l and find_min t ?
22:18
<
qknight >
don't know
22:19
<
qknight >
h is head
22:19
<
qknight >
i've read that already
22:19
<
qknight >
but can't think even about a working solution:
22:19
<
qknight >
let rec minList own_list value temp =
22:19
<
qknight >
match own_list with
22:19
<
qknight >
| h :: t -> temp
22:19
<
qknight >
| [] -> invalid_arg "first";;
22:20
<
qknight >
that's what i have already but i don't understand what's happening to be true
22:20
<
qknight >
pango: don't want to steal your time anyway
22:20
<
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 ?
22:21
<
qknight >
min(already_known_min, new_element)
22:22
<
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
22:22
<
pango >
something like, find_min (h :: q) = min (h, find_min q)
22:22
<
qknight >
i just pass the list and it should return the smales element
22:22
<
qknight >
but it has to be recursive, right?
22:23
<
pango >
that definition is recursive, I just defined find_min by using find_min
22:23
<
pango >
but on a smaller list, so I know it will eventually compute something
22:23
<
qknight >
oh interesting
22:23
<
qknight >
so i have to pass h and q to the find_min
22:23
<
pango >
I just have to give the "base case" : when the list only has one element
22:24
<
pango >
(empty list is a special case, maybe it should be handled separately...)
22:24
<
qknight >
how do i jump trough the elements in that recursion?
22:24
<
qknight >
ignore empty list for now
22:26
<
pango >
let rec find_min l =
22:26
<
pango >
match l with
22:26
<
pango >
| h :: q -> let minq = find_min q in
22:26
<
pango >
if h < minq then h else minq ;;
22:27
<
pango >
it's not the best possible implementation, but it's the straightforward implementation of the mathematical definition
22:29
<
pango >
among things, ocaml complains because l = [] case is not handled
22:29
<
qknight >
thanks for the help
22:30
<
qknight >
i've already fixed that
22:30
<
qknight >
| [] -> invalid_arg "first"
22:30
* qknight
is looking at the code, still trying to understand it
22:32
<
Demitar >
Interestingly pango is as patient as a textbook. :)
22:32
<
qknight >
defining a function in a function (which is then a value) is quite new for me
22:32
<
qknight >
*wonder* ;-)
22:33
<
qknight >
pango: yes, thakns for being so patient
22:33
* 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. :)
22:34
<
qknight >
Demitar: hehe, cool
22:34
<
qknight >
Demitar: i've downloaded a nice gravitiy simulator in ocaml
22:34
<
qknight >
Demitar: very funny program
22:35
<
qknight >
pango: what does the | [e] -> e
22:35
<
qknight >
line do? erase a element from the list?
22:35
<
pango >
since you seem to know c++, I'd say match ... with is like a big switch() statement
22:36
<
Demitar >
qknight, perhaps it's easier to parse if you s/e/element/ s/h/head/ s/q/tail/ :)
22:37
<
pango >
it tests a value against a list of patterns 'til it finds one that matches
22:38
<
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
22:39
<
pango >
e is given the value of that first element automatically, so you just have to return it...
22:40
<
qknight >
oh on [e] -> e the last element is returned and the last minimum compare is performed
22:40
Bigbang is now known as Bigb[a]ng
22:40
<
qknight >
btw: is there a good book about that stuff? onlinebook
22:40
<
pango >
it reads as, the minimum of a list with just one element, is that element
22:41
<
pango >
whether find_min was called with just one element by you, or by find_min itself, doesn't matter : this is always true
22:48
<
pango >
a good introduction to functional programming, with examples in ocaml ? mmh... I'm not sure
22:49
<
pango >
I already knew about fp when I learned ocaml
22:56
<
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
22:57
<
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
22:58
<
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)
23:01
khaladan has joined #ocaml
23:02
<
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
23:02
<
pango >
# find_min [3;1;2] ;;
23:02
<
pango >
find_min <-- [3; 1; 2]
23:02
<
pango >
find_min <-- [1; 2]
23:02
<
pango >
find_min <-- [2]
23:02
<
pango >
find_min --> 2
23:02
<
pango >
find_min --> 1
23:02
<
pango >
find_min --> 1
23:02
<
pango >
- : int = 1
23:05
<
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
23:05
<
pango >
(find_min [2] = 2, find_min [1;2] = 1, find_min [3;1;2] = 1)
23:12
<
pango >
if it's still unclear, it's probably worth trying to single step find_min evaluation by hand
23:17
_fab has joined #ocaml
23:26
mlh has joined #ocaml
23:26
Submarine has quit ["Leaving"]
23:31
<
qknight >
how can i compare two float values?
23:32
<
qknight >
if (b > a) then
23:32
<
qknight >
This expression has type float but is here used with type unit
23:32
<
qknight >
a, b are floats
23:32
<
qknight >
can i do casts?
23:33
<
pango >
if ( b > a ) then ... should work, > is polymorphic
23:33
<
qknight >
but not for me
23:34
<
pango >
# let a = 1.0 ;;
23:34
<
pango >
# let b = 2.0 ;;
23:34
<
pango >
# if (b > a) then b else a ;;
23:34
<
pango >
- : float = 2.
23:35
<
pango >
(parenthesis are not needed in that case btw)
23:35
<
qknight >
let mitternacht a b c = c*a;;
23:35
<
qknight >
print_float (mitternacht 2.1 3.3 50.1);;
23:35
<
qknight >
does not work
23:35
<
qknight >
This expression has type float but is here used with type int
23:35
<
pango >
- : int -> int -> int = <fun>
23:35
<
pango >
you need *. to compute the product of floats
23:37
<
qknight >
yor example is working
23:37
<
qknight >
let a = 1.0 ;;
23:37
<
qknight >
let b = 2.0 ;;
23:37
<
qknight >
let c = a*b;;
23:38
<
qknight >
is not working, too
23:38
<
pango >
let c = a *. b ;;
23:38
<
qknight >
that's strange
23:38
<
qknight >
don't think i've ever needed that in c/c++
23:38
<
pango >
it's needed for type inference
23:39
<
pango >
implicit conversions can also hide interesting bugs, so all conversions are explicit in ocaml
23:40
<
pango >
int_of_float, float_of_int, ...
23:40
<
qknight >
interesting
23:42
<
qknight >
aaaaaaaaaaahhhhhhh
23:42
<
qknight >
let mitternacht a b c =
23:42
<
qknight >
if ((b *. b) > (a *. c)) then
23:42
<
qknight >
This expression has type float but is here used with type unit
23:43
<
qknight >
i think ocaml doesn't like me
23:43
<
qknight >
i'm doing exaclty what you wrote above
23:43
<
qknight >
and still it doesn't work
23:43
<
pango >
they're no instructions in ocaml, everything is a function
23:43
<
pango >
including if then else
23:44
<
qknight >
however it was working once
23:44
<
qknight >
not with float of course
23:45
<
pango >
if then else works like the ternary operator ? :
23:45
<
pango >
problem is, when ocaml tries to determine the type of its result
23:45
<
qknight >
pango: one question: did you help to invent ocaml?
23:46
<
pango >
you have one branch that's of type float (c), and the -missing- other of type unit ()
23:46
<
pango >
types don't match, so ocaml complains
23:46
<
pango >
no, I started learning ocaml 3 years ago
23:46
nicholas has joined #ocaml
23:47
<
pango >
# let mitternacht a b c =
23:47
<
pango >
if b *. b > a *. c then
23:47
<
pango >
val mitternacht : float -> float -> float -> float = <fun>
23:47
<
pango >
that works, because both branches are of type float
23:48
<
qknight >
to much for tonight
23:48
<
pango >
if you don't use a "else" clause, the first branch must be of type unit
23:48
<
qknight >
good argument
23:49
<
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].
23:49
<
pango >
# let mitternacht a b c =
23:49
<
pango >
if b *. b > a *. c then
23:49
<
pango >
Printf.printf "%f" c ;;
23:50
<
pango >
nicholas: not in standard lib, but defining that function yourself is easy
23:51
Skal has quit [Remote closed the connection]
23:51
<
nicholas >
True, but I think it would be a nice thing to have in the standard library.
23:51
<
pango >
nicholas: it cannot be implemented efficiently, that's why it's not in standard lib
23:52
<
pango >
removing the nth element requires n steps
23:53
<
pango >
let rec deln n l =
23:53
<
pango >
match l with
23:53
<
pango >
| h :: q -> if n = 0 then l else deln (n-1) q ;;
23:54
nicholas has quit [Remote closed the connection]
23:54
<
pango >
mmh wrong if n = 0 deln must return q
23:55
<
qknight >
pango: thanks for all your good hints
23:56
<
pango >
np... have fun learning functional programming ;)
23:56
<
pango >
btw ocaml also allows imperative programming
23:56
<
pango >
let find_min l =
23:56
<
pango >
let min = ref (List.hd l) in
23:56
<
pango >
List.iter (fun e -> if e < !min then min := e) l;
23:57
<
pango >
that's an implementation of find_min closer to your c++ version
23:58
<
pango >
the goal is not know the two styles, and pick the one that matches better the problem at hand...
23:58
qknight has quit ["thanks, again... great master pango!"]
23:58
premchai21 has joined #ocaml