<flux>
I was going to say use Array.find, but it doesn't have such a function :)
<flux>
maybe possible_extensions should rather be a list, anyway..
<albacker>
hmm.. i thought since it's always fixed size it would be good to have array. but yeah in my case it makes no difference.
<flux>
with list the function would be like: let get_name ext = snd (List.find (fun (a, _) -> a = ext) possible_extensions) (except for the special case of not finding the value)
<flux>
for that using exceptions would be ok, if not for only other reason because ocaml doesn't support returning option types from List.find :)
<albacker>
don't spoil my code :(
<flux>
:)
<flux>
in ocaml one would always use lists, unless you need constant time indexing or possibly mutability
<flux>
with lists it's easier to write recursive functions
<albacker>
well i can't use snd and fst in my case since i'll have a triplet.
<flux>
oh, ok
<flux>
perhaps you should consider using records in that case
<flux>
because it looks like to me you are using a string array when the index has a fixed meaning
<flux>
basically you're using a non-compiler-verified version of tuples
<flux>
(or perhaps I don't understand what's the function of getName)
<flux>
oh right, and usually ocamlers prefer lowercase_symbols_without_CamelCase. but of course you are free to go as you want, but this approach is least likely to cause funny-looking code when you use other libraries :)
<albacker>
i had an array of arrays of form [|string1;string2;string3|], and i got a string as input of my function (getName) and compared it to every string1 in the array (possible_extensions) and i returned string2 whenever i found smth
<flux>
what's string3 used for?
<albacker>
for later maybe.
<flux>
what do you have in there now?
<albacker>
another string.
<albacker>
=D
<flux>
I think something like type extension_info = { ext : string; name : string; aux : string } would do fine here
<albacker>
yeah.. probably, but i'm not really comfortable with records -_-
<albacker>
ok i'll do it this way, better to learn coding clean once then go wrong all time </positive_thinking>
<flux>
albacker, yes, it's fine (although it could be using List.find). you also don't need to match for ..; aux = aux_value} if you don't need the aux value there.
<flux>
actually what you could do would be: let rec aux l = match l with [] -> "txt" | { ext = ext_value; name = name_value }::_ when ext_value = ext -> name_value | _::t -> aux t
<albacker>
oh that "when" -_-
<albacker>
thanks again.
Drk-Sd has joined #ocaml
ttamttam1 has joined #ocaml
ttamttam has quit [Read error: Connection reset by peer]
spearalot has joined #ocaml
rwmjones has quit [Ping timeout: 245 seconds]
Shoggoth has joined #ocaml
<albacker>
has anyone had any experience with curl? (ocaml curl)
<f[x]>
there is no docs for ocurl - true, because it is really a thin wrapper over libcurl
matthieu has joined #ocaml
<f[x]>
looks like ocurl doesn't implement this option for httppost
<f[x]>
actually no, looks like it implements it, | CURLFORM_CONTENT of string * string * curlContentType
maattd|away has quit [Ping timeout: 264 seconds]
{newbie} has joined #ocaml
bzzbzz has joined #ocaml
<f[x]>
the first string is form name and the other is contents
<f[x]>
it doesn't expose COPYNAME because it is not-needed (too low level for gc memory management)
<albacker>
hmm.. i get an exception :/
det has joined #ocaml
<albacker>
f[x], what about the CURLFORM_FILE and CURLFORM_FILECONTENT ?
<albacker>
one string is filename.
pimmhogeling has quit [Ping timeout: 265 seconds]
<f[x]>
form name and file name
{newbie} has quit [Ping timeout: 268 seconds]
spearalot has quit [Quit: -arividerchi]
{newbie} has joined #ocaml
Smerdyakov has joined #ocaml
pimmhogeling has joined #ocaml
{newbie} has quit [Quit: {newbie}]
Smerdyakov has quit [Quit: Leaving]
ikaros has joined #ocaml
lokydor has joined #ocaml
avsm has quit [Quit: Leaving.]
lokydor has quit [Client Quit]
<albacker>
i failed, this http://pastebin.org/107477 does not do what it was meant to (paste the "something to paste" string in pastebin, and return URL). in fact it hangs and gives no output :/
ikaros has quit [Quit: Leave the magic to Houdini]
<f[x]>
yep, read how http post works and read tutorials on curl site
_unK has joined #ocaml
avsm has joined #ocaml
pimmhogeling has joined #ocaml
<maennj>
I'm trying to make 'context' type which is basically a list of mappings between names and values, I'm also trying to define a lookup function that looks for the given name in the given context and returns the value.. I'm new to OCaml, can someone tell me what's wrong in my code : http://pastebin.com/r6cvau35
<maennj>
I'm getting Error: This expression has type context but an expression was expected of type int
<avsm>
it should be (Some value)
<avsm>
since you return None in another part of the pattern match
<maennj>
ooh
<avsm>
also, the second binding wont ever match
<Camarade_Tux>
also, I think the second pattern-match for Binding is unused
<Camarade_Tux>
you should get a warning about it
<maennj>
hmm
<maennj>
yea I got warning :/
joewilliams_away is now known as joewilliams
<Camarade_Tux>
why two different cases?
<maennj>
because if name doesn't match with the head
<maennj>
I'm not sure if that's the right way to do it :)
<maennj>
I mean, I imagine the context as linked list , each node contains a string and integer and link to the rest of the list
<Camarade_Tux>
oh, I see: you're actually defining a new variable here: you can use 'when' here (extension of the language):
<Camarade_Tux>
Binding(binding_name, value, _) when binding_name = name -> value
<Camarade_Tux>
|Binding(_, _, ctx) -> lookup name ctx
<maennj>
ooh ok, I thought I'm using the same name :)
<maennj>
cool no warnings now, thanks a lot
<Camarade_Tux>
or also use 'Binding(binding_name, value, ctx) -> if binding_name = name then value else lookup name ctx'