<archie_sihir>
i am confused about some ocaml syntax ...
<archie_sihir>
this function :
<archie_sihir>
# let sum i =
<archie_sihir>
let sum2 j =
<archie_sihir>
i + j
<archie_sihir>
in
<archie_sihir>
sum2;;
<archie_sihir>
val sum : int -> int -> int = <fun>
<archie_sihir>
# sum 3 4;;
<archie_sihir>
- : int = 7
<archie_sihir>
how does it know that 4 is supposed to be for sum2 ?
<mellum>
I don't understand the question.
<Kinners>
sum 3 returns a curried function (sum2), with i bound to 3
<Kinners>
does that sound right?
<archie_sihir>
hmmm
<archie_sihir>
yeah
<archie_sihir>
wat is a curried function ?
<Kinners>
I don't know the exact definition, maybe a function that returns another function
<Kinners>
let sum i j = i + j can also be written as let sum = fun i -> fun j -> i + j
<archie_sihir>
ok ...
<Kinners>
they're the same basically
<archie_sihir>
Kinners: what do you use ocaml for ?
<Kinners>
so if you partially apply that sum function (sum 3), then you get a function in return, fun j -> i + j where i is 3
<Kinners>
not a lot at the moment, still learning :)
<archie_sihir>
=)
<Kinners>
and just about to send in a patch for compiling ocaml in qnx
<archie_sihir>
Kinners: what bg do you come from ?
<Kinners>
a C & various scripting languages background
<archie_sihir>
i come from a python bg
<archie_sihir>
# let is_uppercase = funct
<archie_sihir>
'A' .. 'Z' -> true
<archie_sihir>
| c -> false;;
<archie_sihir>
what is 'c' here ?
<Kinners>
c is set to the value that is being matched, in thise case it's not needed and _ could be used instead
<archie_sihir>
Kinners: does your ocaml installation have readline support ?
<archie_sihir>
i am using the interpreter and not being able to use the up key to see my previous command is pissin' me off
<Kinners>
there's no builtin readline support (licence problems), you can try a line editor like ledit or maybe a readline line editor like rlwrap
foxster has quit []
TachYon has joined #ocaml
mattam has joined #ocaml
Kinners has left #ocaml []
giedi has joined #ocaml
Smerdyakov has quit [calvino.freenode.net irc.freenode.net]
stefp has quit [calvino.freenode.net irc.freenode.net]
phubuh has quit [calvino.freenode.net irc.freenode.net]
wax has quit [calvino.freenode.net irc.freenode.net]
TachYon has quit [calvino.freenode.net irc.freenode.net]
lament has quit [calvino.freenode.net irc.freenode.net]
smkl has quit [calvino.freenode.net irc.freenode.net]
asqui has quit [calvino.freenode.net irc.freenode.net]
gl has quit [calvino.freenode.net irc.freenode.net]
lam has quit [calvino.freenode.net irc.freenode.net]
mattam has quit [calvino.freenode.net irc.freenode.net]
Riastradh has quit [calvino.freenode.net irc.freenode.net]
TachYon has joined #ocaml
lament has joined #ocaml
smkl has joined #ocaml
asqui has joined #ocaml
lam has joined #ocaml
gl has joined #ocaml
mattam has joined #ocaml
Smerdyakov has joined #ocaml
stefp has joined #ocaml
phubuh has joined #ocaml
wax has joined #ocaml
Riastradh has joined #ocaml
phubuh has quit [calvino.freenode.net irc.freenode.net]
stefp has quit [calvino.freenode.net irc.freenode.net]
Smerdyakov has quit [calvino.freenode.net irc.freenode.net]
wax has quit [calvino.freenode.net irc.freenode.net]
mattam has quit [calvino.freenode.net irc.freenode.net]
Riastradh has quit [calvino.freenode.net irc.freenode.net]
mattam has joined #ocaml
Smerdyakov has joined #ocaml
stefp has joined #ocaml
phubuh has joined #ocaml
wax has joined #ocaml
Riastradh has joined #ocaml
smkl has quit [Remote closed the connection]
smkl has joined #ocaml
asqui has quit [Excess Flood]
smkl has quit [Read error: 104 (Connection reset by peer)]
smklsmkl has joined #ocaml
asqui has joined #ocaml
TachYon has quit [Remote closed the connection]
Ph4tB0y_2k has joined #ocaml
lament has quit [Read error: 110 (Connection timed out)]
gene9 has joined #ocaml
Ph4tB0y_2k has quit ["Client exiting"]
<archie_sihir>
what is this about : x::l-fx::map fs;;
<archie_sihir>
what is this about : x::l-fx::map fl;;
TachYon26 has joined #ocaml
Kinners has joined #ocaml
<archie_sihir>
Kinners: what is this about ? # let rec map f = function
<archie_sihir>
[] -> []
<archie_sihir>
| x :: l -> f x :: map f l;;
<Kinners>
ah, getting into the nitty gritty now :)
<Kinners>
map is a recursive function taking two arguments, the second is used in the implicit pattern match that you get by using function
<Kinners>
let rec map f l = match l with [] -> [] | ... is the same
<Kinners>
x :: l matches the head and tail of a list, the head is bound to the name x and the tail to l (the tail can be empty)
<Kinners>
:: is a list constructor (of a type 'a -> 'a list -> 'a list)
<Kinners>
got that?
<archie_sihir>
hang on
<archie_sihir>
x::l
<archie_sihir>
means x is the first element of the list and l is the last ?
<phubuh>
x is the first and l is everything after it
<phubuh>
so x is a single type and l is a list
<archie_sihir>
so what does x::l->fx::map fl;; do ?
<phubuh>
f x applies the function f with the argument x. a::[b;c] is [a;b;c]. so you apply the function passed to the first element of the list, and return a list with that result as the first, and the rest is the result of calling map with the rest of the list and the same function
<phubuh>
so if you pass fun x -> x + 1 (a function that returns its argument plus 1), and the list [1; 2; 3], this is what will happen
<phubuh>
the second case matches, and binds x to 1 and l to [2; 3]
<phubuh>
then f x is computed, which is 1 + 1; 2. then the function calls itself, but with [2; 3] as the list instead of [1; 2; 3]
<phubuh>
in this scope, x is 2 and l is [3] (a list with one element). f x is computed to 3, and then we go all over again
<phubuh>
x is 3 and l is []. f x is 4, and we go all over again
<phubuh>
but this time, the first case matches, since the list is empty, so it just returns an empty list instead of going all over again
<phubuh>
now we're back in the previous one, and we have the result it will return: 3 :: [], which is [3]. now we return yet again to the yet previous one
<phubuh>
wait, what the hell
<phubuh>
oh, of course, it will return [4], not [3], silly me
<phubuh>
anyway, it returns all of the way until the result is [2; 3; 4]
<archie_sihir>
# let rec mem x l =
<archie_sihir>
match l with
<archie_sihir>
[] -> false
<archie_sihir>
| y :: l -> x = y || mem x l;;
<archie_sihir>
so this one the second case matches y::l ?
<archie_sihir>
what is that ?
<archie_sihir>
i really don't get this part
<archie_sihir>
what is y ?
<archie_sihir>
anything not matched in the first part?
<phubuh>
only the empty list is matched in the first part, y is just like x in the map function
<phubuh>
the names are arbitrary
<phubuh>
y :: l matches a list of one element or greater and binds y to the first and l to the rest
<archie_sihir>
phubuh: from the command which part says that it's a list of one element of greater ?
<archie_sihir>
?
<Kinners>
if it was empty it would be matched by the empty list
<Kinners>
and a :: b implies a list that has to have at least one element
<archie_sihir>
oh ..
<archie_sihir>
then ->x=y||mem x l
<archie_sihir>
means that it returns a bool right
<Kinners>
yes
<archie_sihir>
the boolean btwn x which is bound to the first element of the list
<archie_sihir>
and the function mem of x l
<archie_sihir>
why does it want to do that ?
giedi has quit [Remote closed the connection]
<Riastradh>
mem tests if that element is found in a list.
<Riastradh>
If it didn't call itself again, then it would only test the first element.
<archie_sihir>
sure does a lot of things for such a terse function
<archie_sihir>
that '||' is a or right ?
<Riastradh>
Yes.
<archie_sihir>
so the it returns the boolean of ( if (first arguement=y or the function mem with the x and l arguements ))
<archie_sihir>
so if the first aguement which is x matches y then it returns true
<Riastradh>
Right.
<archie_sihir>
if it doesn't ...
<archie_sihir>
then now it depends on mem x l
<archie_sihir>
when called again now ...
<Riastradh>
l, remember, has been shadowed by the pattern matching clause -- 'y :: l' -- so it now refers to the rest of the list.
<archie_sihir>
oh !
<archie_sihir>
so it now it's like using the mem function traversing down the list
<archie_sihir>
wow that is like really cool
<archie_sihir>
with out any for loops !
<Riastradh>
Tail-call elimination makes 'while' and 'for' and such loops completely unnecessary to be in the core language -- they can merely be syntactic sugar with camlp4 over tail-recursive functions.
<archie_sihir>
Riastradh: sorry could you explain again what y::l does ?
<archie_sihir>
Riastradh: this is like really new stuff to me
<Riastradh>
It deconstructs the list 'l'. 'y' becomes bound to the head of it and 'l' to the tail of it.
<archie_sihir>
okok
<archie_sihir>
it's clear now
<Riastradh>
It's sort of like how in maths you could say that 2 + 1 = 3, and then get 2 and 1 back from 3 by saying 3 = 2 + 1 -- the two things are the same, and you're just pulling different pieces out of it.
<archie_sihir>
is it possible to assign more to the head
<archie_sihir>
?
<archie_sihir>
i mean the first two elements ?
<Riastradh>
| y :: z :: l -> ... (* Like that? -- 'y' is now the first element, 'z' the second, and 'l' the tail *)
<archie_sihir>
thanks mate
<archie_sihir>
u really helped a lot
<archie_sihir>
hehe couldn't understand it at first
<archie_sihir>
so ... # let rec map f = function
<archie_sihir>
[] -> []
<archie_sihir>
| x :: l -> f x :: map f l;;
<archie_sihir>
means that f function is applied on the first function and
<archie_sihir>
it calls the map function on the tail
<Riastradh>
'f' is applied to the first element in its last argument.
<archie_sihir>
in it's last arguement ?
<Riastradh>
It might be easier to understand the map function were it written like this:
<Riastradh>
let rec map f list =
<Riastradh>
match list with
<Riastradh>
[] -> []
<Riastradh>
| head :: tail -> f head :: map f tail;;
<archie_sihir>
ok
systems has joined #ocaml
__DL__ has joined #ocaml
systems has quit ["Client Exiting"]
giedi has joined #ocaml
jao has joined #ocaml
gene9 has quit []
mattam has quit [Read error: 110 (Connection timed out)]
giedi has quit [Remote closed the connection]
Kinners has left #ocaml []
jao has quit ["leaving"]
_DL_ has joined #ocaml
__DL__ has quit [Read error: 104 (Connection reset by peer)]
smklsmkl is now known as smkl
mattam has joined #ocaml
Vincenz has joined #ocaml
<Vincenz>
Hello people!!!
<Vincenz>
I have a question about ocamllex
<mattam>
interresting
<Vincenz>
ah someone actually lives :)
<Vincenz>
well the question goes as follows:
<Vincenz>
rule a calls rule b
<Vincenz>
when does rule b finish and when does it go back to rule a?
<mattam>
when the { action } is reached i think
<Vincenz>
hmm oh
<Vincenz>
so how do I make it stay in rule b mode until further notice?
<mattam>
stay ?
<Vincenz>
never mind, perhaps I'm thinking of this the wrong way
<mattam>
notice ?
<mattam>
like signaling the rule to stop working at a certain moment ?
<Vincenz>
more like:
<Vincenz>
take ocaml syntax
<Vincenz>
rule token = parse
<Vincenz>
...
<Vincenz>
| "(*" {comment lexbuf}
<Vincenz>
and comment = parse
<Vincenz>
| "*)" {do nothing}
<Vincenz>
| _ {comment lexbuf} ?
<Vincenz>
is that correct?
<mattam>
should be
<Vincenz>
that however doesn't help with comments appearing in other comments (forgot the name for that)
<Vincenz>
and comment = [are
<Vincenz>
and comment = parse
<Vincenz>
| "*)" {do nothing}
<Vincenz>
| "(*" {comment lexbuf}
<Vincenz>
| _ {comment lexbuf}
<Vincenz>
:/
<Vincenz>
hmm | "*)" should probably have as action {token lexbuf} because the original token rule must return a token
<mattam>
| "(*" { (comment lexbuf) ^ (comment lexbuf) } if nested comments should be valid
<Vincenz>
(This is the first time in my life I write a lexer/compiler)
<mattam>
that would ignore the first part of the comment
<Vincenz>
I want to ignore comments
<Vincenz>
that's why
<Vincenz>
| "*)" {token lexbuf}
<mattam>
right
<Vincenz>
still doesn't do it tho
<Vincenz>
and comment = parse
<Vincenz>
| "*/"{token lexbuf}
<Vincenz>
| "/*"{comment lexbuf; comment lexbuf}
<Vincenz>
| _{comment lexbuf}
<Vincenz>
because....if I do /* /* */ it will try to token and not comment
<mattam>
it could be better to return the lexbuf with the comments and ignore them, and parse the next token in the token rule, otherwise you could have stack overflow
<Vincenz>
ah :)
<Vincenz>
found this site :)
<Vincenz>
in cmoment
<Vincenz>
"*/" {()}
<Vincenz>
in token
<Vincenz>
"/*" {comment lexbuf; token lexbuf}
<Vincenz>
:)
<mattam>
handling both well-formed and ill-formed comments is difficult
<Vincenz>
just need to take a different approach
<Vincenz>
besides, it's tailrecursive, so no stack problems
<mattam>
right
<Vincenz>
hmm, another question, if you don't mind....in comment they have "/*" {comment lexbuf; comment lexbuf} but instead of _ after they use '/' {comment lexbuf} '*' { comment lexbuf} [^'*''/']* {comment lexbuf}
<Vincenz>
perhaps that's to skip a lot of text at once?
<mattam>
you mean they have the four choices: "/*" "/" "*" and [^'*''/']* ?
<Vincenz>
yes
<Vincenz>
and "*/" of course
<mattam>
this is equivalent afaict. (they use the same action anyway)
<Vincenz>
perhaps it allows it to jump over many symbols at once
<Vincenz>
instead of one symbol at the time
<mattam>
the automaton should be the same as it recognizes the same language and they are minimized (not sure)
<Vincenz>
alright
<Vincenz>
almost done :)
<Vincenz>
all that's left is string
<Vincenz>
lexbuf is always a string, correct?
<mattam>
i think it's actually 'a lexbuf
<Vincenz>
oh
<mattam>
no, i'm wrong
<Vincenz>
it's complexer than I thought tho
<Vincenz>
Lexing.lexeme lexbuf is what I need :)
<Vincenz>
odd
archie_sihir has quit [Read error: 113 (No route to host)]
archie_sihir has joined #ocaml
<Vincenz>
do I need to specifically open my lexer? In the example in the manual they don't but he complains he doesn't know what I'm calling
<mattam>
dunno
<Vincenz>
File "driver.ml", line 5, characters 16-32:
<Vincenz>
Unbound value TigerLexer.token
<mattam>
you parsed it with ocamllex to get the ml file right ?
<Vincenz>
yes
<Vincenz>
I've got TigerLexer.ml and driver.ml
<mattam>
so the token function is in it, you should see it. (The lexer comes first in compilation order)
<Vincenz>
gives me some warnings but for the rest works fine
<Vincenz>
maybe because of the warnings
<Vincenz>
cause it doesn't generate cmo and cmi fils
<Vincenz>
it complains on line 55, and twice on 60
<mattam>
ignore() the 'coments lexbuf'
<Vincenz>
File "TigerLexer.mll", line 64, characters 43-75:
<Vincenz>
This expression has type string but is here used with type unit
Smerdyakov has quit ["reboot"]
<mattam>
do a let _ = comment lexbuf in comment lexbuf. (It has a wrong syntax when you transform to .ml otherwise)
Smerdyakov has joined #ocaml
<Vincenz>
hmm, that's not it
<Vincenz>
but odd enough it complains on this line of generated code :
<Vincenz>
| n -> lexbuf.Lexing.refill_buff lexbuf; __ocaml_lex_comment_rec lexbuf n
<Vincenz>
on the second part
<Vincenz>
I'll just return some random int
<Vincenz>
oh!
<Vincenz>
my main token returns a string
<Vincenz>
apparently it expects them all to return string now
<Vincenz>
yay!
<Vincenz>
I just added ; ""
<Vincenz>
and put ignore around them all
<Vincenz>
:)
<Vincenz>
odd tho
<Vincenz>
grr
<Vincenz>
Yay :)
<Vincenz>
it works :)
<Vincenz>
apparently if you forget something
<Vincenz>
it keeps hanging there
<Vincenz>
(I had forgotten a '\n')
<Vincenz>
time to get to step 3: a parser
<Vincenz>
then step 4: AST :)
<Vincenz>
hmm, does ocamlyacc have such things as: %prefer and %value and %verbose?
<Vincenz>
and %change
liyang_ is now known as liyang
TachYon26 has quit ["bez ki³y nie ma zaliczenia (z prawd studentek AM)"]
gorgias has joined #ocaml
<gorgias>
Hi
<gorgias>
c'est la fete ici...
<gorgias>
Est-ce quelq'un de vous peut me conseiller
<gorgias>
can anyone of you suggest me an ocaml package that does huffman encoding?
<gorgias>
...and decoding? If possible a package that does this quickly?
<gorgias>
coucou
<Riastradh>
Is this for homework?
<Riastradh>
Ou, si vous preferez le francais, est-ce que ca pour vos devoirs?
* Riastradh
pousse/prods gorgias.
TachYon has joined #ocaml
<gorgias>
Riastradh
<gorgias>
sorry, got a phone call
<gorgias>
No, this is for a research paper.
<gorgias>
check out
<gorgias>
ai1.inf.uni-bayreuth.de
<gorgias>
I would not like to go into detail before publication
<Riastradh>
Er, I don't know German.
<gorgias>
but from time to time
<gorgias>
OK. Just to make you see I am not joking
<gorgias>
I am this wolfgang m?ller guy on that site.
<gorgias>
If you want to make sure that I am not some student who is lazu
<gorgias>
lazy
<gorgias>
but rather a lazy postdoc
<gorgias>
the way to go is to drop me a mail
<gorgias>
if you want to avoid doing homework for 2nd year students
<gorgias>
;-)
<gorgias>
Anyway, I have used ocaml from time to time for doing prototypes
<gorgias>
and for some stuff I need to know how small I can get the data doing
<gorgias>
just very simple compression
<gorgias>
(cause things have to be fast)
<Riastradh>
Considering the level of optimization that the OCaml compiler is capable of, I don't think you really need to worry about programmer optimization that much.
<gorgias>
Yes, so just a simple huffman implementation would do for me :-)
<Riastradh>
Unless you've already profiled your code and found that this certain place in which you'd like to use Huffman encoding trees is the slowest and most memory-consuming place in the program.
<gorgias>
No, I think this is not the point.
<gorgias>
I have some application where gzip is not adapted
<gorgias>
and I just need the huffman
<gorgias>
so anyone who can give me one in one of my favourite languages
<gorgias>
will be thanked
<gorgias>
a lot =)
rox has quit [Read error: 60 (Operation timed out)]
<gorgias>
Concerning speed, it's only a prototype, but in the particular application I would have only
<gorgias>
a couple of clock cycles for every bit transferred
<gorgias>
(if it were not a prototype)
rox has joined #ocaml
<Riastradh>
A quick Google search brought this up:
<gorgias>
It might be uncool that it does not seem to do any bitfiddling
<gorgias>
but this you can do using an array of ints
<gorgias>
doing some nifty transformation into a list of ones and stuff
<gorgias>
Riastradh, what are you doing for/with ocaml?
* Riastradh
doesn't write much with OCaml...he prefers Scheme and Haskell.
<gorgias>
Oha.
<gorgias>
I did some Scheme exercises for a while (I was the tutor),
<gorgias>
but as things are, I never got much beyond what you need for tutoring 1st year scheme students...
<gorgias>
Why do you prefer Haskell over OCaml, and what do you do in Haskell?
<Riastradh>
I prefer Haskell's generic type system, it's more pure functionalness, and I find its syntax to be a lot more elegant.
<Riastradh>
s/it's/its/1
<gorgias>
There is something to it.
<gorgias>
I am missing in Haskell the quick and easy addition of printouts for debugging ;-)
<gorgias>
And, I got onto OCaml when I was writing a paper on holidays
<gorgias>
not a paper about holidays, but the machine
<Riastradh>
Eh, it's not that hard -- you just have to use 'do' and (>>) more often.
<gorgias>
I had with me was slooow for developing
<gorgias>
c++ compiled slowly,
<gorgias>
JAVA was not an option for memory reasons,
<gorgias>
perl was too slow,
<Riastradh>
Ewww, why did you even consider C++ and Perl?
<gorgias>
but OCaml just took twice as much mem than C++ and was fast enough
<gorgias>
At the job they call me the Perlman
<gorgias>
I mainly wrote c++ the last few years...
<gorgias>
But I liked scheme a lot when I tutored it
<gorgias>
but as a sloppy programmer I need strong types
<Riastradh>
The only thing I miss in Scheme is a strict type system.
<Riastradh>
And more standard libraries.
<gorgias>
I agree
<gorgias>
And ocaml is strong on that one
<Riastradh>
OCaml's is too strong, in my opinion; Haskell's is just right to me.
<gorgias>
I don' have enough experience. What I liked about ocaml
<gorgias>
when it compiles ---> it runs
<gorgias>
What do you recommend as haskell literature?
<Riastradh>
Haskell is like that, too, but it's much easier to get it right the first time -- functions like + work on all numbers, whereas in OCaml you have +, +., +/ for rationals or complexes or something, et cetera.
<Riastradh>
I read the 'Gentle Introduction to Haskell' and 'What the Hell are Monads?'.
<gorgias>
The former, not the latter, 2 years ago
<gorgias>
Riastradh, thanks for your suggestions, I've got to leave.
<gorgias>
Cheers
<Riastradh>
Au revoir!
<gorgias>
Au revoir
<gorgias>
\bye
gorgias has quit ["Client exiting"]
TachYon has quit ["Client Exiting"]
<Riastradh>
Argh, why can exceptions take no type parametres?
<Vincenz>
euhm they can, can't they?
<Vincenz>
exception Plop of int?
<Riastradh>
type 'a list = Cons 'a ('a list) | Nil (* 'a is the type parametre there. Exceptions can't have things like them *)
<Vincenz>
ah!
<Vincenz>
I heard there was a reason for that?
<Riastradh>
Well?
<Riastradh>
What's the reason?
pattern_ has quit [calvino.freenode.net irc.freenode.net]
pattern_ has joined #ocaml
<phubuh>
hey, can you hear me
<Riastradh>
No, but I can see what you're typing.
<phubuh>
you seem to be very certain that i am actually typing, instead of, say, using a voice recognition system
<Riastradh>
I can see what characters have been sent to your IRC client.
<phubuh>
actually, you can see what characters have been sent to _your_ IRC client
<phubuh>
my IRC client automatically ROT13s everything i say when it sends it
<Riastradh>
Weirdo.
<docelic>
yeah, you pervert.
<phubuh>
i've found that qwerty is more comfortable to type with when the input looks nothing at all like a natural language
stefp has quit [Read error: 110 (Connection timed out)]
stefp has joined #ocaml
<Vincenz>
Riastradh: as for the reason...no idea
<Riastradh>
Does OCaml have an equivalent of Lisp's COND?