ocaml

UML for OCaml immediate objects

I have created an immediate object in OCaml. let x = object (self) val dataMember = 3 method aMethod = print_endline "Called a method" end;; As the object doesn't have a name (is it considered anonymous?), how can it be correctly represented in UML? Thanks. ...

Converting PCL to PDF

I am looking to create (as a proof-of-concept) an OCaml (preferably) program that converts PCL code to PDF format. I am not sure where to start. Is there a standardized algorithm for doing so? Is there any other advice available for accomplishing this task? Thanks! ...

Absolute value for floats in core OCaml

I am in need of an absolute value function for floats in OCaml and the core language doesn't seem to possess one, so I wrote the following: let absF (f:float) = if f > 0.0 then f else (f *. -1.0);; which seems to work for positives but not for negatives, citing: This expression has type float -> float but is here used with type int ...

OCaml types with different levels of specificity

I am attempting to simulate an interface in OCaml and am using the "type" construct. I have two types: type fooSansBar = {a: string; b: int};; type fooConBar = {a:string; b:int; bar:char};; ...and would like to define a particular fooSansBar: let fsb = {a="a"; b=3};; ...but am told that the bar field is not defined. From this, it a...

Hidden Features of OCaml

After being disappointed by the responses to the hidden features of F# question, please allow me to rephrase it: What are the lesser known, or hidden, features of OCaml that every programmer should know about? ...

What are the differences between SML and Ocaml?

What sets the two ML dialects apart? ...

circular dependency control in OCAML

Hi everyone, [EDIT] Thank you for your answer, my problem is the following : Module A called Map.ml let lst = ref [Instance1_ModuleB; Instance2_ModuleB; ...];; let is_coliding p = DoSomeWork_And_Return_A_Bool ;; .... other things here. Module B called Player.ml Open Map class player_object (x_in, y_in, name_in)= object (self) me...

Wrapping my head around OCaml

I'm only a novice programmer (I do it for fun) and I'm coming from the world of Python/C++/other procedural languages, and procedural style of problem solving. I fell in love with OCaml's simplicity after being boggled by its functional style for about a week. Since I'm not an engineer or mathematician, what are some helpful books or res...

A Gentler Introduction to Functional Programming

I am trying to learn Haskell, and I really like it, but I can't wrap my head around most of it. Would Lisp, OCaml, etc. be a gentler introduction to functional programming? ...

The Mediator Design Pattern in OCaml

I am trying to accomplish a mutual binding between two classes in OCaml (a la Mediator Pattern's) and am getting an error upon compilation. class virtual ['mediator] colleague mIn = object val m = mIn method virtual getmediator : 'mediator end;; class concreteColleague mIn = object inherit colleague method getmediator = m end;; (...

Visitor Design Pattern in OCaml

I am attempting to implement the Visitor Design Pattern using OCaml's OO constructs and type system and am running into problems upon instantiation of an Element. class virtual ['hrRep] employee = object method virtual receiveEvaluation : 'hrRep -> unit method virtual getName : string end;; class ['hrRep] accountant myName = object ...

Should I learn Haskell or F# if I already know OCaml?

I am wondering if I should continue to learn OCaml or switch to F# or Haskell. Here are the criteria I am most interested in: Longevity Which language will last longer? I don't want to learn something that might be abandoned in a couple years by users and developers. Will Inria, Microsoft, University of Glasgow continue to support...

List of Functional code snippets for Procedural Programmers?

Sometimes I still get stuck trying to translate procedural code into functional code. Is there a list of functional idioms/snippets that are mapped to procedural idioms/snippets? Edit Since there doesn't seem to be a centralized website of these snippets, I am turning this into a community wiki. Please paste any procedural -> function...

Why are functions in Ocaml/F# not recursive by default?

Why is it that functions in F# and Ocaml (and possibly other languages) are not by default recursive? In other words, why did the language designers decide it was a good idea to explicitly make you type rec in a declaration like: let rec foo ... = ... and not give the function recursive capability by default? Why the need for an exp...

{X with value} in ocaml

I saw the following function call in Yacfe example: Visitor_c.vk_program { Visitor_c.default_visitor_c with Visitor_c.kexpr = (fun (k, bigf) exp -> match Ast_c.unwrap_expr exp with | Binary(e1, Logical (Eq), (((Constant(Int("0")) as _e2),_t),ii)) -> (match Ast_c.get_onlytype_expr e1 with | Some ...

Why "**" does not bind more tightly than negation in OCaml?

after this question, I don't know what to think. In OCaml, if you do something like -1.0**2.0 (because of the typing you need to have float), you obtain 1.00. According to the standard order of operations, the result should be -1 (as in python). I wasn't able to find the reason or a clear definition of the operator precedence in OCaml....

What are some exotic parsing techniques?

I've been parsing poker hand histories for the past year and have learned quite a deal about parsing in general. We started with regexes but quickly realized that wouldn't scale easily. We skipped languages from ruby to c++ and finally came to grips that it was the algorithim that had to change. We picked up Boost::Spirit and watched o...

How to copy Gdk.image?

Is it possible to make a copy of Gdk.image object using lablgtk2 for Ocaml? I tried to find 'copy' or 'clone' methods but failed. ...

Is it possible to call a C function from OCaml passing a huge array efficiently?

I'm considering the use of a combination between OCaml and C code in a new application. It seems that calling C code from Ocaml is simple: external name : type = C-function-name However, it seems also that in the other way around (calling OCaml from C) is more complicated: static void call_ocaml_void (const char * name) { ...

Ocaml OpenGL example from wikipedia fails to compile

I am trying to get started with some basic Ocaml programming. To start I wanted to get the OpenGL example from wikipedia running. http://en.wikipedia.org/wiki/Ocaml let _ = ignore( Glut.init Sys.argv ); Glut.initDisplayMode ~double_buffer:true (); ignore (Glut.createWindow ~title:"OpenGL Demo"); let angle t = 10. *. t...