joshcryer has quit [Read error: 104 (Connection reset by peer)]
EsotericMoniker has left #ocaml []
CosmicRay has joined #ocaml
CosmicRay has quit ["Client exiting"]
jcreigh has joined #ocaml
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
Revision17 has joined #ocaml
dleslie is now known as danly
d-bug has joined #ocaml
hikozaemon has joined #ocaml
shekmalhen has joined #ocaml
slipstream has joined #ocaml
piggybox has quit []
slipstre1m-- has quit [Connection timed out]
tristram has joined #ocaml
piggybox has joined #ocaml
khaladan_ has joined #ocaml
khaladan has quit [Connection timed out]
khaladan_ is now known as khaladan
clconway has joined #ocaml
clconway has left #ocaml []
scriptdevil has joined #ocaml
<scriptdevil>
how old or how new is OAML?
scriptdevil has quit [Client Quit]
scriptdevil has joined #ocaml
scriptdevil has left #ocaml []
scriptdevil has joined #ocaml
scriptdevil has left #ocaml []
youknow365 has quit ["Konversation terminated!"]
shekmalhen has quit ["b.."]
postalchris has joined #ocaml
mnemonic has joined #ocaml
mnemonic has quit [Client Quit]
smimou has joined #ocaml
ookk has joined #ocaml
pattern has quit [Connection reset by peer]
pattern has joined #ocaml
Snark has joined #ocaml
Kai1111 has joined #ocaml
<ookk>
can i use an array in a functional way?
<ookk>
when i want to pass the array to another function with just one value in it changed
<postalchris>
ookk, perhaps you can clarify your question with an example?
<postalchris>
an array is a sort-of fundamentally non-functional structure, since it's modifiable in-place
<ookk>
i would like to pass an array in a recursive function with one value changed
<ookk>
and i was wondering if there was a function that returned the same array with one value at index i changed
hcarty has joined #ocaml
<ookk>
thats not dog-slog
<ookk>
slow*
<postalchris>
Isn't that function "a.(i) <- new_value"?
d-bug has quit [Read error: 60 (Operation timed out)]
<postalchris>
Or you mean, you want a copy of a?
<ookk>
that is imperative
<zmdkrbou>
ookk: what's the point of using an array if you pass it like a list and process it functionnally ?
<ookk>
that statement doesnt return a new array with the position at index i changed to new_value
<zmdkrbou>
let _ = a.(i) <- new_value in a
<ookk>
zmdkrbou, because i want a fixed length
<ookk>
zmdkrbou, doesnt that return unit?
<ookk>
a.(i) <- value
<zmdkrbou>
nope, it returns a
<ookk>
okay then it should not be considerd imperative imo
<zmdkrbou>
this is equivalent to "a.(i) <- new_value ; a"
<zmdkrbou>
but i don't get the fixed-length thing
<zmdkrbou>
if you don't add elements, a list also has a fixed length
<ookk>
yeah i guess it doesnt matter
<ookk>
i just want a functional way of passing a list, array whatever to a function with one value changed
hikozaemon has quit ["Leaving..."]
<ookk>
i guess i could write a function that does that to a list
<ookk>
but i feel it would be slower then an imperative approach
<Dylan>
ookk: do you mean map?
<ookk>
and i want to learn to make fast programs the functional way, that why im interested in ocaml :P
<ookk>
Dylan, doesnt that have unessesary overhead?
<ookk>
with it using keys
<Dylan>
um
<Dylan>
I mean List.map
<Dylan>
List.map : ('a -> 'b) -> 'a list -> 'b list
<postalchris>
Still requires "imperative" counting to find the index.
<Dylan>
you want to change it based on the index?
<ookk>
i was thinking:
<ookk>
let modify lst i value =
<ookk>
match lst with
<ookk>
| head::tail -> if i == 0 then value :: tail else head :: modify tail (i-1) value
<ookk>
;;
<Dylan>
You could use a fold_left, probably... But if you want to escape imperative this much, ocaml's not for you
<ookk>
i dont have anything againt imperative i code c++ normally, i just want to explore the functional possibilites before i revert to the imperative way
<ookk>
maybe i could use a map beacuse i use the index as a key
<Dylan>
well, wanting to change an item based on an index in an array is still imperative thinking
* zmdkrbou
agrees with that
<ookk>
but i got the feeling that map is much slower than using an array where elements lie next to eachother in the memory
<postalchris>
ookk: List.fold is your "most functional" solution given the way you've posed the problem
<Dylan>
for sequential access, a list is very fast.
<ookk>
Dylan, well the function i pasted is not imperative
<postalchris>
ookk: do you want to program functionally, or think about memory layout ;-)
<ookk>
hehe i cant not think about it :P
<ookk>
you cant be to naive about what happens to you code :P
<Dylan>
arrays are good for *random* access, but linked lists are good for sequential
<ookk>
yes
<ookk>
but this is very random
<ookk>
so there is no efficient way of doing random access in a functional way?
<zmdkrbou>
ookk: to program in a functional way, you *have* to forget about low-level
<postalchris>
ookk: let me re-read Okasaki and get back to you...
<ookk>
heh
<zmdkrbou>
"being next to another element in memory" doesn't mean anything in the functional world
<ookk>
zmdkrbou, well if you are concerned about speed you cant forget about low level
<zmdkrbou>
nope, you have to trust the implementation :)
<ookk>
hehe yeah i guess you do
<ookk>
but as i am used to c++ where you ususally can guess in what happens in the low level
<ookk>
to not use if-statements because of branching and all that :P
<zmdkrbou>
either you take functional programming as it is, or you stick to c/c++ & co, imo
<ookk>
yeah i have discovered a lot of good stuff about funcitonal programming
<zmdkrbou>
(if i'd be looking for speed, i wouldn't use functional programming)
<ookk>
my main dissapointment is arrays though but ocaml supports the imperative way so i guess it doesnt matter
<ookk>
problably not if you want to do something with large arrays of data
<ookk>
but i have heard that ocaml is pretty fast at stuff more appropriate for functional programming
pattern has quit ["Reconnecting to server - dircproxy 1.1.0"]
pattern has joined #ocaml
<ertai>
ookk: you can use a map to do random access in a functional way