<jeremy_c>
Anyone know how to convert a float to a string w/x number of decimal points? Sure, printf "%.2f" float_var, but I want to do something like to_float ~decimals:5 my_float ...
<jeremy_c>
I tried constructing a printf statement into a string, but that gave all sorts of weird compile errors
<TSC>
sprintf?
<jeremy_c>
TSC: I cannot supply a variable amount of decimal points at program run time to sprintf.
<jeremy_c>
I want to make... float_from_sql ~decimals:3 myfloat
<TSC>
Can't you build the format string at runtime?
<jeremy_c>
TSC: I couldn't make it work.
<jeremy_c>
let fmt = "%.2f" in sprintf fmt 10.123 ;; .... that does:
<jeremy_c>
This expression has type string but is here used with type
<jeremy_c>
('a -> 'b, out_channel, unit) format =
<jeremy_c>
('a -> 'b, out_channel, unit, unit) format4
<TSC>
Try using "format_of_string" to convert the string to format
<dbueno>
I probably should learn it, if I aim to be a competent ocaml programmer.
mauke has quit [Read error: 60 (Operation timed out)]
<dark_light>
yeah..
mauke_ is now known as mauke
jcreigh has joined #ocaml
<Ballin_105>
i need to finish some of my crap tonight
<dbueno>
I'm new here... what crap?
<Ballin_105>
finish im sending .........which is almost done .........i was gonna use the unix.select for getitng new messages but GTK has a better alternatvie seeitng up a GIO channel in that ..........then just add a few GUI functions and all should be good
<Ballin_105>
if i work it on really hard everyday i should get it done this week
<dbueno>
It's like a one-sided conversation....
ziggurat has quit ["Leaving"]
chessguy has joined #ocaml
<levi_home>
Ballin_105: Ada is good if you want to write highly-reliable and predictable embedded systems.
<levi_home>
Oops, I was way up in my scrollback.
chessguy has quit [" HydraIRC -> http://www.hydrairc.com <- IRC for those that like to be different"]
pango_ has joined #ocaml
<jeremy_c>
How can I determine the type of Some coming to a function? let set_age (Some 12) .... let set_age (Some "12") ?
<mauke>
huh?
<TSC>
Eh?
<jeremy_c>
let set_age (x : 'a option) = xxx
<mauke>
ok, now what?
<jeremy_c>
where xxx set's the age of a mutable var always to a int or None, regardless if it's passed a string or int value
<mauke>
you're not making sense
<jeremy_c>
I want to be able to:
<jeremy_c>
set_age (Some "12") ;
<jeremy_c>
set_age (Some 12) ;;
<mauke>
you can, but only if you also allow set_age (Some None); set_age (Some []); and all other types
<jeremy_c>
this is a class method that updates a mutable val. The mutable val "age" will always be an integer or None (int option)
<jeremy_c>
that's bad code obviously, but it's what I want to do.
<mauke>
you can't
<jeremy_c>
so then I need to add an additional method set_age_from_string
pango has quit [Remote closed the connection]
pango_ has quit [Remote closed the connection]
pango_ has joined #ocaml
ziggurat has joined #ocaml
* jeremy_c
wishes OUnit would print out expected/got on failed assert_equal's
<Ballin_105>
levi_home: Ada looks quite interesting
<levi_home>
Ballin_105: It's kind of a cleaner, stricter C++.
<Ballin_105>
levi_home: also pascal looks pretty coolio
<levi_home>
I haven't heard anyone say pascal looked cool for a LONG time.
<Ballin_105>
i dunno just something cool to try sometime
<Ballin_105>
a switch from the c/ c++ counter parts
<levi_home>
Ada is very syntactically similar to Pascal, yet far more powerful. So, stick with Ada.
<Ballin_105>
yea
<Ballin_105>
i just like to try different things
<Ballin_105>
im going to finish my jabber client in Ocaml
<Ballin_105>
then i might make something in Pascal Ada or FreeBasic or something
<Ballin_105>
lisp / erlang are pretty cool but dont compile very good and require their own libs like 8 mb
<Ballin_105>
well is there any way to try my ocaml scritps like run them easier then going to terminal etc ?
batdog|gone has joined #ocaml
<Ballin_105>
i wish that ide camelia allowed me to use more then one file inside of a file
batdog|gone is now known as batdog
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
DR_QUAT has joined #ocaml
<DR_QUAT>
hm
<DR_QUAT>
is the free book in the topic recommended for someone new to ocaml?
jewel has joined #ocaml
_velco has joined #ocaml
smimou has joined #ocaml
batdog is now known as batdog|gone
Wild_Cat has joined #ocaml
Wild_Cat has quit [Remote closed the connection]
<pango_>
jeremy_c: Printf format aren't considered strings, even if they "smell" like ones
khaladan has joined #ocaml
<pango_>
jeremy_c: they can't be created at runtime (only catenated using ^^)
<pango_>
jeremy_c: but there's a solution to your problem: Printf.sprintf "%.*f\n" 3 100.2314323
Wild_Cat has joined #ocaml
<jeremy_c>
pango_: hm.
<Ballin_105>
pango_: do you know of any way to automate the running of your ocaml app do youuse anything etc ........ its gets annoying typing ocaml dsdd.ml ggg.ml libraries etc everytime to test a script
<pango>
personally I've only used old fashioned Makefiles to date
<pango>
so I can't compare all the available solutions... maybe when I find the time
love-pingoo has quit ["Leaving"]
<Ballin_105>
also my lablgtk is not installed for opt
<Ballin_105>
hmmmmmmm
<Ballin_105>
pango: also stripping the program .......... does that effect program perforamnce or portability ?
<pango>
no
velco has joined #ocaml
_JusSx_ has joined #ocaml
b00t has joined #ocaml
Schmurtz has joined #ocaml
jewel has quit [Read error: 110 (Connection timed out)]
jewel has joined #ocaml
cognominal has quit ["Leaving"]
Demitar_ has joined #ocaml
Snark has quit ["Leaving"]
chessguy has joined #ocaml
pango has quit [Remote closed the connection]
pango has joined #ocaml
dbueno has quit ["Leaving"]
Demitar has quit [Read error: 104 (Connection reset by peer)]
Godeke has quit [Read error: 60 (Operation timed out)]
chessguy2 has joined #ocaml
chessguy has quit [Nick collision from services.]
chessguy2 is now known as chessguy
ramki has quit [Read error: 110 (Connection timed out)]
ziggurat has quit ["Leaving"]
<jeremy_c>
Ballin_105: OCamlMakefile is nice and easy, but I'm like pango, I use Makefiles as well.
<jeremy_c>
Ballin_105: best editor? Emacs, Vim or TextMate. All are very capable programmer editors. Which ever you choose, learn it very, very well. That's the secret that most people don't seem to know.
<jeremy_c>
Ballin_105: the editor is the programmers swiss army knife. Too often we use a swiss army knife with 100 blades but we only know how to use the standard, knife blade. We don't know what the others do and therefore are not at all as productive as we could be or should be.
mikeX has joined #ocaml
dbueno has joined #ocaml
b00t has quit [Client Quit]
chessguy has quit [Read error: 104 (Connection reset by peer)]
jewel has quit [Read error: 110 (Connection timed out)]
batdog|gone is now known as batdog
HS|damg has joined #ocaml
mikeX has quit ["leaving"]
lesshaste has joined #ocaml
<lesshaste>
so..why hasn't ocaml taken over the world ? :)
<lesshaste>
It seems to have the best of all worlds
<buggs>
you talk about a world ruled by DOS
chs_ has joined #ocaml
<lesshaste>
:) why do you say that?
chessguy has joined #ocaml
cjeris has joined #ocaml
Godeke has joined #ocaml
<jeremy_c>
lesshaste: because owning the world doesn't have to do with intelligence.
<lesshaste>
ah.. you mean ocaml should own the world but doesn't because people are stupid? :)
Schmurtz has quit ["L'énergie semble manquer : dodo !"]
batdog has quit []
batdog has joined #ocaml
luca83 has joined #ocaml
postalchris has joined #ocaml
damg has joined #ocaml
damg has quit [Client Quit]
smimou has joined #ocaml
velco has quit ["Ex-Chat"]
<jeremy_c>
I have two files, user_finder.ml and claim_finder.ml ... users have claims, so I have a method in user_find.ml that refs claim_finder.ml ... however, since users have claims, that means that a claim also has a user, so in claim_finder.ml I reference user_finder. How do I solve the compile problem?
HS|damg has quit [Read error: 110 (Connection timed out)]
<jeremy_c>
they are not modules, just straight .ml files. I've been accessing User_finder.by_pk (Some 10) for instance.
<postalchris>
jeremy_c: you could try adding a layer of indirection, i.e., a 3rd module that references both User and Claim
<jeremy_c>
postalchris: yuk. I was thinking it could be done through .mli files
<jeremy_c>
postalchris: if they were modules, could I solve the problem that way?
<postalchris>
jeremy_c: not sure what you mean by "if they were modules" (since everything is implicitly a module per-file), but...
<jeremy_c>
postalchris: k.
<postalchris>
what you have here are recursive data types.
<postalchris>
(though I'm not convinced (based on very little information ;-) that the recursion is really necessary)
<postalchris>
If you move the datatype decls and manipulation functions into the same module, you should be all right.
<jeremy_c>
the Claim_finder and User_finder access their Claim/User counter parts to create new instances of the classes they found rows for.
<jeremy_c>
Thus, using Claim_finder requires Claim to be included first, but Claim requires User_finder which in turn requires User first ... recursive.
<postalchris>
jeremy_c: sorry to cop out on you here, but I'm not thinking to clearly right now... I recommend a layer of indirection: e.g., returning an int user_id from claim#user so that Claim doesn't ref User directly.
<jeremy_c>
postalchris: np. thanks for the help in figuring it out. I'd prob still be spinning my wheels.
Schmurtz has joined #ocaml
Demitar_ has quit [Read error: 104 (Connection reset by peer)]
Demitar has joined #ocaml
Wild_Cat has joined #ocaml
pango has quit ["Leaving"]
pango has joined #ocaml
Wild_Cat has quit []
mauke has left #ocaml []
Schmurtz has quit [Read error: 110 (Connection timed out)]
_fab has joined #ocaml
mikeX has joined #ocaml
<flux__>
jeremy_c, yoy _may_ be able to solve that by using functors also, by parametrizing both User and Claim by Claim and User, respectively
skyde has joined #ocaml
<skyde>
hy
<skyde>
i have a question. is programming in imperative style in ocaml a mistake ?
<skyde>
i am a ruby programmer and a haskell programmer take me to ocaml for better performance and more lambda magik. but should i still program imperatively
kaspersv has joined #ocaml
<pango>
skyde: using only imperative paradigm (if at all possible in ocaml) would be a mistake imho... speed is not the only thing ocaml has to offer
<kaspersv>
hello, I'm having trouble compiling a camlp4 syntax extension, I get the following error message "Error while linking pa_while.cmo: Reference to undefined global `Plexer'" when I try to compile it
<pango>
skyde: about polymorphism, all values in ocaml have the same memory size (= one word); Either plain value for enumerated types, or pointer to an allocated block
<pango>
skyde: that's how polymorphic code can "handle" values of any type
<pango>
skyde: one bit is reserved to tell apart plain values from pointers, but it's for Gc use; Types are all determined at compile time
<pango>
for parametric code, where you'd use templates in C++, you'd probably use functors in ocaml. (mecanisms are different however, functors also relies on polymorphism internally)
Snark has joined #ocaml
<skyde>
ok tanks
mikeX has quit ["leaving"]
kaspersv has quit ["Leaving"]
skyde has quit []
Snark has quit [Remote closed the connection]
postalchris has quit [Read error: 110 (Connection timed out)]
dan2 has joined #ocaml
<dan2>
hi guys
<dan2>
what's the best way to do xml in ocaml?
<dan2>
as far as libraries and modules go
<luca83>
xml in ocaml... mmm
<luca83>
of course what do you want to do with ocaml and xml?
<DRMacIver>
xml is evil. :(
<dan2>
I'm designing a program that recursively grabs all the names of my mp3s and in input-directories, follows an xml described format for symlinking and reorganizing them with a regular expression as the key
<luca83>
DRMacIver: why?
<dan2>
xml has it's uses
<dan2>
frankly I don't feel like writing a parser
<dan2>
I'd rather use an existing one and try to work on what my application is to do
<DRMacIver>
luca83: Don't mind me. I'm just bitter.
<luca83>
DRMacIver: OK :)
<DRMacIver>
I code Java for a living, and the setup we use consists of tying together hundreds of Java Beans via XML configuration.
<DRMacIver>
It's totally opaque and depressingly verbose.
<luca83>
dan2: I think it exist an XML parsing library
<dan2>
luca83: should I use the expat bindings?
<luca83>
DRMacIver: ah ok
<DRMacIver>
On a related note, I had a serious "I wish I had OCaml's type system to hand" moment earlier today. Java Generics make me cry.
<luca83>
dan2: that's it... but I don't know how to use them
<DRMacIver>
(and experienced Java coders give me a hard time when I complain about this aspect of them)
<dan2>
DRMacIver: java would be 100x the language if it had a type system nearly as strong as ocaml
<DRMacIver>
dan2: Agreed. Although it's specifically polymorphism support I had in mind.
<DRMacIver>
Hm. Although actually now that I think about it, I don't know that OCaml's type system supports what I want to do any more nicely. It's just that it allows me to treat functions in a sane manner so I don't notice this problem as much. :)
<DRMacIver>
(Well, it gets rid of one of the problems because its polymorphism is good. You can't have a generic array in Java)
<dan2>
what I like about ocaml is often, if it compiles, it works
<dan2>
that's an unusual charactieristic of most programming languages
<dan2>
except, maybe, uhh lisp
<dan2>
and lisp sucks
<DRMacIver>
Mm. That's an interesting point.
<DRMacIver>
And very telling given that the last two weeks have been spent in a state of "It compiles, but it sure doesn't work" :)
<luca83>
DRMacIver: ahahah
skyde has joined #ocaml
<DRMacIver>
And now that I think about it, I can probably attribute about a third of that to type safety issues.
<dan2>
DRMacIver: the whole idea of functional programming makes so much more sense than imperative
<DRMacIver>
If not more.
<skyde>
how ocaml compare to objective-c in speed
<dan2>
DRMacIver: are you referring to java or ocaml?
<DRMacIver>
dan2: Java
<dan2>
skyde: C,Ocaml, ObjC run all about the same speed in realistic terms
<DRMacIver>
If it were OCaml then type safety issues = My code doesn't compile. :)
<DRMacIver>
(For all practical purposes)
<DRMacIver>
But I don't agree that functional programming makes more sense than imperative.
<DRMacIver>
They both have their strengths and weaknesses.
<dan2>
this is true
<DRMacIver>
Functional programming is e.g. not very good when you need side effects like file access. :)
<DRMacIver>
(You can do it, but it inevitably breaks out of the pure functional model)
<dan2>
DRMacIver: the big problem with imperative programming is using it with object oriented programming
<dan2>
DRMacIver: very hard to debug
<DRMacIver>
*twitch*
<DRMacIver>
Yes.
<DRMacIver>
Yes it is.
_fab has quit [Read error: 110 (Connection timed out)]
<dan2>
DRMacIver: there's one simple reason for this
<skyde>
objective-c does strutural subtyping by dynamic typing ala smalltalk + implicit implementation of protocol
<DRMacIver>
Speaking of type safety, you know what's really fun? Dynamic loading of types.
<DRMacIver>
*cringe*
<DRMacIver>
(No, I don't mean dynamic typing)
<dan2>
Most programs don't follow the simple rule: If the class does more than what you can describe in a single sentence, break it up
<dan2>
DRMacIver: OOP can be done very well with immutable classes
<DRMacIver>
dan2: I've encountered an interesting corollary of people following that rule actually.
<skyde>
ruby :P
<DRMacIver>
When something *does* go wrong you have to burrow fifty layers deep in order to find it.
<dan2>
DRMacIver: yeah, but the fix is usually a one liner
_fab has joined #ocaml
<dan2>
DRMacIver: because there's only so much that could go wrong in a single function
<DRMacIver>
Once you've found where to fix and why it's going wrong in the first place. :)
<DRMacIver>
dan2: Except that part of 'what could go wring in a single function' is 'the function is getting an argument it shouldn't
<DRMacIver>
'
<dan2>
DRMacIver: a big failure of java imho is the getter/setter patterns
<DRMacIver>
By the way, my comment about dynamic loading of classes was not intended to be considered as promoting it as a good idea...
<DRMacIver>
Hm. I'm not sure I agree with that as a failing. What's wrong with it?
<dan2>
DRMacIver: `it makes debugging a living hell
<dan2>
DRMacIver: it screws up the chain of access
<DRMacIver>
Doesn't OCaml effectively do the same in fact?
<dan2>
DRMacIver: ocaml has immutable types
<DRMacIver>
Well, yes.
<dan2>
unless specifically designated, one instantiation only
<DRMacIver>
What's that got to do with it?
<DRMacIver>
Hm
<dan2>
if you can limit instantiation to one
<dan2>
you know how much simpler it is to debug?
<dan2>
there is only 1 creator of XYZ variable
<dan2>
and if there are more than one, you'll get either a quick exception runtime error, or compile time error
<dan2>
getter/setter screwed that all up
<DRMacIver>
Surely the problem isn't one of instantiation? It's one of mutation.
<dan2>
not to mention how much more practical it is for garbage collection using a single instantiation
<dan2>
DRMacIver: right
<DRMacIver>
But possibly I'm just confused as to what you mean. My brain is a bit tired. :)
<dan2>
DRMacIver: Java shouldn't have native functionality to reassign types, that's all
<dan2>
DRMacIver: that's 80% of the nightmare in itself
<DRMacIver>
Hm.
<dan2>
the other part is using dumb functions to change types that could be easily done via public variable
<dan2>
third, those dumb functions are most of the time void return, so you can't tell if they are successful or not
<DRMacIver>
I think I'm confused as to what you mean. :)
<DRMacIver>
Are you complaining that if I have public Foo x I can cast it to (Bar) x?
<DRMacIver>
Or are you complaining that I can do setFoo(baz)?
<Ballin_105>
jeremy_c: you up ?
<dan2>
DRMacIver: the latter
<DRMacIver>
ok
<DRMacIver>
Then I don't agree with you.
<jeremy_c>
Ballin_105: I'll be here for about 5 minutes, then going to go fly my powered paraglider
<Ballin_105>
paraglider?
<DRMacIver>
A field is part of the object's internal state and shouldn't be publically accessible.
<DRMacIver>
A public method doesn't want to care about the internal representation of an object.
<DRMacIver>
e.g. I don't need to know that when I call user.setBanned it isn't really setting a user.mBanned = true, it's doing User.mStatus.add(UserStatus.Banned));
dbueno has quit ["these are the only ones of which the news has come to harvard; there may be many others but they haven't been discoooovered"]
<DRMacIver>
It's a separation of concerns issue.
<DRMacIver>
If my setter method failed to set the value then that's a sign of Things Going Wrong, and that's what an exception is for.
<Ballin_105>
jeremy_c: still trying to find a good editor
<skyde>
i would need an staticly-typed imperative object oriented language = you'd say c++ = but i wan type inference and structural subtyping = youd say ocaml but it is a functional one
ijoshua has joined #ocaml
<Ballin_105>
jeremy_c: pretty cool i have an actual plane glider
<Ballin_105>
and im about to buy a small cessna plane or something one of these days
<jeremy_c>
Ballin_105: I've solo'ed in a glider but the season was up (last year) right as I soloed. I started way late.
<Ballin_105>
hmmmmm how fast those things do? how high ?
<jeremy_c>
Ballin_105: I fly for pleasure and flying a PPG is the ultimate. Soooo much freedom. I fly by tree's and kick the tops of them.
dbueno has joined #ocaml
<jeremy_c>
The average one goes 22-25mph. World record alt is up near 22k feet, however, I've never been about 3k feet.
<Ballin_105>
i see ..........whats the risk ? lol
<Ballin_105>
for these kinds of things
<jeremy_c>
very safe. Your flying an already inflated parachute!
<Ballin_105>
how strong is the chute itself
<jeremy_c>
you can't leave the ground if your paraglider isn't inflated.
<jeremy_c>
Mine is a beginner wing and it is stressed to 8g.
<jeremy_c>
They have aerobatic wings that are stressed much higher.
skyde has quit []
<Ballin_105>
i see do people be doing like tricks with them and stuff ?
<Ballin_105>
and do you still have to stay in touch with like an air traffic control or w/e monitoring is in your area ?
<jeremy_c>
in US, your not allowed to fly it in controlled airspace (which 99% of the country is not)
<Ballin_105>
i seeee
<jeremy_c>
you can search the web for Powered Paraglider Video, or PPG video and find quite a bit if you want to see them fly.
<Ballin_105>
how far have you went on one before ?
<jeremy_c>
about 45 miles.
<jeremy_c>
which is pretty far at 22mph/hr
<jeremy_c>
it's not for transportation, it's for fun.
<jeremy_c>
as to editors... really, stick with Vim or Emacs. Once you're past the learning curve you'll wonder how you ever did w/o them.
<Ballin_105>
that makes me nervous as shit lol
<jeremy_c>
take some time, go through the tutorial, work at learning them. You'll be happy you did.
<Ballin_105>
is that you ?
<jeremy_c>
nervous? I'm afraid of heights but have never had a problem in PPG's.
<jeremy_c>
no. I don't have video of me :-(
<Ballin_105>
do you have another parachute just in case something happened ?
<jeremy_c>
some do, some don't. I do not.
<Ballin_105>
i seee
<Ballin_105>
i like to keep an extra chute whenever im flying
<jeremy_c>
Ballin_105: where are you in the world?
<Ballin_105>
Florida
<Ballin_105>
<< miami
<jeremy_c>
oh, you should see quite a few flying down there.
<jeremy_c>
off the beaches and all around you.
<Ballin_105>
yea i have a few times
<Ballin_105>
how much did that cost you ?
<jeremy_c>
k, I'm leaving to go flying... oh, the best part? You can take of and land in quite a few places. I'm going to get mine from the garage and take off from my back yard....
<jeremy_c>
I bought a brand new unit from someone who began training and got discouraged (takes practice to get the wing up). I bought it for $4k. New ones are 6-7k.
* jeremy_c
flying away
<Ballin_105>
im about to buy a motored glider
<dan2>
hmm
<dan2>
how do you turn something option into something
<pango>
best way is to use pattern matching, because it forces you to consider the case when you receive None ;)
<dan2>
pango: that doesn't answer my question
<pango>
match maybesomething with | Some value -> f value | None -> ...
_velco has quit ["I'm outta here ..."]
<dan2>
pango, I'm sitting at the interpreter right now, what's the easiest way to do on a one by one basis
<pango>
not sure what you mean
<ijoshua>
(<- newbie) is it possible to use type to define a type representing a function?
<ijoshua>
e.g. type 'a t = s -> ('a,s) (* syntax error *)
<dan2>
pango: a function of a class returns NodeList, and NodeList#item 0 return Node option
<dan2>
assuming option is a reference/pointer to Node
<dan2>
how do I dereference it
<pango>
option types are just predefined variant types
<pango>
type 'a option = None | Some of 'a
<pango>
so to check a value of option type, just proceed with pattern matching as usual
<pango>
match ... with
<pango>
| None -> ...
<pango>
| Some x -> ...
<pango>
ijoshua: you probably mean type 'a t = s -> 'a * s
<ijoshua>
pango: maybe, but that still gives a syntax error
<pango>
if you already defined the s type, it should work fine
<ijoshua>
pango: oh, that was the problem. thanks@