flux changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | Grab OCaml 3.10.2 from http://caml.inria.fr/ocaml/release.html (featuring new camlp4 and more!)
Jessehk has joined #ocaml
Jessehk has left #ocaml []
pants1 has joined #ocaml
mtrimpe has quit []
mfp_ has joined #ocaml
mfp has quit [Read error: 110 (Connection timed out)]
Jedai has quit [Read error: 113 (No route to host)]
Morphous_ has joined #ocaml
jlouis has quit [Remote closed the connection]
Ched- has joined #ocaml
Morphous has quit [Read error: 110 (Connection timed out)]
Ched has quit [Read error: 110 (Connection timed out)]
pants1 has quit ["Leaving."]
seafood has joined #ocaml
seafood has quit [Read error: 104 (Connection reset by peer)]
seafood has joined #ocaml
seafood has left #ocaml []
seafood has joined #ocaml
seafood has quit []
Associat0r has quit []
zbrown has joined #ocaml
seafood has joined #ocaml
Consul has joined #ocaml
shortc|desk is now known as shortcircuit
shortcircuit is now known as shortc|desk
seafood has quit []
johnnowak has left #ocaml []
love-pingoo has joined #ocaml
bluestorm has joined #ocaml
LordMetroid has joined #ocaml
Tetsuo has joined #ocaml
filp has joined #ocaml
hkBst has joined #ocaml
Linktim has joined #ocaml
Tetsuo has quit [Read error: 104 (Connection reset by peer)]
Jedai has joined #ocaml
Yoric[DT] has joined #ocaml
LordMetroid has quit [Connection timed out]
ofaurax has joined #ocaml
gildor has quit [Read error: 110 (Connection timed out)]
LordMetroid has joined #ocaml
sponge45 has joined #ocaml
ofaurax has quit ["Leaving"]
tails has joined #ocaml
<tails> hi, i have a strange problem with polymorphic functions, can you help?
<tails> let negate x = -x;;
<tails> let foo = negate 1;;
<tails> let bar = negate 1.;;
<tails> the last line gives an error that i try to use a float where an integer is expected
<tails> compiled under F#, but hopefully this isn't a problem
<flux> (-) isn't a polymorphic function in ocaml
<tails> so, the compiler infers that negate is (int->int) the first time it sees it used?
<flux> yes
<tails> and it can't compile an appropriate overload?
<flux> ocaml doesn't have overloading
<tails> okay, i need polymorphic negation
<tails> what can i do?
<flux> you could always associate your number with the group of operations you can perform on it
<flux> such as (1, integer), where integer can have a set of operations one can perform on integers
<flux> the function signatures could be: val negate ('a * 'a operations) -> 'a
<tails> right, and i have the same problem when comparing numbers with 1, 0, a suitable epsilon value, etc.
<tails> i can stuff the appropriate values into such traits types associated with the value
<tails> at the base level, my problem is that i can't write a polymorphic negate or abs function that operates with primitive types
<tails> and i can't find any information how i could do such a thing
<tails> hasn't someone thought about this?
<flux> I think it's quite a rare need
<flux> not many things you can do with floats map nicely into integers
<flux> however, the same problem arises with int, int32, int64 etc
<flux> for that purpose there is something in ExtLib
<tails> let abs x = if x < 0 then -x else x;;
<tails> how can that be made polymorphic?
<tails> and not (int->int0
<bluestorm> it cannot
<tails> ...
<bluestorm> let custom_abs lower_than zero change_sign x = if lower_than x zero then change_sign x else x
<tails> plus a dozen of curried cuctom_abs'es for specific types
<bluestorm> yeah, int and float :p
<tails> i've seen that in F# you can do a match on the type of 'a
<bluestorm> ocaml does not provide ad hoc polymorphism
<tails> i guess that's my best bet for a concise polymorphic abs...
<bluestorm> why do you need a polymorphic abs anyway ?
<tails> for writing generic code
<bluestorm> use a functor
<tails> that implements the abs operation?
<bluestorm> hm
<bluestorm> use a functor taking as parameter a module implementing the numerical operations
<bluestorm> i've done a small experiment in that direction : http://bluestorm.info/ocaml/numeric/numeric.mli.html
<bluestorm> ( and .ml , similar URL )
<bluestorm> (other people have done that too and it has been partly integrated in a still-in-development "standard library on steroids" project )
<tails> ic, so it's a project in development..
<tails> sigh..
<tails> awright, thanks
<tails> at least it's not something obvious that i've missed
<bluestorm> tails: you can implement that yourself if you want
<bluestorm> see http://bluestorm.info/ocaml/numeric/numeric.ml.html , the implementation is quite straightforward
<bluestorm> it would not be difficult to do something like that, tailored for your specific needs
<bluestorm> (as you can see, my module implement the abs operation, but you could deduce it from compare, zero and sub)
<flux> there will be a performance hit, though
<flux> I'm not sure how big one
<bluestorm> flux: i've done measurements and the answer is : not much for non-native (int and float) types
<tails> if the function calls get inlined, then there's no problem
<bluestorm> the problem is with the type-specific specialization of the generic functions
<bluestorm> wich do not occur in a functorized settings, and for some specific codes provide a comfortable performance improvement
<tails> well, thanks all, i might as well go see how F# implements type matching
tails has quit ["the printf() fanclub"]
<bluestorm> ...
<bluestorm> brain-dead tentative spotted
Associat0r has joined #ocaml
Associat0r has quit [Read error: 104 (Connection reset by peer)]
mfp_ is now known as mfp
Associat0r has joined #ocaml
zimbatm has joined #ocaml
love-pingoo has quit [Read error: 110 (Connection timed out)]
general has joined #ocaml
<general> Can anybody point me to resources where I can learn OCaml (along with some theory about functional programming)? I only know C and Python, and have only a layman's idea about how functional programming languages work.
<general> bluestorm: I've seen that manual. Is it enough for a clueless newbie (that's where I'd place myself)?
<bluestorm> hm
<bluestorm> the ocaml manual is not
<bluestorm> on the other hand, my links point to numeral different tutorials
<bluestorm> hm
<general> Oh. Let me look.
<general> Whoa. How come I missed this page? Thanks :)
<bluestorm> there is also http://www.ocaml-tutorial.org/ and http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf (wich iirc is not in the documentation index, and from what i heard is quite good )
<bluestorm> if you're really into theory, http://caml.inria.fr/pub/docs/u3-ocaml/index.html could be a good choice
LordMetroid has quit ["Leaving"]
<general> bluestorm: Since you guys are OCaml programmers, I'd like to know where *you* learnt from. And another thing. I hope the OCaml language hasn't changed much, since a couple of those tutorials are pretty old (2001-2003).
LordMetroid has joined #ocaml
<bluestorm> i learned with http://caml.inria.fr/pub/docs/oreilly-book/index.html , and i think it's one of the best choice for starts, with the Jason Hickey books ( cs134b/book.pdf )
<bluestorm> general: none of these tutorials are really outdated
<bluestorm> there has been little change to the language, but they concern quite advanced parts
<general> That Jason Hickey book says it's from 2008.
<bluestorm> yeah, it's a recent rework from an older tutorial
<general> By the time I reach the advanced parts, I'm sure I'll have seen enough code to be able to comprehend the official reference. I'll be at this a long long time, if I start :)
<bluestorm> if you're new to functional programming, you'll have a hard (and delightful) time with the basis of the language ( expressions, recursion, typing, pattern matching ) wich have not changed at all
<bluestorm> ah, and you should not try to pick the object oriented part first, even if you're used to other object oriented languages : it's vastly different and probably quite difficult if you're not used to the rest of the language
<general> As you say. Actually, I want to learn some sort of a functional language before my college begins, even a small part will do.
<general> I'm torn between Haskell, Erlang and OCaml.
<general> Oh, and Lisp.
<bluestorm> hm
<bluestorm> depends on how much different from what you know you want it to be
<bluestorm> i think OCaml is a good choice
<general> Just different enough from C++ and Java. In India, they don't touch FP in college.
<general> All they want to do is produce code monkeys for offshoring jobs.
<bluestorm> Haskell is too different imho : you'll have to get all the idea of functional programming that are inside OCaml, plus some more due to purity (monads) and lazyness, all at the same time
<bluestorm> on the other hand Erlang is simpler (no static typing and poor pattern matching), but you get less benefits from learning it at the same time :p , and it specialized in a, well, specialized area, concurrent programming
<general> I heard about OCaml when a guy turned up with a raytracer in some 100 lines. Pretty neat, that :)
love-pingoo has joined #ocaml
<bluestorm> i think OCaml is a good place to start. If you get the basis, you'll be able to learn Erlang quickly, and it will reduce the effort of learning Haskell
<general> Okay then. I'll check out all those books and find out what fits me. Thanks :)
general has left #ocaml []
Morphous_ is now known as Amorphous
LordMetroid has quit [Connection timed out]
filp has quit ["Bye"]
pango has quit [Remote closed the connection]
marmotine has joined #ocaml
pango has joined #ocaml
LordMetroid has joined #ocaml
zbrown has left #ocaml []
arquebus has joined #ocaml
arquebus has quit [Remote closed the connection]
\banlist is now known as masterlinux
silentbicycle has joined #ocaml
silentbicycle has left #ocaml []
tomh has joined #ocaml
Associat0r has quit [Read error: 104 (Connection reset by peer)]
Kopophex has joined #ocaml
Associat0r has joined #ocaml
<palomer> http://ocaml.pastebin.com/m7d406603 <--how can I do something like this?
rwmjones has joined #ocaml
<mfp> palomer: type a = [`A]
<mfp> # let bar (x : [`A | `B]) = match x with `B -> () | #a as y -> foo y;;
<mfp> val bar : [ `A | `B ] -> unit = <fun>
Ched- has quit [Remote closed the connection]
munga has joined #ocaml
<palomer> WHOA
<palomer> you can do that??
<palomer> what does that syntax mean?
Ched- has joined #ocaml
jlouis has joined #ocaml
<Smerdyakov> palomer, behold the manual!
Linktim has quit ["Quitte"]
munga has quit ["Ex-Chat"]
mfp has quit [Remote closed the connection]
Smerdyakov has quit ["Leaving"]
Smerdyakov has joined #ocaml
Yoric[DT] has quit ["Ex-Chat"]
LordMetroid has quit ["Leaving"]
love-pingoo has quit [Remote closed the connection]
zimbatm has quit ["Ex-Chat"]
sponge45 has quit ["see you at http://ocamlhackers.ning.com/"]
bluestorm has quit ["Konversation terminated!"]