<async>
which is a combination of all of the other functions
<async>
then just map that to all the elements of the list
<cgxt>
hmm i can't use combine though
<cgxt>
well i believe im only supposed to use map or fold_right and not do it with any helper functions
<Kinners>
do you want my answers?
<cgxt>
i guess so, i don't see any other way i can learn this with out an example
<cgxt>
plus it will probably help me on the later ones
<Kinners>
let multimap1 flst xlst = fold_right (fun f l -> map f l) flst xlst;;
<Kinners>
let multimap2 flst xlst = map (fold_right (fun f n -> f n) flst) xlst;;
<cgxt>
i think my problem is im not really understanding the fun fn -> fn
<Kinners>
let foo bar = bar * 2;; is the same as let foo = fun bar -> bar * 2;;
<cgxt>
ah ok i get it now haha
<cgxt>
thanks a lot for all the help and stuff
<cgxt>
hopefully i can finish this thing
<async>
/whois kinners
<async>
sry
<cgxt>
hey would it be ok if i ask you guys some more questions later on if i get stuck
<Kinners>
you can always ask, but you may not always get an answer :)
<cgxt>
hehe, i don't want to annoy everybody
two-face has joined #ocaml
<two-face>
hi
<cgxt>
whats up
jedy has quit ["Bye."]
jedy has joined #ocaml
Kinners has left #ocaml []
teratorn has joined #ocaml
karryall has joined #ocaml
Guillaumito has joined #ocaml
systems has joined #ocaml
buggs|afk is now known as buggs
<cgxt>
hey anybody still here
<two-face>
yes
<cgxt>
hey
<cgxt>
i was wondering if you could help me out with somethin
<two-face>
depends
<cgxt>
im havin some trouble writing a funtion that computs a running sum
* Guillaumito
is away: strasbourg/frites
<cgxt>
ive got the use of functions fold_right and map and List.rev
<two-face>
i need to go
<cgxt>
aight
cgxt has quit []
Kinners has joined #ocaml
mattam has quit [Nick collision from services.]
mattam has joined #ocaml
systems has quit [Read error: 110 (Connection timed out)]
ustcbot has joined #ocaml
jedy is now known as ppmm
ppmm is now known as jedy
ustcbot has quit ["Edit the config file!!!"]
ppmm has joined #ocaml
* Guillaumito
is back (gone 01:23:29)
det has quit [Remote closed the connection]
det has joined #ocaml
* Guillaumito
is away: pipi
<two-face>
mouahaha
Guillaumito has left #ocaml []
<karryall>
passionant
<two-face>
tiens j'ai trouvé une référence à "Kitty Karyall" sur le web
<karryall>
ah ?
<karryall>
c'est quoi ?
<two-face>
un personnage de série TV on dirait
<two-face>
une fifille
buggs|afk has joined #ocaml
<karryall>
hmm
<two-face>
karryall: c'est une poupée en fait :)
<karryall>
arf
<two-face>
Episode 3: Kitty Karryall Is Missing
<two-face>
Cindy's doll is missing and Bobby is the main suspect. When Booby's kazoo is missing, he subsequently blames Cindy. In one of the most touching scenes in Brady Bunch history, Bobby breaks his piggy bank to but Cindy a new doll. It turns out that the flea-bitten Tiger has stolen both items. They are found in his doghouse and everyone is happy.
<two-face>
mouarf :)
Kinners has left #ocaml []
<karryall>
damned
buggs has quit [Read error: 110 (Connection timed out)]
polin8 has quit [Read error: 104 (Connection reset by peer)]
jedy has quit ["Bye."]
jedy has joined #ocaml
stardust has joined #ocaml
stardust is now known as stardust_
stardust_ is now known as stardust
stardust has quit ["leaving"]
polin8 has joined #ocaml
jedy has left #ocaml []
pflanze has quit [Read error: 110 (Connection timed out)]
systems has joined #ocaml
two-face has quit [Read error: 110 (Connection timed out)]
two-face has joined #ocaml
pflanze has joined #ocaml
clam has joined #ocaml
<two-face>
tovarisch
ppmm has quit ["Edit the config file!!!"]
ppmm has joined #ocaml
<systems>
what
<two-face>
?
<systems>
tovarisch ? what is that
<systems>
are you doing black magic
<mellum>
sounds russian
<two-face>
attempt to speak russian
<two-face>
meant to mean "comrade" :)
ppmm has quit ["Bye!"]
ppmm has joined #ocaml
systems has quit [Read error: 110 (Connection timed out)]
uppo has joined #ocaml
<uppo>
/msg NickServ IDENTIFY duilio48
<Smerdyakov>
Hm?
two-face has quit ["Client exiting"]
uppo has left #ocaml []
uppo has joined #ocaml
uppo has left #ocaml []
<det>
uppo, nice
clam has quit ["no reason"]
ppmm has quit ["Bye!"]
ppmm has joined #ocaml
ppmm has quit [Client Quit]
ppmm has joined #ocaml
reltuk has joined #ocaml
cgxt has joined #ocaml
<cgxt>
hi i was wonderin if i could get some help with writing a function that computes the running sum of a list
<cgxt>
currently i have this
<cgxt>
let rsum lst =
<cgxt>
(fold_right (+) (fold_right(fun a b -> a::b) lst [0]) 0)::[];;
<cgxt>
but that only gets me the first iteration
<Hadaka>
cgxt: that summing is in every example written just about
<cgxt>
for real
<cgxt>
can you point me to a good sight then to see these examples
<Hadaka>
just a sec, I'll dig one up
<cgxt>
thanks a lot
karryall has quit ["tcho"]
<cgxt>
because how i need it is [0;x1+x2;x1+x2+x3;x1+x2+x3...+xn]
<Hadaka>
ah, sorry - misunderstood running sum then
<vegai>
was the function "iterate" in ocaml's standard?
<vegai>
oh, sorry -- what standard? =)
<vegai>
but you know what I meant =)
<cgxt>
yah im supposed to use fold_right, the only list function i can use is list.rev
<cgxt>
now i got it at
<cgxt>
let rsum lst =
<cgxt>
fold_right (fun x y -> (fold_right (+) (fold_right(fun a b -> a::b) lst
<cgxt>
[0]) 0)::y) lst [0];;
<vegai>
hmm, ocaml.org frontpage doesn't say anything about 3.07
<Hadaka>
cgxt: err... is this an exercise you have to do or is this a real problem?
<cgxt>
ah an excercize, im sorry if im buggin ya
<cgxt>
ill leave ya alone then
<Hadaka>
no, feel free to ask - just that I believe people will try to rather help you make it yourself then, than to give the answer right away :)
<cgxt>
ya i know where ya gettin at
<cgxt>
for the list [1;2;3;4;5] it gives me [15,15,15,15,15,0] so i guess my problem is im not changing the list to the next iteration, thats where i gotta learn
<Hadaka>
I'm not sure what the original question is though - you need to make every list element a sum of every element before it and it, or?
<cgxt>
well the input is a list of integers
<cgxt>
and the output should be [0;x1+x2;x1+x2+x3;x1+x2+x3...+xn]
<cgxt>
where x1 , x2 are elements of the input list
<Hadaka>
sure the first element is 0 and not x1?
<cgxt>
oh whoops i left that out
<cgxt>
haha
<cgxt>
a little tired
<cgxt>
[0;x1;x1+x2;x1+x2+x3;x1+x2+x3...+xn]
<Hadaka>
ah, okay, that makes a bit more sense
<Hadaka>
well, the way I think it should be done is that you map over the initial integer list, always summing every element together and taking the tail - and then reversing the result
<cgxt>
yah for some reason im having a problem taking the new tail with partial function use
<cgxt>
since i can't use recursion
<Hadaka>
oh, not using recursion was a requirement? and you can only use reversion on lists?
<cgxt>
yah but i have the use of fold_right and map which i wrote earlier, and also List.rev if i need it
<Hadaka>
but map should be enough
<Hadaka>
map over the list with a function which does fold_right on the remaining list every time
<vegai>
wonder where I should search to find good ocaml assignments
<vegai>
perhaps the Book had some
<Hadaka>
the o'reilly book has plenty of nice exercises - but obviously they are a bit public and copyright issues might arise ;)
<vegai>
I'm just gonna do them, not republish
<Hadaka>
oh, do - then the book is excellent
<Hadaka>
I thought you were looking for exercises for your students or something ;)
ppmm has quit ["Leaving"]
<vect>
'lo people
ppmm has joined #ocaml
ppmm has quit [Client Quit]
ppmm has joined #ocaml
<vect>
cgxt try this : let rec sum k = function [] -> [k] | t::q -> t::(sum (t+k) q);; let rsum foo = sum (List.hd foo) (List.tl foo);;
Demitar has joined #ocaml
<vect>
it's a bit ugly, but I think it's what you want
ppmm has quit [Client Quit]
ppmm has joined #ocaml
<vect>
oh, didn't see that you must use fold_right ..
<cgxt>
yah its coo
<cgxt>
im not supposed to use recursion
<vect>
fold_right is recursive :)
<cgxt>
well i mean upon the function im writing haha
<cgxt>
as long as its in the higher order functions im using its ok
<cgxt>
well i got this so far, but i think im way off
<cgxt>
let rsum lst =
<cgxt>
map (fun x y -> match y with
<cgxt>
[] -> [0]
<cgxt>
| l::ls -> (fold_right (+) ls 0)::[]) lst;;
<vect>
you can even remove "lst"
pflanze has quit [Connection timed out]
<vect>
let rsum = map (blabla ...);;
<Hadaka>
cgxt: what does your map give the function as parameters?
<cgxt>
its map f lst
<cgxt>
so a function and a list right?
<cgxt>
however my rsum function only gets the list as an input
<vect>
let rsum = map (function x -> function [] -> [0] | l::ls -> (fold_right (+) ls 0)::[]);;
<Hadaka>
but what does the function get as an argument? if it's just 'a -> 'b then that's a problem
<vect>
a bit shorter
ppmm has quit ["Bye!"]
<Hadaka>
you'd need the rest of the list as an argument to the function - and not the current element
ppmm has joined #ocaml
ppmm has quit [Client Quit]
<cgxt>
yah map is 'a -> 'b
<Hadaka>
okay, then you can't easily use that
<cgxt>
('a -> 'b) -> 'a list -> 'b list = <fun>
<cgxt>
so i should probably just stick with the fold_rights then
<Hadaka>
yup... but even fold right only handles elements
<cgxt>
oh man i feel a headache comin on, hehe
<Hadaka>
you have to make fold_right returning lists to make that happen I believe
<Hadaka>
solved it!
<Hadaka>
I started ocaml just a few days ago myself
<cgxt>
for real
<cgxt>
yah i just can seem to get the hang of this language
<cgxt>
ive got this haha
<cgxt>
let rsum lst =
<cgxt>
fold_right (+) (fun x y -> match y with
<cgxt>
[] -> [0]
<cgxt>
| l::ls -> fold_right x::y ls []) 0;;
<Hadaka>
okay, you'll have to do it a bit differently
<Hadaka>
first of all, don't use fold_right with (+) at all - but instead use it so that you only add the next number to the previous sum to get the next sum
<Hadaka>
Then - the fold_right that you do at the top level - that gets in a function that takes in an int - and produces out an int list each time - and you match it pretty much like you did, but not quite
Hipo has quit [Remote closed the connection]
Hipo has joined #ocaml
<Hadaka>
cgxt: you only need on fold_right there
<Hadaka>
one
<cgxt>
hmm got this so far
<cgxt>
let rsum lst =
<cgxt>
fold_right (fun a b -> a + b) (match lst with
<cgxt>
[] -> [0]
<cgxt>
| l::ls -> ls) 0;;
<Hadaka>
okay
<Hadaka>
that needs a bit of tweaking
<cgxt>
yah
<cgxt>
im sorry bout all this
<Hadaka>
you want to do the matching inside the function you give to fold_right - and just give lst to fold_right where you do the matching - and what is coming out of the fold_right is always a list - so instead of giving 0 as the last argument, you give [] as the last argument
Demitar has quit ["Bubbles everywhere!"]
<Hadaka>
actually, you don't need matching at all, because of the zero - they've made it even easier
<Hadaka>
can you use List.hd and List.tl?
<Smerdyakov>
Those functions are SCARY!
<cgxt>
no
<Hadaka>
okay, then you have to match - but the match is only for doing the h :: t separation
<cgxt>
so it should be somethin like this
<cgxt>
let rsum lst =
<cgxt>
fold_right (fun a b -> match with b
<cgxt>
[] -> [0]
<cgxt>
| b::bs -> a + b) lst [];;
<Smerdyakov>
[0]! How a scary list !!
<Hadaka>
pretty much
<Hadaka>
but, a couple things
<Hadaka>
well, only one thing
<Hadaka>
where you do the b::bs match
<Hadaka>
err, it's confusing to use the same letters there
<Hadaka>
you want:
<cgxt>
oh woops
<Smerdyakov>
I always use the same letters.
<Smerdyakov>
It's extra fun.
<Hadaka>
fold_right (fun a b -> match b with ... | h :: t -> ...
<Hadaka>
anyway, what you return from the [] case is indeed a list of a zero - but what you wish to return from the second case should also be a list - a list where the new sum is concatenated to the front of the list that was given
<cgxt>
let rsum lst =
<cgxt>
fold_right (fun a b -> match b with
<cgxt>
[] -> [0]
<cgxt>
| h::t -> a + h::b) lst [];;
<Hadaka>
almost perfect
<Hadaka>
you got the knack now
<cgxt>
hehe
<cgxt>
unfortunately im gettin the wrong sums out
<cgxt>
hmm
<Hadaka>
the one problem is that [] -> [0] should be either [] -> a :: [0] - or you could give [0] as the initial argument to fold_right and never have that case fulfilled
<Hadaka>
and the other problem is that you have to reverse the list given in and the result after that
<cgxt>
let rsum lst =
<cgxt>
let rlst = List.rev lst in
<cgxt>
(List.rev (fold_right (fun a b -> match b with
<cgxt>
[] -> a :: [0]
<cgxt>
| h::t -> a + h::b) rlst []));;
<cgxt>
oh man haha
<cgxt>
thanks a lot for the help
<cgxt>
haha sorry it took me so long
<Hadaka>
no problem
<cgxt>
hopefully what i learned from this one will help me along on teh rest
<Hadaka>
well, I hope you learned more than just by getting the answer :)
<Hadaka>
oh btw, why are you doing these? are you in a school and put to learning these - or are you studying yourself?
<cgxt>
yah in school unfortunately, haha
<Hadaka>
where do they teach OCaml? :)
<cgxt>
University of Illinois
<Hadaka>
that's cool :)
<cgxt>
yah unfortunately it looks like im not absorbing much haha
<Hadaka>
well, you did evolve towards the correct choice throughout the whole time
<Hadaka>
and with a little pushing you did realize how it's done
<phubuh>
cgxt, cs321?
<cgxt>
haha yah
<phubuh>
i have a friend who's taking that class in cs321. he's doing some assignment with triminos or something -- is that what you're doing? :-)
<cgxt>
yah
<cgxt>
unfortunately im pretty behind, ive been sick and the work piled up
<cgxt>
this ones probably gonna be late
moira has joined #ocaml
<moira>
huh
<moira>
read the lecture notes if you're behind, you only need to read up through lecture 6
<moira>
I never went to that class, all I did was read the pdfs
<cgxt>
yah coo
<cgxt>
well ive been goin to class
<cgxt>
just behind on the mp
<cgxt>
and reading the pdfs
<Hadaka>
hmmh, I wonder if I should do that as well to learn more ocaml or not :)