hedonick has quit ["ircII2.8.2-EPIC3.004 --- Bloatware at its finest."]
mrvn_ is now known as mrvn
pattern_ has joined #ocaml
rhil|food is now known as rhil|zzz
New2Python has left #ocaml []
Smerdyakov has quit []
gene9 has joined #ocaml
davinci has joined #ocaml
davinci has left #ocaml []
pattern_ has quit [leguin.freenode.net irc.freenode.net]
pattern_ has joined #ocaml
lus|wazze has quit ["sul °°"]
lam has quit [leguin.freenode.net irc.freenode.net]
lam has joined #ocaml
phubuh has joined #ocaml
gene9 has quit [Connection reset by peer]
gene9 has joined #ocaml
Yurik has joined #ocaml
mattam has quit [Read error: 54 (Connection reset by peer)]
mattam has joined #ocaml
gene9 has quit [Read error: 110 (Connection timed out)]
systems has joined #ocaml
systems has quit ["Client Exiting"]
Smerdyakov has joined #ocaml
mattam_ has joined #ocaml
Smerdyakov has quit []
Smerdyakov has joined #ocaml
Smerdyakov has quit ["go"]
mattam has quit [Read error: 110 (Connection timed out)]
CybeRDukE has joined #ocaml
mrvn_ has joined #ocaml
owll has joined #ocaml
mrvn has quit [Read error: 110 (Connection timed out)]
lus|wazze has joined #ocaml
asquii has joined #ocaml
asqui has quit [Read error: 60 (Operation timed out)]
asquii is now known as asqui
owll has quit ["Client Exiting"]
pattern_ has quit ["..."]
pattern_ has joined #ocaml
foxster has quit [Read error: 104 (Connection reset by peer)]
foxen has joined #ocaml
Breeder has joined #ocaml
<Breeder> can anyone help me? I have this expression function f -> (function x -> (f (x +. 1.0))*10);;
<Breeder> and the type is (float -> int) -> float -> int = <fun>
<Breeder> what means that type? I know it is a basic question but I'm no understanting it :-\
<phubuh> a function taking [a function taking a float returning int] and a float, returning int
<phubuh> actually, a function taking [a function taking a float returning int] returning [a function taking a float returning int]
<Breeder> :-\ I'm going to have an exam but I'm having difficulties about found the type of an expression
<Breeder> any tutorial online about this?
thomas001 has joined #ocaml
<thomas001> hi
<thomas001> how to do bitschifts in ocaml?
<phubuh> << is lsl, >> is lsr
<phubuh> Breeder: foo -> bar is a function taking foo and returning bar
<thomas001> # 16>>2;; Unbound value >> ?
<phubuh> foo -> bar -> baz groups as foo -> (bar -> baz), hence a function taking foo and returning another function which takes bar and returns baz
<phubuh> thomas001: oh, i meant lsl is ocaml for left bitshift, lsr is ocaml for right
<thomas001> oh thx phubuh
<thomas001> are there any switches to ocamlopt to optimize more? like gcc's -O2 -O3 ?
<phubuh> well, there's -unsafe
<phubuh> generally, ocaml doesn't really do "unsafe" optimizations (it doesn't need to, as it is more high-level than C), so it just does whatever it can
<mrvn_> -unsafe eliminates the tests for string and array out of bound exceptions for example.
CybeRDukE has quit ["Programmers never die: They just GOSUB without RETURN."]
<thomas001> no options for inlining functions nor sth like that?
<mrvn_> ocaml already does that
<phubuh> it does inline functions
<thomas001> ok
<mrvn_> you can change the amount of inlining
<phubuh> although it is rather conservative about it, to prevent thrashing the cache, among other things
<thomas001> another different thing: what is the relation between OCaML and SML ?
<thomas001> do SML programs work with ocaml and vice versa ?
<phubuh> nope
<phubuh> they share heritage, in that they're both dialects of ML
<thomas001> the question which one is better is senseless,isn't it ?
<phubuh> somewhat. i do find that the advantages of ocaml outweighs the benefits of sml though, but what else would you expect from someone in #ocaml :-)
<thomas001> has sml some kind of object system?
* Riastradh likes some things in both.
<phubuh> thomas001: no, not really
<Breeder> this is very hard to understand :-(
<phubuh> have you done any functional programming before ocaml?
<Breeder> no :-\
<Breeder> only imperative languages
<phubuh> you're supposed to find it confusing then :-)
<Riastradh> The confusion is the last dying attempts of imperative concepts to infest your brain.
<Breeder> i cant even get the types out of and expression :-\, prolog was hard too i just know some basics
<Riastradh> 'Can't even get the types out of an expression?' What do you mean?
<Breeder> function f -> function x -> (f x)=x;;
<Breeder> i know this is basic stuff and that is what bothers me most :-\
<Riastradh> Are you trying to determine by hand what the type of that is?
<Breeder> yes this stuff appers in the exam :-\
<Riastradh> Would you like some help?
<Breeder> yes, i would like be able to read it
<Riastradh> OK, first of all, how do you notate the type of a function?
<Breeder> from the operations after the ->
<Riastradh> No, no, not 'determine' but 'notate.'
<Riastradh> e.g., you notate addition with 'addend + addend'
<phubuh> addend + augend :-)
<Riastradh> Bah, whatever.
<Riastradh> You notate exponentiation with base^exponent. How do you notate the type of a function?
<Breeder> f x?
<Riastradh> No, that's a function application.
<Riastradh> How would you write the type of a function that takes an int and returns a bool?
<Breeder> function f -> x=x for example
<Riastradh> (e.g., in C, you might write (supposing there were a real 'bool' type in C): 'bool (*)(int)')
<Riastradh> No, that's the syntax for writing functions, not the -types- of functions.
<Breeder> int -> bool
<Riastradh> Yes, yes.
<phubuh> bingo!
<thomas001> a pointer?
<thomas001> type t = (int -> bool) ref;; ?
<Riastradh> thomas001, irrelevant, don't confuse him.
<thomas001> sry
<Riastradh> Now, the type of the function 'function f -> function x -> f x = x' is going to be '<something> -> <something>'. The first <something> we'll deal with later.
<Riastradh> What does the function return? -- suppose you did: let g = function f -> function x -> f x = x;; What would 'g quux' return?
<Breeder> a bool
<Riastradh> No.
<thomas001> depends on what quux it?
<Breeder> a function taking something and returning a bool
<Riastradh> Yes.
<Riastradh> How do we notate it now?
<Breeder> 'a-> bool
<Riastradh> We've gotten the '<something> -> <something>' bit, and now we're filling in the second <something>.
<mrvn_> No. '_a -> bool
<Riastradh> No, no, how do we notate the whole function?
<mrvn_> and not even that since guux provides the '_a
<thomas001> if quux is not polymorphic why is the result of the function ?
<thomas001> (of g)
<mrvn_> g : ('a -> 'a) -> 'a -> bool
<Riastradh> Ignore polymorphic stuff for now.
<Riastradh> Damnit, mrvn!
<Breeder> that last part is correct but what about the first
<thomas001> mrvn_: if quux is int -> int, (g quux) whould be int -> bool ?
<mrvn_> Riastradh: didn't you ask me?
* Riastradh gets disgusted and wanders away.
<Riastradh> No, I was trying to explain this to Breeder.
<mrvn_> thomas001: Thats what g : ('a -> 'a) -> 'a -> bool says.
<thomas001> mrvn_: i meant no 'a and no '_a
<mrvn_> thomas001: The type of guux detemines what 'a is.
<thomas001> k
<mrvn_> in your example int.
<Breeder> we have then <something> -> <something>, the second something is 'a->bool correct? now the first something :-(
<mrvn_> Breeder: not exactly.
<mrvn_> The 'a depends on the first something
<mrvn_> or the first something on the 'a
<Breeder> from where do you start the interpretation of the expression?
<mrvn_> I? Inside out.
<Breeder> 'function f -> function x -> f x = x'
<mrvn_> function f -> function x -> f x = x
<mrvn_> f : 'a, x : 'b
<mrvn_> The you look at "f x"
<mrvn_> 'a is of form 'c -> 'd
<mrvn_> f: 'c -> 'd, x : 'b
<mrvn_> You follow that?
<thomas001> why am i getting different assembly code when replacing lsr 1 with / 2 ? compiled with -unsafe
<mrvn_> thomas001: different for negative numbers
rhil|zzz is now known as rhil
<thomas001> hmm
<Breeder> not quite, from what i understand f x means f taking parameter x right?
<thomas001> a lsr on negative numbers is defined ?
<phubuh> # -1 lsl 1;;
<phubuh> - : int = -2
<mrvn_> Breeder: Firstly it means f is a function
<phubuh> however, # -1 / 2;;
<phubuh> - : int = 0
<thomas001> oh k
<mrvn_> thomas001: do you mean lsr or *2?
<phubuh> err, that example is incorrect
<Breeder> yes and have x as parameter
<mrvn_> Breeder: thats the next step.
<phubuh> of course i mean * 2, and they both produce the same value
<thomas001> mrvn_: i mean >> ;)
asqui has quit [Read error: 60 (Operation timed out)]
<mrvn_> thomas001: >>1 != /2
<mrvn_> f : 'c -> 'd takes an x : 'b ==> 'b = 'c
<phubuh> this is what's interesting; -5 lsr 1 = 1073741821 and -5 / 2 = -2
<mrvn_> f: 'b -> 'd, x : 'b
<thomas001> mrvn_: for all possitive ints it is
<mrvn_> thomas001: which ocaml has no type for.
<mrvn_> Breeder: folloed that?
<thomas001> mrvn_: C doesn't care if signed or not it's the same operation...
<mrvn_> thomas001: no.
<mrvn_> thomas001: C does exactly the same.
<mrvn_> thomas001: Thats why you have lsr and asr
<Breeder> my mind is switched to imperative :-\
<thomas001> mrvn_: which one is >> ?
<mrvn_> thomas001: depends on the signedness
<mrvn_> iirc
<mrvn_> int a = -5;
<mrvn_> printf("%d %d\n", a>>1, a/2);
<mrvn_> -3 -2
<thomas001> hmm your right
<mrvn_> >> is not /2
<Breeder> how do you evaluate (the steps you take) this expression function x -> 2::x (int list -> int list)
<thomas001> it uses shr for unsigned and sar for signed ...
<mrvn_> x: 'a, 2::x ==> x: int list, function x -> 2::x ==> int list -> int list
<thomas001> mrvn_: but i once learned bitshifts are a cheap replacement for /2 and *2; and that worked quite well in all C/C++ programs i wrote
<phubuh> still, since ocaml doesn't have unsigned/signed, it would be an error to optimize > 1 to / 2
<thomas001> btw:i never tried to shift negative numbers...
<mrvn_> thomas001: only for positive numbers
<thomas001> mrvn_: thats all i need
<lus|wazze> ?
<lus|wazze> why phubuh
<lus|wazze> bitshifts can be done both on signed an unsigned integers as well
<mrvn_> 10: 89 c2 mov %eax,%edx
<mrvn_> 12: c1 ea 1f shr $0x1f,%edx
<mrvn_> 15: 01 d0 add %edx,%eax
<mrvn_> 1d: d1 f8 sar %eax
<phubuh> read the conversation, -5 lsr 1 <> -5 / 2
<mrvn_> That is int a; a/2
<lus|wazze> thats true
<lus|wazze> thats because for signed numbers you have to use the arithmetic bitshift
<phubuh> yes
<lus|wazze> i.e. it uses a different method for filling the shifted bits
<mrvn_> signed / 2 differes from >> for negative numbers.
<lus|wazze> x / (2**y) == x asr y
<lus|wazze> no
<thomas001> hmm
<lus|wazze> there are three shifting operations
<mrvn_> lus|wazze: only for unsigned
<lus|wazze> nope
<lus|wazze> asr != lsr
<lus|wazze> thereare actually three kinds of bit-shifting operations:
<lus|wazze> the logical left-shift
<lus|wazze> the logical right-shift
<mrvn_> -5/2 = -2, -5 >> 1 = -3
<lus|wazze> and the arithmetic right-shift
<lus|wazze> hmm
<lus|wazze> the rounding is different?
<phubuh> # -5 lsr 1;;
<phubuh> - : int = 1073741821
<mrvn_> division rounds different than shifts.
<thomas001> gcc optimizes /2 to sarl $1,%eax
<thomas001> for signed integers
<mrvn_> thomas001: no.
<mrvn_> 10: 89 c2 mov %eax,%edx
<mrvn_> 12: c1 ea 1f shr $0x1f,%edx
<mrvn_> 15: 01 d0 add %edx,%eax
<lus|wazze> well then it depends on what the language spec says about rounding in integer division
<mrvn_> 1d: d1 f8 sar %eax
<mrvn_> Thats a /2 for int.
<lus|wazze> SHOULD /2 round downwards, towards zero, or what?
<mrvn_> lus|wazze: thats upwards.
<lus|wazze> -5 >> 1 = -3 is downwards rounding
<mrvn_> lus|wazze: yes.
<mrvn_> but / rounds towards 0
<thomas001> wow sry for starting this
<lus|wazze> well then it is an error
<mrvn_> A lot of optimisation C could do breaks down for a few special cases, like negative numbers or very big (near MAX_INT) numbers.
<lus|wazze> maybe doing a TEST eax,1 JNZ blubb SHR eax,1 would still be faster than a DIV
<mrvn_> lus|wazze: a JUMP? are you nuts?
<lus|wazze> as long as it is correctly predicted and inside the cache?
<lus|wazze> hmm
<mrvn_> lus|wazze: gcc does a/2 = (a+(a>>31))>>1
<lus|wazze> im not sure how good the prediction in x86 processors is but as there are no hints youre probably right
<lus|wazze> ic
<mrvn_> it adds 1 for negative numbers and then shifts
<thomas001> land 1 = mod 2 ? ;-)
<mrvn_> One should use unsigned for unsigned ints so the compiler can optimize better.
<mrvn_> Too bad ocaml has only one int type.
<lus|wazze> how is integer division supposed to round in ocaml?
<mrvn_> towards 0 I think.
<lus|wazze> thomas: in lisp there are TWO different modulo operations, for one of which your equation holds :)
<mrvn_> the mathematical way.
<thomas001> lus|wazze: and in ocaml? ;)
<lus|wazze> i dunno
<thomas001> lus|wazze: i'm to a lisp fan
<thomas001> to=not
<lus|wazze> well i dont really associate fandom wth programming languages
<lus|wazze> i look at them to see what they might be useful for
<lus|wazze> so far ive found few languages which are completely useless and none which are useful for every task
<thomas001> which ones are useless?
<lus|wazze> cobol
<lus|wazze> ^^
<thomas001> lol
<lus|wazze> why? don't you agree? :]
<mrvn_> Gotta reboot. *wave*
<thomas001> i never looked at cobol
<lus|wazze> well i didnt look into it too thoroughly either :/
<mattam_> an advice: don't
<lus|wazze> well i looked at it just long enough to figure out that theres nothing it might be more useful for than some other language, i.e. that theres no reaso nto use it, ever ^^
<mattam_> except when paid for, remind it
<lus|wazze> ?
<mattam_> there is a CLR (.net) compiler for COBOL even, so some still write in/use this language
<lus|wazze> remind it <--- that doesnt make any sense whatsoever :|
<mattam_> remember that maybe ?
<lus|wazze> yeah i know that is is being used ... that doesnt mean at all that it SHOULD be used though :)
<mattam_> someone could hire you (well, me at least) to write COBOL
<mattam_> and that's one of the worst things that can happen to you (or me)
asqui has joined #ocaml
<lus|wazze> well id argue that they shouldnt hire anyone to write cobol code but rather hire someone to solve their task in a better language :p
<mattam_> someone should have wrote a "COBOL considered harmful" paper a long time ago
<lus|wazze> ? they havent?
<mattam_> no, it is still teached
<mattam_> how would i know this language otherwise ? :)
<lus|wazze> well probably the fact was assumed too trivial to be worth having a paper being written about it
<lus|wazze> :0
<lus|wazze> "COBOL considered harmful: reasons left to the reader as an exercise" ;|
phubuh has quit [Remote closed the connection]
foxen has quit [Broken pipe]
foxster has joined #ocaml
rhil is now known as rhil|out
phubuh has joined #ocaml
phubuh has quit ["Client exiting"]
phubuh has joined #ocaml