jeremiah has quit [Read error: 104 (Connection reset by peer)]
kg4qxk has joined #ocaml
sporkmonger_ has quit [Read error: 110 (Connection timed out)]
threeve has quit []
seafood has joined #ocaml
jeremiah has joined #ocaml
Myoma has joined #ocaml
sporkmonger has joined #ocaml
<Palace_Chan>
if i receive an argument x of type int * int how can i grab the first element of the tuple or the second ? do i have to add a: match x with (first,last) ?
<kig>
let (a,b) = x in
<kig>
there's also fst x and snd x
<kig>
you can also write e.g. let multiplyTuple (a,b) = a * b
<Palace_Chan>
if i do let (a,b) = x in then subsequently a will contain the first element of the tuple and b the second ?
<kig>
yes
<Palace_Chan>
ah, thanks, that is simpler than having to nest a match
<pango_>
and also write arguments list as f ... ((first, last) as x) ... instead of just x
<Palace_Chan>
pango_, ? what about f (x: int * int)(anotherarg: itstype)....
<pango_>
((first, last) as x: int * int), etc. should do, if you really want such type annotations
<bluestorm>
do you really need the type annotations ?
fbotelho has joined #ocaml
<Palace_Chan>
pango_, oh wait i think i get the syntax, it would be for example: f (type as x) (type2 as y)...
<Palace_Chan>
to write argument lists that is
itewsh has quit ["KTHXBYE"]
<bluestorm>
it's not the type you put there
<bluestorm>
it's a pattern
<bluestorm>
(pattern as name) match the parameter with the pattern, but also bind it to the name
gaja has quit ["Lost terminal"]
<bluestorm>
let f ((x, y) as couple) : if you call f (1, 2) you'll have x -> 1, y -> 2, couple -> (1, 2)
<bluestorm>
you could also do let f couple = let (x, y) = couple in ....
<bluestorm>
if you want to specify a type for your argument's, it's (parameter : type) : let foo (n : int) = n , you can combine them into eg. ((first, last) as x : int * int)
<bluestorm>
however, giving the type here is not very elegant and imho a bad decision in most situations
<Eridius>
it's useful when you're using the object system
<bluestorm>
that's a different matter
<Eridius>
after all, you don't want a val foo : < size : int; .. > -> int = <fun>
<bluestorm>
it's also useful when the type system fails somewhere deep down in your code and you have to debug that
<bluestorm>
(but it's *not* so useful for documentation when your code gets big : there are .mli files for that purpose)
<Palace_Chan>
the type inference system can fail ? wow that mus be hard to debug
<bluestorm>
hm
<bluestorm>
i said it wrong
<bluestorm>
sometimes you fail, and the type inference system spot it
<Palace_Chan>
oh oko
<bluestorm>
you've got something like "this value has type .... but is used with type ...." and you're like "o_O what the hell ?"
<bluestorm>
because you _know_ it is the correct type at this place, and of course the error message doesn't make sense
<Eridius>
because the type inference system picked up the wrong type for it based on your error
<bluestorm>
usually it's because you use your value as a parameter of a function that was coded wrong before in your code, and you didn't noticed that
<Eridius>
like maybe it takes an int arg and does lots of math with it, but the very first thing it does is accidentally uses a floating point operation, now it thinks it's supposed to be given a float
<bluestorm>
(wrong code -> wrong use -> wrong type inferred)
<Eridius>
once you annotate it as an int, then it can point out where you accidentally treated it as a float
Proteus has joined #ocaml
<Palace_Chan>
i see
<bluestorm>
well, as Yoric would probably said (seems he's at IFL, sleeping with Haskellites probably), "it's time to call it a night"
bluestorm has quit [Remote closed the connection]
struktured has joined #ocaml
takuya has joined #ocaml
seafood has quit [Read error: 60 (Operation timed out)]
rwmjones_ has joined #ocaml
Proteus has quit ["Leaving"]
takuya has left #ocaml []
rwmjones_ has quit ["Closed connection"]
jlouis has quit ["Leaving"]
lde has quit [Read error: 113 (No route to host)]
Kopophex has quit ["Leaving"]
struktured_ has joined #ocaml
struktured has quit [Read error: 110 (Connection timed out)]
struktured_ has quit ["Konversation terminated!"]
<Palace_Chan>
if a function declaration in a signature is: val f : type->type...
<Palace_Chan>
how do i declare a type declaration in a signature ?