psb has quit [Read error: 60 (Operation timed out)]
[1]platypus has joined #ocaml
<[1]platypus>
what does List.fold_left mean ?
benja has joined #ocaml
<benja>
hey all
<[1]platypus>
hey
<benja>
I have a type t = A of int | B of float;; and a function compute : int -> t. Is there an ocaml trick to parametrise the function to determine that it'll return A or B ?
<Riastradh>
I'm not quite sure I understand your question.
<benja>
To avoid a match after the function
<benja>
let say that my function can return a composite type (A or B) but when I want to use it, I want it to return a A value.
<Riastradh>
That would rather depend on what that function does, wouldn't it?
<benja>
I don't know how to do it but here is how I see it. x : int = read "file" `INT or y : float = read "file" `FLOAT
<benja>
so I want to pass an extra parameter which tell the type of the returned value
<benja>
does that make sense ?
<Riastradh>
I suppose you could just use a sentinel value -- e.g., write [[let A x = read "file" (A 0)]] or [[let B x = read "file" (B 0.0)]].
<benja>
ok I see
<benja>
so my function would have a type : string -> 'a -> 'a but how can I restraint the type of 'a to an element of type t ?
<sundeep>
platypus: i'll paste the meaning from the online reference:
<sundeep>
List.fold_left f a [b1; ...; bn] is f (... (f (f a b1) b2) ...) bn.
<Riastradh>
benja, I don't believe you can have a function like that.
<benja>
the class system is able to do that with a parametric class but is there parametric functions ?
<benja>
if i try 'let x y = match y with int -> () | float -> ()' in the toplevel. the type of the function is 'val x : 'a -> int = <fun>'
<benja>
all right I'll write read_{type} function for each type...
bk_ has joined #ocaml
bzzbzz has quit [Read error: 60 (Operation timed out)]
skaller has quit [Read error: 110 (Connection timed out)]
skaller has joined #ocaml
benja has quit ["Leaving"]
franco has joined #ocaml
franco has left #ocaml []
psb_ has quit ["ChatZilla 0.8.23 [Mozilla rv:1.3/20030312]"]
vezenchio has joined #ocaml
skylan has joined #ocaml
CiscoKid has joined #ocaml
skylan has quit [Read error: 104 (Connection reset by peer)]
skylan has joined #ocaml
kinners has quit ["leaving"]
<[1]platypus>
how do i get access to the filename module?
[1]platypus has quit [zelazny.freenode.net irc.freenode.net]
[1]platypus has joined #ocaml
[1]platypus has quit [zelazny.freenode.net irc.freenode.net]
[1]platypus has joined #ocaml
<[1]platypus>
when a character is placed in double quotes ocaml treats it as a char but in single it's treated as a string ?
<bk_>
the other way around
<bk_>
"a" is a string 'a' is a char
<[1]platypus>
# String.rindex "cock" "k";;
<[1]platypus>
Characters 21-24:
<[1]platypus>
String.rindex "cock" "k";;
<[1]platypus>
^^^
<[1]platypus>
This expression has type string but is here used with type char
<[1]platypus>
ops
<[1]platypus>
sorry sorry
<[1]platypus>
din mean to flood
<[1]platypus>
i was trying to paste it elsewhere
<CiscoKid>
val rindex : string -> char -> int
<bk_>
String.rindex "cock" 'k'
<simon->
is ocaml platypus-compatible?
<[1]platypus>
bk_, yeah but what is the error reffering to ?
<[1]platypus>
simon-, :)
<[1]platypus>
simon-, at this point i guess not
<simon->
platypus, look at what CiscoKid wrote.
<bk_>
you're using a string "k" instead of a char
<CiscoKid>
It's telling you that you used a string where a char was wanted.
<bk_>
This expression has type string mean the "k"
<CiscoKid>
I wonder how much easier ocaml would be if that error was restructured a bit. :)
<simon->
...but is here used with type char (referring to the "char" bit in what CiscoKid wrote)
<[1]platypus>
ok
<[1]platypus>
got it :)
<sundeep>
CiscoKid: i wonder why no one has done anything about the error messages
<[1]platypus>
which module do i use if i want to read and write to a file ?
<sundeep>
platypus: the module Pervasives which is open by default, you can also use Printf
<CiscoKid>
There's a lot of improvements that could be made to ocaml, but they don't seem to be very fast to accept improvements.
[1]platypus has quit [zelazny.freenode.net irc.freenode.net]
[1]platypus has joined #ocaml
bk_ has quit ["Leaving IRC - dircproxy 1.1.0"]
Snark has joined #ocaml
<Snark>
slt
Snark has quit [Read error: 104 (Connection reset by peer)]
<simon->
blt
Snark has joined #ocaml
<[1]platypus>
what does this mean ??
<[1]platypus>
in_channel -> buf:string -> pos:int -> len:int -> int
<CiscoKid>
It's labeled.
<[1]platypus>
i am reading the manual and it says this :
<[1]platypus>
Read len characters from the given channel, storing them in string buf, starting at character number pos. Raise End_of_file if the end of file is reached before len characters have been read. Raise Invalid_argument "really_input" if pos and len do not designate a valid substring of buf.
<[1]platypus>
but what i don understand is ... how do i change the value of len ??
<[1]platypus>
i mean say i want it to read till the length 5, how do i do it
<CiscoKid>
Set the length to 5.
<[1]platypus>
how ?
<CiscoKid>
How are you using a value other than 5 now?
<simon->
platypus, did you read any tutorials at all?
<[1]platypus>
simon-, i did
<[1]platypus>
well i did this : i open up a file using open_in ... so it gave me a in_channel type
<[1]platypus>
then i sent the in_channel to be used by really_input
<CiscoKid>
OK, which part of the manual are you reading to get a labeled really_input? Pervasive's isn't labeled.