Proteus has quit [Read error: 54 (Connection reset by peer)]
Proteus has joined #ocaml
mbishop has joined #ocaml
Proteus_ has quit [Read error: 113 (No route to host)]
seafood has joined #ocaml
Proteus_ has joined #ocaml
dejj1 has joined #ocaml
lecas has quit [Remote closed the connection]
Proteus__ has joined #ocaml
Proteus_ has quit [Read error: 104 (Connection reset by peer)]
nuncanada has joined #ocaml
pango_ has quit [Remote closed the connection]
dejj has quit [Read error: 110 (Connection timed out)]
Proteus has quit [Read error: 113 (No route to host)]
seafood has quit [Connection timed out]
sporkmonger has joined #ocaml
Proteus has joined #ocaml
mfp has quit [Read error: 104 (Connection reset by peer)]
dejj1 has quit ["Leaving."]
Proteus__ has quit [Read error: 113 (No route to host)]
Ched- has quit [Read error: 110 (Connection timed out)]
Ched- has joined #ocaml
Proteus_ has joined #ocaml
pango_ has joined #ocaml
mfp has joined #ocaml
Proteus_ has quit [Connection reset by peer]
Proteus_ has joined #ocaml
Proteus has quit [Read error: 113 (No route to host)]
bohanlon has quit ["leaving"]
Proteus__ has joined #ocaml
Mr_Awesome has quit [Connection timed out]
m3ga has quit ["disappearing into the sunset"]
Proteus_ has quit [Read error: 113 (No route to host)]
jeddhaberstro has quit []
_y_ has quit []
nuncanada has quit [Remote closed the connection]
Mr_Awesome has joined #ocaml
<Palace_Chan>
if i want to check for Hashtbl.find sometable somekey but i want to catch a Not_found exception do i do: try Hashtbl.find sometable somekey with | Not_found -> (caught it)
<Eridius>
what happens when you try?
<Eridius>
incidentally, the | is optional. It's intended to provide a slightly "cleaner" appearance when each match case is on a separate line
<Palace_Chan>
well Hashtbl.find throws Not_found if a key is not in the table...but i want to catch that exception and say return a boolean
<Eridius>
ok, so what's the problem?
<Palace_Chan>
so i guess inside the function i can do try Hashtbl.find, then with Not_found -> handle
<Palace_Chan>
the syntax, i was wondering if that was it
<Eridius>
I hope you realize you can test the syntax very quickly in the toplevel
<Palace_Chan>
i have been doing so yes, only sometimes i am still not used to the compiler error messages
struktured_ has joined #ocaml
<Palace_Chan>
i get type errors still, it's my second day in OCaml
<thelema>
Palace_Chan: yes - that's the syntax.
<Eridius>
Palace_Chan: I bet your handle statement is returning a different type
<Eridius>
than the Hashtbl.find
<Eridius>
after using ruby for a while, I love having a strong type inference system
<Palace_Chan>
im going to check it on the top level
<Eridius>
in my little scripts, once I fix all the type errors, it almost always works on first run
<Eridius>
when it doesn't, it's because I have a conceptual error about how to solve the problem
<Eridius>
Palace_Chan: what's the error you get?
<thelema>
Palace_Chan: you only get one return type, so if your handler returns bool, your main function must also return bool
<Eridius>
Palace_Chan: if you want your expression to return the value if it exists, or indicate it doesn't without an exception, I recommend using 'a option
<Palace_Chan>
actually my function syntax "seems" correct
<Eridius>
try Some (Hashtbl.find tbl key) with Not_found -> None
<Palace_Chan>
'a option the type ? how so ?
<Eridius>
you could also check the result of Hashtbl.mem tbl key first, which returns a bool that indicates the presence of the key
<Palace_Chan>
Eridius, if the exception is not thrown, that should return Some result ?
<Eridius>
yeah
<Palace_Chan>
without using .mem though, Hashtbl.find, in the case of not throwing exception, would return the image of the key...is there a way to detect that and report it in bool form ?
<Eridius>
Palace_Chan: you can either return a bool, or you can return the type of value that the Hashtbl hash. You have to pick, one or the other
<Eridius>
if you want to return a bool.. just use Hashtbl.mem
<Eridius>
you're missing the whole type aspect here
<Eridius>
this isn't a wishy-washy dynamic typed language. Your expression has to return a single type
<Eridius>
this is the entire point of the 'a option type. It lets you represent the idea of "return an object, or return nothing at all"
<Eridius>
kinda like returning a pointer or NULL in C
<Eridius>
or an object or nil in ruby
<Palace_Chan>
hmm, wait that is interesting i had never understood why there would be some made up type called type 'a option = None | Some of 'a
<Eridius>
it's for exactly this situation
<Eridius>
another example is in camlimages, the OImages.oimage class type has a method called save, which takes a filename, an file_type option, and a list of options.
<thelema>
Palace_Chan: all pointers are non-null. Ocaml won't ever give you a null dereference.
<Eridius>
the file_type option lets you say something like (Some Images.Png) to mean save as a PNG, or just None to mean infer the filetype from the filename
<Palace_Chan>
i see
struktured has quit [Read error: 110 (Connection timed out)]
<Palace_Chan>
in the signature: val get_current_ctr : unit -> int
<Palace_Chan>
unit is not the return type anymore
<Eridius>
that's a function which takes unit and returns an int
<Palace_Chan>
like, if one says let get_current_ctr () : int -> !ctr
<Palace_Chan>
that is also a function which takes unit and returns int
<Eridius>
sure
<Palace_Chan>
ah, little confusing since in the first case unit appears righrt between : and ->
<Palace_Chan>
in the place the return type usually appears
<Eridius>
you're confusing yourself
<Eridius>
val get_current_ctr : type
<Eridius>
type there is unit -> int
<Palace_Chan>
ohhhh
<Eridius>
actually, your let code is syntactically invalid
<Palace_Chan>
a function from unit to int
<Palace_Chan>
cuz that is what it is
<Eridius>
let get_current_ctr () : int = !ctr
<Eridius>
hopefully that'll clarify it
<Palace_Chan>
yes, thanks i didnt catch that
<Eridius>
let get_current_ctr () : unit -> int = (fun () -> !ctr)
struktured_ has quit ["Konversation terminated!"]
<Palace_Chan>
whenever i define a type i need a constructor of some sort as in type t = This | That don't i ?
<Palace_Chan>
but if i wanted to define a type within a module interface, i.e between sig and end what does a type definition prototype look like ?