ocaml Questions
7
Clojure has a macro, ->, which takes a piece of data and a bunch of functions, applies the data to the first function, and then applies the result of that to the next one, the result of that to ...
Guan asked 3/3, 2012 at 11:37
3
The typical List.map function in OCaml is pretty simple, it takes a function and a list, and applies the function to each items of the list recursively. I now need to convert List.map into a tail r...
Guinness asked 9/12, 2014 at 18:47
1
I'm encoding a form of van Laarhoven lenses in OCaml, but am having difficulty due to the value restriction.
The relevant code is as follows:
module Optic : sig
type (-'s, +'t, +'a, -'b) t
val le...
Fist asked 21/3, 2015 at 19:49
7
Solved
I want to write a function that taking a string and return a list of char. Here is a function, but I think it is not do what I want ( I want to take a string and return a list of characters).
let ...
Arnold asked 9/4, 2012 at 3:53
2
Solved
I'd like to do something like this
String.concat '\n' [str1; str2 ... strn]
so I can print in a file. But ocaml doesn't allow me to do that. What can I do?
Peterec asked 3/4, 2012 at 2:22
2
Solved
I am trying to understand the purpose of locally abstract types in OCaml. How are locally abstract types different from type variables? It appears that they have the same behavior:
(* Type variable...
4
I am attempting to install OCaml via the OCaml opam package manager on MacOs. I have successfully installed opam via homebrew. Initiating the package manager with opam init yields the following err...
4
Solved
Are there any implementations of a purely functional standard binary heap? I know there are lots of interesting heaps eg: Binomial, leftist heap, they all have functional implementation, just wonde...
Quiroz asked 2/1, 2012 at 1:30
1
I saw the following:
type rlevel = [
| `rlevel
]
but I've never seen this before and the tutorials for ADTs (algebraic data types) are not super helpful nor is the OCaml grammar.
What does this me...
Classroom asked 14/7, 2022 at 18:51
3
Solved
Is there an equivalent to Haskell's $ operator in OCaml, or do I have to rely on brackets? See for example,
multiplyByFive 5 + 1 -- 26
but
multiplyByFive $ 5 + 1 -- 30
Anabasis asked 1/7, 2022 at 8:47
4
Solved
In OCaml, is there a way to refer to the cons operator by itself?
For example, I can use (+) and ( * ) as int -> int -> int functions, but I cannot use (::) as a 'a -> 'a list -> 'a li...
3
Solved
I'm currently trying to do some mahjong hand processing in OCaml and straight from the beginning I'm confronted with something that bugs me.
I'll give you examples based on cards because I don't w...
Kall asked 18/6, 2013 at 15:38
3
Solved
I'm trying to make a recursive function to get the transpose of a list of lists, n x p to p x n. But i'm unable to do so. I've been able to make a function to transpose a 3 x n list of lists to an ...
Hinson asked 21/10, 2010 at 16:35
6
Solved
What are some ways that I can accomplish what Haskell's typeclasses do in OCaml? Basically, I want to write a polymorphic function without writing too much code. The typical way to do polymorphism ...
Justino asked 18/2, 2013 at 10:35
7
Solved
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 ite...
Tachymetry asked 8/7, 2010 at 9:9
4
Solved
I am implementing a simple C-like language in OCaml and, as usual, AST is my intermediate code representation. As I will be doing quite some traversals on the tree, I wanted to implement
a visitor ...
Zabrina asked 19/3, 2014 at 5:16
3
Solved
I sometimes write functions that make the assumption that some arguments cannot occur. If they do, this is a bug and I fail:
let foo = function
| 0 -> ()
| _ -> failwith "foo: bad argument...
Privily asked 16/11, 2015 at 15:20
1
Solved
I'm currently learning about OCaml, and especially functors. I looked at map.mli from the standard library, and around line 70, there is :
type key
(** The type of the map keys. *)
type !+'a t
(**...
Changchun asked 22/12, 2021 at 14:44
1
Solved
I face a situation where a record is given a weak polymorphic type and I am not sure why.
Here is a minimized example
module type S = sig
type 'a t
val default : 'a t
end
module F (M : S) = stru...
Acrylonitrile asked 15/12, 2021 at 12:46
3
Solved
Is there a way to make optional argument f flexible enough to have type 'a -> 'b, yet still make it default to identity, given that identity has type 'a -> 'a?
An earlier question begins by ...
View asked 21/1, 2018 at 5:31
6
Solved
To learn the basics of OCaml, I'm solving one of the easy facebook engineering puzzles using it. Essentially, I'd like to do something like the following Python code:
some_str = some_str.strip()
...
1
Solved
Looking at the following code:
type z = Z of z
type 'a s = Z | S of 'a
type _ t = Z : z t | S : 'n t -> 'n s t
the last line contains a generic variant, or what seems like one, but instead of...
3
Solved
OCaml has several different syntaxes for a polymorphic type annotation :
let f : 'a -> 'a = … (* Isn’t this one already polymorphic? (answer: NO) *)
let f : 'a. 'a -> 'a = …
let f : type a. a...
Guardant asked 11/9, 2021 at 15:50
1
Solved
A very common pattern in functional programming is to chain a series of calls to map on lists. A contrived, simple example:
[1; 2; 3] |> List.map (fun x -> x + 1) |> List.map (fun x -> ...
Feck asked 10/9, 2021 at 16:27
5
Solved
The Objective Caml language will only produce stack traces if you ask for them just right - what are the requirements for both bytecode and native code?
Snowmobile asked 28/9, 2008 at 13:53
© 2022 - 2024 — McMap. All rights reserved.