Is there a way to do a C-style forward declaration in OCaml?
My problem is that I have two variants which mutually refer to each other:
type path_formula =
[ `Next of state_formula
| `Until of (state_formula * state_formula)
| `UntilB of (state_formula * int * state_formula)
]
type state_formula =
[ `True | `False
|...
Hello!
I'm learning OCaml and although I have years of experience with imperative programming languages (C, C++, Java) I'm getting some problems with delimiters between declarations or expressions in OCaml syntax.
Basically I understood that I have to use ; to concatenate expressions and the value returned by the sequence will be the ...
From what I understood I can use pattern-matching in a match ... with expression with tuples of values, so something like
match b with
("<", val) -> if v < val then true else false
| ("<=", val) -> if v <= val then true else false
should be correct but it gives me a syntax error as if the parenthesis couldn't be used:
File "oc...
How can I use some OCaml record that I've defined in some other file? Say for example that I have the file a.ml in which I define the r record:
type r = {
i: int;
j: int;
};
and a file b.ml in which I want to use the r record. Something like this:
let s = {i = 12; j = 15;} clearly doesn't work - I know it has something to do with acce...
Hello,
just a fast hint: I want to print a list of strings and I was going to do it by pattern matching just to get into this powerful functionality, how can I express the "do-nothing-but-return-unit" operation?
What I mean is
let print_nodes nodes =
match nodes with
[] -> (* here i want to noop *)
| s :: t -> print_string s;...
I'm trying to write a simple recursive function that look over list and return a pair of integer. This is easy to write in c/c++/java but i'm new to ocaml so somehow hard to find out the solution due to type conflict
it should goes like ..
let rec test p l = ... ;;
val separate : (’a -> bool) -> ’a list -> int * int = <fun>
test (fun ...
Can someone give me the difference between these two kinds recursions and example?
specifically in ocaml. Thanks
...
From what I can tell, = and != is supposed to work on strings in OCAML. I'm seeing strange results though which I would like to understand better.
When I compare two strings with = I get the results I expect:
# "steve" = "steve";;
- : bool = true
# "steve" = "rowe";;
- : bool = false
but when I try != I do not:
# "steve" != "rowe";...
I'm new to ocaml and tryin to write a continuation passing style function but quite confused what value i need to pass into additional argument on k
for example, I can write a recursive function that returns true if all elements of the list is even, otherwise false.
so its like
let rec even list = ....
on CPS, i know i need to ad...
is there a way to iterate list over the list through List.map?
I know List.map takes single function and list and produce a list that the function applies to all elements. But what if i have a list of function to apply a list and produce list of the list ?
...
I'm learning Ocaml and quite lost how to deal with this.
Here is example.
let's say
type xml = Element of tag * xml list | CharData of string;;
and i want to access tag value and modify it.
The way i can think of is
match xml with
Element (tag, xlist) -> (* do something *)
| CharData str -> (* do something *)
I know th...
Hello, I'm having a problem in fixing a warning that OCaml compiler gives to me.
Basically I'm parsing an expression that can be composed by Bool, Int and Float.
I have a symbol table that tracks all the symbols declared with their type:
type ast_type = Bool | Int | Float
and variables = (string, int*ast_type) Hashtbl.t;
where int i...
I'd like to be able to get the AST for a given OCaml program (I'd like to walk the AST and generate an instrumented version of the code or do some kind of transformation, for example). Do any of the OCaml tools support this functionality?
...
Hello, maybe I'm just failing in a really simple thing but I'm developing an intepreter written in OCaml with standard tools as ocamllex and ocamlyacc and I have this situation:
iparser.mly contains parser spec
ilexer.mll contains lexer spec
impossible.ml contains the vm that executes the code and all the types needed
The instruction...
Hello, how does referenced linking work in OCaml?
Example, let's assume I have 3 modules declared as
A.ml
B.ml
C.ml
of which
A needs B and C
B needs A
How should I proceed in compiling?
Since order is relevant using ocamlc or ocamlopt how can I fix the cross reference between B and A?
I'm trying to first compile them all into ...
What's wrong with this code?
let vm_run vm =
let guard = ref true in
while !guard do
if vm.cur_pc = -1 && not (Stack.empty vm.call_stack) then vm_pop_ar vm
else if vm.cur_pc = -1 then guard := false
else if vm.cur_pc < Array.length vm.cur_code then
execute vm Array.get vm.cur_code vm.cur_pc;
...
Suppose I have some code like this:
List.map (fun e -> if (e <> 1) then e + 1 else (*add nothing to the list*))
Is there a way to do this? If so, how?
I want to both manipulate the item if it matches some criteria and ignore it if it does not. Thus List.filter wouldn't seem to be the solution.
...
Hello, suppose I have a type defined as
type value =
None
| Int of int
| Float of float
| Complex of Complex.t
| String of string
| Char of char
| Bool of bool
and I want to be able to work with Sets of these values. From what I understood I have to use the functor to concretize the Set module with a conc...
Hello, I want to use regexps in OCaml and it seems that Str module provides these functionalities.
So I tried with a simple program:
open Str
let regx = regexp "."
but it gives me the following error
File "lol.ml", line 1, characters 0-1:
Error: Error while linking lol.cmo:
Reference to undefined global `Str'
As if module i...
Hello, how can I manage to define a Set in OCaml that can contains element of its type too?
To explain the problem I have a type declaration for a lot of data types like
type value =
Nil
| Int of int
| Float of float
| Complex of Complex.t
| String of string
| Regexp of regexp
| Char of char
| Bool of bool
| Range of (int*int) list
|...