<cleverdra>
Curious that they only have non-human primates.
<pattern>
they only hire the best
The-Fixer has quit ["Goodbye"]
The-Fixer has joined #ocaml
Nutssh has quit [Read error: 110 (Connection timed out)]
cleverdra has quit ["client"]
cleverdra has joined #ocaml
tomasso has quit [Read error: 110 (Connection timed out)]
tomasso has joined #ocaml
Nutssh has joined #ocaml
Kinners has joined #ocaml
wazze has joined #ocaml
Swynn_wk has quit ["Leaving"]
Kinners has quit [Remote closed the connection]
Kinners has joined #ocaml
tomasso has quit ["Leaving"]
Kinners has left #ocaml []
cleverdra has quit ["it seems that I hate xchat."]
cleverdra has joined #ocaml
Iorek has quit []
Nutssh has quit ["Client exiting"]
The-Fixer has quit ["Goodbye"]
The-Fixer has joined #ocaml
Kinners has joined #ocaml
det has quit [Read error: 104 (Connection reset by peer)]
det has joined #ocaml
gim_ has joined #ocaml
mattam has quit [zelazny.freenode.net irc.freenode.net]
mattam has joined #ocaml
The-Fixer has quit ["Goodbye"]
Swynndla has joined #ocaml
gim_ has quit [zelazny.freenode.net irc.freenode.net]
rox has quit [zelazny.freenode.net irc.freenode.net]
smkl has quit [zelazny.freenode.net irc.freenode.net]
gim_ has joined #ocaml
rox has joined #ocaml
smkl has joined #ocaml
Kinners has left #ocaml []
det has quit [Read error: 110 (Connection timed out)]
The-Fixer has joined #ocaml
<pattern>
using map, foldl, and/or foldr write a function that turns a list of integers [a1;a2;...;an] into the alternating sum a1 - a2 + a3 - a4 + ...
<pattern>
can anyone give me a hint regarding this problem?
<pattern>
i don't want the solution (yet)... but i'm having a hard time with it
<pattern>
oh, wait, maybe i should pattern match
<pattern>
no, i still can't think of a solution :(
<pattern>
ah.. i have another idea...
<pattern>
no... i just don't know how to use map, foldl or foldr to apply to alternate elements of a list
<pattern>
it seems like i have to use both elements with foldl and foldr, and every element with map
<pattern>
it seems impossible
<Swynndla>
pattern, I don't know the solution, but I would look in the direction of using foldl .... and that part of the function should use the fact that: -1 = -1, -1*-1 = 1, -1*-1*-1 = -1 etc etc
<pattern>
hmmm
<Swynndla>
or ... (-1) raised to the even power is 1, and raised to the odd power is -1
<Swynndla>
(not sure though)
<pattern>
well, it's given me some ideas
<pattern>
thanks, swynndla
<Swynndla>
:P
<Swynndla>
actually pattern, I think I can do it with pattern matching
<pattern>
i thought of pattern matching to get two lists, the first minus it's first element
<pattern>
but you still need alternate elements, and foldl/r can't do that
<Banana>
hello.
<pattern>
hi
<Swynndla>
pattern ... I did it with pattern matching just now
<pattern>
ok, don't tell me how
<Swynndla>
ok
<pattern>
i thought of a way too
<Swynndla>
4 lines
<pattern>
let me try it
<Swynndla>
ok
<Banana>
1 line with fold_left.
<Swynndla>
lol
<pattern>
:P
<Swynndla>
let me try it Banana
<Banana>
Swynndla: you gave the good point, key is "involution of - opérator" (whooo).
<Swynndla>
for fold_left ... yup :)
<Banana>
dammit, there is a bug !!!
<Banana>
in one line !!!
<Swynndla>
oh ... I'm still trying to work it out
<pattern>
i think i figured it out
<pattern>
or stumbled in to it
<pattern>
let me test it with a few more values...
<Swynndla>
pattern, the pattern match way?
<pattern>
no
<pattern>
one line
<Banana>
pattern: hint try with odd and even lenght list.
The-Fixer has quit ["Goodbye"]
<pattern>
i did try it with odd and even length lists before, but failed (that was my try with pattern matching)
<pattern>
and i see now that i didn't have the solution after all... just happened to coincide with my first list's alternate sum
<pattern>
:(
<pattern>
ok, i did it with pattern matching
<pattern>
let rec altsum l = match l with
<pattern>
[] -> 0
<pattern>
| x::[] -> x
<pattern>
| x::y::ys -> x - y + altsum ys
<Swynndla>
yes!
<pattern>
:)
<Banana>
erf I got -result depending on parity of length.
<Banana>
ha ha ha.
<pattern>
i also tried stuff like: let altsum l = foldl ( - ) ( foldr ( - ) 0 l ) l
<pattern>
with different operator combinations
<pattern>
clearly i need to brush up on my math to see that that obiviously would lead nowhere
<Swynndla>
this is close: let sumalt_list = List.fold_left (fun a i -> (a + i)*(-1)) 0
<Swynndla>
but unfortunately it does: -a1 + a2 - a3 ...
<pattern>
but wait
<pattern>
my solution with pattern matching doesn't use foldl/foldr/map at all
<pattern>
and the problem requires it
<pattern>
hmmm
<Swynndla>
you solution was the same as my 1st one ... and it works
<Swynndla>
but this one liner is harder
<pattern>
yeah, but i have to use map/foldl/foldr
<Swynndla>
all of them or either?
<pattern>
any one or a combination
<pattern>
so banana, did you actually figure it out or is your code buggy?
<Banana>
buggy.
<pattern>
wel, if you guys can't figure it out i have no chance
<Swynndla>
no I'm new to ocaml
<pattern>
still, i suck at math
<Banana>
ok I think I got it.
<pattern>
and this looks like more of a math problem than an ocaml problem
<Banana>
no, there is a hack.
<Banana>
you want a hint ?
<pattern>
1;2;3;4;5 should give you -3
<pattern>
yeah
<Banana>
arf
<pattern>
oops
<pattern>
1;2;3;5
<pattern>
should give you -3
<Banana>
it seems to work.
<pattern>
cool
<Banana>
but I don't know if allowed.
<pattern>
hmmm
<Banana>
i use an extra function appart from fold_left.
<Banana>
the function is fst.
<pattern>
ok, that's an interesting hint
<Banana>
breakfast time.
<pattern>
hey, post your solution to a code pasting site
<pattern>
kinners, using map, foldl, and/or foldr write a function that turns a list of integers [a1;a2;...;an] into the alternating sum a1 - a2 + a3 - a4 + ...
<pattern>
banana, but it works!
<Banana>
[1;2;4] should give you 3 ? 1-2+4
<pattern>
well, i only tried even number of elements
Riastrad1 has joined #ocaml
<pattern>
it works for even numbers :)
<Banana>
^_^ good pattern
<pattern>
and that's a hell of a lot better than i did before
<Swynndla>
hehe
<Banana>
but i got to appologies. my hint might have lured you.
<pattern>
unfortunately, i did not arrive at this solution through analysis
<Banana>
fst is a predefined function.
<pattern>
i just tried lots of different combinations of operators with the folds
<pattern>
ahhh
<Banana>
it is in Pervasives module.
<pattern>
i see
<Banana>
fst (a,b) -> a
<pattern>
oh
<Banana>
yes
<pattern>
well, that should work the same
<Banana>
not realy.
Riastradh has quit [Read error: 110 (Connection timed out)]
<pattern>
i only use the first element
<pattern>
doesn't matter if it's a list or a tuple
<Banana>
and foldr is an alias for List.fold_right ?
<pattern>
an equivalent function
<Banana>
ok.
<pattern>
let rec foldr f y l = match l with
<pattern>
[] -> y
<pattern>
| x::xs -> f x ( foldr f y xs )
<pattern>
not efficient to keep passing f back to foldr, i know
Demitar has joined #ocaml
<pattern>
well, i'm going to peek at your solution now, banana
<pattern>
wow, very different
<pattern>
yours was more along the lines of swynndla's
<Banana>
yeap
<Banana>
the trick is that when you use -1*-1 = 1 you have to 'start' with -1
<Banana>
if you see what i mean.
<pattern>
not yet... i'm still trying to make sense of it
<Banana>
ok
<Banana>
if you have list [a1 ; a2; a3 ...]
<Banana>
you use foldl and a initial counter at 0 and it does :
Nutssh has joined #ocaml
<Banana>
((((0+a1)*-1)+a2)*-1)+a3)*-1 ...
<pattern>
wait
<pattern>
you have (fun (cpt,sign) y) as the function passed to foldl
<Banana>
yes
<Banana>
y is what is in the list.
<Banana>
(cpt,sign) my accumulator.
<pattern>
and in the first case, it takes an and y, where y is (0,1), right?
<pattern>
swynndla, looks to me like "a::s = l" is the source of that warning
<Banana>
yes.
<pattern>
but that's from just a cursury look... i haven't tried to compile it
<Banana>
it is.
<pattern>
so a list can always be empty, right?
<Swynndla>
pattern, yea that's the problem it highlights
<Banana>
if l = [] then your program fail with exception unmatched Pattern or something.
<Swynndla>
oh
<Banana>
the fact is that even it you test it with if l=[] ... then ...
<Banana>
the compiler has now to know at compile time that your list will alway be non empty here.
<Banana>
so it warns you.
<Swynndla>
but I've got ' if l = [] then []' in there
<pattern>
i guess the "a::s = l" pattern match doesn't know that
<Swynndla>
right
<Banana>
Swynndla: the compiler can't look around in your code and make static analysis like this.
<Swynndla>
gotcha
<pattern>
banana, with your "List.fold_left (fun (cpt,sign) y -> (sign*y+cpt,-sign))", in the first case it would take a1 and a tuple for y, right?
<Swynndla>
well with the top one (with no warning) ... the last line of it ... | _ -> [] @ bt100list t;; ... is that the leftover for match l with or match b with??
<pattern>
swynndla, i always like to use "begin" and "end" in these cases to make it clear
<Swynndla>
oic
<pattern>
or parenthesis, which ammount to the same thing, i am told
<Swynndla>
ok
<Swynndla>
pattern .. to your question, I think that y is not a tuple ...
<Swynndla>
but y is each element of the list ... one at a time
<Swynndla>
I think I understand that bit you see ....
Kinners has quit [Remote closed the connection]
Kinners has joined #ocaml
<pattern>
ok, if y is not a tuple then how come (0,1) is passed as the accumulator?
<Swynndla>
but I don't understand what the 'fst' is doing
<pattern>
fst(a,b) = a
<Swynndla>
first?
<Banana>
ha ha ha good people.
<Banana>
yes.
<Banana>
there is snd to.
<Swynndla>
ahhh
<Banana>
i made a trace function :
<Kinners>
my resultant function ended up basically the same as Banana's :)
<Banana>
^_^
<pattern>
you rock
<Banana>
you have to keep more than the res philosopy.
<pattern>
mine only works for even number of elements
<Banana>
i think you see well what altern does once you look at the result.
<pattern>
i tried your previous one
<Banana>
ok.
<pattern>
i understand it much better now that i have the arguments in the correct order
<Banana>
the point is that you need to keep track of the sign you used the previous** time (while folding the list). which I think you can't do (?) by just keeping the result.
<pattern>
cool solution
<pattern>
i was trying to come up with something like that, but couldn't think of anything
<pattern>
the best i could do was my solution, which only works for lists of even numbers of elements
<pattern>
and i'm not even sure why it works at all
<Swynndla>
yes, your solution is cool Banana
<Banana>
thx.
<Banana>
pattern: try the 'a -> 'b function. the result is very deep, because it's the essence of ocaml type. (imho).
<pattern>
yeah, it looks hard
<pattern>
i want to figure out my own function first, though
<Banana>
ok.
<pattern>
i don't know why it works
<Banana>
which functions ?
<Kinners>
pattern: is it your function using foldr that you don't understand?
<pattern>
and how is it different from a plain: foldr ( - ) 0 l
<Kinners>
pattern: foldr traverses the list in reverse (all the previous elements of the list are pushed on the stack)
<pattern>
yes, i understand foldr
<pattern>
i just don't understand how my function can work and foldr ( - ) 0 l fails
<pattern>
since they seem to do the same thing
<Swynndla>
Banana, where is your 'a -> 'b function?
<pattern>
swynndla, it's a puzzle
<Swynndla>
:P
<Banana>
Swynndla: this is it "try to write a function which as type 'a -> 'b"
<Swynndla>
i give up!!
<pattern>
don't say the answer on the channel, please
<Swynndla>
:)
<Banana>
ok.
<pattern>
oh, wait "foldr ( - ) 0 l" did work
<pattern>
for an even list
<pattern>
i could swear i tried that before
<pattern>
well, that's a lot simpler
<pattern>
ok, now on to 'a -> 'b
<pattern>
btw, is this a trick question, banana? do i have to use Object.magic or something like it?
<Banana>
non.
<Banana>
you don't
<pattern>
ok
<Banana>
do you think Obj.magic is the essence of ocaml ?
<pattern>
of course not
<Banana>
arf young these days ^_^
<pattern>
but neither is changing an object from one type to another
<pattern>
except by using int_to_string ;)
<Swynndla>
what is arf?
<pattern>
an exclamation
<Banana>
yes.
<pattern>
like wow! or doh!
<Banana>
more like sighhh.
<Banana>
;)
<pattern>
or meh
<Swynndla>
oh ... like arhggg
cleverdra has quit [Read error: 110 (Connection timed out)]
<pattern>
yeah
<Banana>
Swynndla: not quite. there is no anger in arf.
<Swynndla>
oh ... like ... gosh?
<Swynndla>
or ... meh seems to fit sighhhh
<Swynndla>
as pattern pointed out
<Banana>
12:07 < Banana> more like sighhh.
<pattern>
pffft
<Swynndla>
whoops
<Swynndla>
:P~~~
<Banana>
^_^
<Swynndla>
I'm getting tired ... have to go to bed - it's late here (for me)
<pattern>
night, swynndla
<Banana>
'night.
<Swynndla>
night
<pattern>
banana, do you have a hint?
<Swynndla>
and thx for your help you two
Swynndla has quit ["Leaving"]
<Banana>
yes.
<Banana>
in Ocaml, all function that returns a value is well typed.
<pattern>
hmm
<Banana>
and obviously 'a -> 'b could break type safety.
<Banana>
(a cast operator).
<pattern>
yes
<pattern>
but string_of_int does it, except it's not general enough to be 'a -> 'b
<Banana>
that's the point.
<pattern>
ok
<pattern>
so with string_of_int you know what types go in and what types come out
<pattern>
but this cast function is indeterminate in what it's going to return, except that it'll be a type
<Banana>
yes.
<pattern>
and possibly a different type than what came in
<Banana>
yes.
<Banana>
but if i may say something...
<pattern>
please
<Banana>
you stated that "what it's going to
<Banana>
return"
<pattern>
evalute to
<Banana>
hum...
<Banana>
this might be the point.
<pattern>
hmm
<pattern>
# let (foo:'a -> 'b) = function a -> a ;;
<pattern>
val foo : 'a -> 'a = <fun>
<pattern>
that's the closest i've been able to get
<Banana>
not bad.
<pattern>
:)
<Banana>
there are 2 different solutions.
<Banana>
i gotta go.
<pattern>
i don't know... i am at a dead end
<pattern>
ok, what's the solution?
<Banana>
let rec f x = f x
<Banana>
or let f x = failwith "foo"
<pattern>
oh, i thought about trying a recursive function
<pattern>
forgot to try it
<pattern>
interesting
<pattern>
thanks, banana
<Banana>
nothing.
<Banana>
(btw this function does not return (infinite loop) and that's why it's type safe).
<pattern>
ah
<pattern>
neat
<pattern>
so handling exceptions can really screw up your type safety, huh?
<Banana>
no.
<Banana>
because the second function doesn't return either.
<pattern>
isn't that what that filwith function evaluating to 'b means?
<pattern>
can't you handle that exception and return something?
<Banana>
then the type will be constraint.
<Banana>
by the value you return.
<pattern>
ah
<pattern>
so it evaluates to 'b only if you don't handle the exception?
<Banana>
yes
<pattern>
i see
<pattern>
so in neither case was 'b a real type
<Banana>
but not handling exception meens program termination so it's safe.
<Banana>
it is a real type.
<pattern>
it's meaningless
<pattern>
just a placeholder
<Banana>
but there is no value that fit in here.
<Banana>
yes.
<pattern>
tricky
<pattern>
very interesting, though
<pattern>
thanks for showing me this
<Banana>
ok i'm off.
<Banana>
see you.
<pattern>
see you
Banana is now known as Banana[AFK]
Guillaumito has joined #ocaml
<Guillaumito>
hi
<Guillaumito>
can I ask a question in french or should I ask it in english ?
<pattern>
i only understand english (and i'm a beginner anyway)... but you can ask it in either language... you could always ask it in both languages, too :)
<Guillaumito>
yes, but it's hard for me to speak english
<Guillaumito>
but I think I find the answer to my question
<pattern>
then try french... i've seen french speakers come here
<Guillaumito>
ok
<Guillaumito>
est ce que quelqu'un ici a deja utilise (et sait comment fonctionnent) les ensembles de ocaml ?
<Guillaumito>
tous en train de manger...
Nutssh has quit ["Client exiting"]
<mellum>
ensembles?
<Guillaumito>
Set
<pattern>
modules?
<Guillaumito>
yes
<pattern>
i'm a beginner... i don't know much about modules, unfortunately
<mellum>
I tend to use Hashtbl :)
<Guillaumito>
never tried Hashtbl
_JusSx_ has joined #ocaml
<_JusSx_>
ok
<_JusSx_>
yeah
<Kinners>
Guillaumito: like, module S = Set.Make(String) ?
<Guillaumito>
yes
<Guillaumito>
in fact, this is what i'm using
<Guillaumito>
set over ordered string
<Guillaumito>
and I was using (by mistake) the '=' operator :
<Guillaumito>
if set1 = set2 then...
<Guillaumito>
instead of "if Set.compare set1 set2 then..."
Kinners has quit [Remote closed the connection]
<Guillaumito>
...
Kinners has joined #ocaml
_JusSx_ has quit ["BitchX: the Cadillac of all clients"]
<pattern>
continue, guillaumito
<pattern>
ask your question
<Guillaumito>
mmm, ok
<Guillaumito>
the '=' operator works only if the two sets are build the same way
<Guillaumito>
ie :
<Guillaumito>
set1 = "chaine1"
<Guillaumito>
set1.add "chaine2"
<Guillaumito>
set2 = "chaine1"
<Guillaumito>
set2.add "chaine2"
<Guillaumito>
in this case set1 = set2
<Guillaumito>
but if you do set2 = "chaine2" then set2.add "chaine1"
<Guillaumito>
set1 != set2...
<Guillaumito>
the question is "why?"
<Kinners>
use, StringSet.compare set1 set2
<Guillaumito>
I know
<Guillaumito>
It was using "=" by mistake
<Guillaumito>
but it take me some time to find it
<Kinners>
a set cuold be internally built different ways, which = doesn't understand
<Guillaumito>
guess the '=' test the tree behind the set...
<Kinners>
yes
<Guillaumito>
ok
<Guillaumito>
one week to find it...
<Guillaumito>
thank you
* Guillaumito
is away: kawak
gim has quit [Read error: 104 (Connection reset by peer)]
Kinners has left #ocaml []
Tamagucci has joined #ocaml
owll has joined #ocaml
owll has left #ocaml []
<pattern>
hmm... i didn't know there was no nobel prize for mathematics
Smerdy has joined #ocaml
<Guillaumito>
it's a long story :)
Smerdyakov has quit [Read error: 110 (Connection timed out)]
srv has quit [Read error: 54 (Connection reset by peer)]
The-Fixer has quit ["Goodbye"]
Tamagucci has quit [Remote closed the connection]
gim has joined #ocaml
mimosa has joined #ocaml
alef72 has joined #ocaml
alef72 has left #ocaml []
tomasso has joined #ocaml
gim has quit [Read error: 104 (Connection reset by peer)]
Smerdyakov has joined #ocaml
gim has joined #ocaml
Smerdy has quit [Read error: 110 (Connection timed out)]
srv has joined #ocaml
whiskas has joined #ocaml
<whiskas>
Hi.
mattam has quit [Read error: 60 (Operation timed out)]
mattam has joined #ocaml
Guillaumito has quit ["Fermeture du client"]
whiskas has quit [Remote closed the connection]
Smerdy has joined #ocaml
Smerdyakov has quit [Nick collision from services.]
Smerdy is now known as Smerdyakov
yinnte has joined #ocaml
reltuk has joined #ocaml
yinnte has quit ["yinnte has left and wish you a nice day"]
malc has joined #ocaml
det has joined #ocaml
yinnte has joined #ocaml
yinnte has left #ocaml []
<async>
snerdy
<Smerdyakov>
Yup.
<async>
you in soda?
<Smerdyakov>
Not yet. Will be in 20 minutes. :)
<async>
its unpleasant outside
* Smerdyakov
leaves.
tomasso has quit [Read error: 104 (Connection reset by peer)]
tomasso has joined #ocaml
_JusSx_ has joined #ocaml
Nutssh has joined #ocaml
Nutssh has quit ["Client exiting"]
Nutssh has joined #ocaml
srv has quit [Read error: 110 (Connection timed out)]
_JusSx_ has quit [Read error: 60 (Operation timed out)]
whiskas has joined #ocaml
mr_jim has joined #ocaml
Nutssh has quit ["Client exiting"]
whiskas is now known as whiskas|food
Smerdy has joined #ocaml
mr_jim has quit ["Leaving"]
anpanman has joined #ocaml
malc has quit ["no reason"]
Smerdyakov has quit [Read error: 110 (Connection timed out)]
The-Fixer has joined #ocaml
Nutssh has joined #ocaml
Nutssh has quit [Client Quit]
whiskas|food is now known as whiskas
_JusSx_ has joined #ocaml
_JusSx_ has quit [Client Quit]
Smerdy is now known as Smerdyakov
Riastrad1 is now known as Riastradh
Kinners has joined #ocaml
Kinners has left #ocaml []
wazze has quit ["Learning about how the end letters on French words are just becoming more and more silent, I conclude that one day the French]
mr_jim has joined #ocaml
Nutssh has joined #ocaml
The-Fixer has quit ["Goodbye"]
Nutssh has quit ["Client exiting"]
mr_jim has quit ["Leaving"]
The-Fixer has joined #ocaml
whiskas has quit ["Leaving"]
mimosa has quit ["J'ai fini"]
Nutssh has joined #ocaml
cleverdra has joined #ocaml
mr_jim has joined #ocaml
The-Fixer has quit [Read error: 104 (Connection reset by peer)]